diff --git a/jail_audio.cpp b/jail_audio.cpp index 7ce9aec..38ece31 100644 --- a/jail_audio.cpp +++ b/jail_audio.cpp @@ -14,6 +14,7 @@ struct JA_Channel_t { JA_Sound sound; int pos {0}; int times {0}; + int volume {64}; JA_Channel_state state { JA_CHANNEL_FREE }; }; @@ -55,11 +56,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { if (channels[i].state == JA_CHANNEL_PLAYING) { const int size = SDL_min(len, channels[i].sound->length - channels[i].pos); - SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2); + SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, channels[i].volume); channels[i].pos += size; if (size < len) { if (channels[i].times != 0) { - SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2); + SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, channels[i].volume); channels[i].pos = len-size; if (channels[i].times > 0) channels[i].times--; } else { @@ -243,7 +244,13 @@ JA_Channel_state JA_GetChannelState(const int channel) { return channels[channel].state; } +int JA_SetChannelVolume(const int channel, int volume) { + if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; + channels[channel].volume = volume > 128 ? 128 : volume < 0 ? 0 : volume; + return channels[channel].volume; +} + int JA_SetVolume(int volume) { JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume; return JA_volume; -} \ No newline at end of file +} diff --git a/jail_audio.h b/jail_audio.h index 7d03400..8d36e65 100644 --- a/jail_audio.h +++ b/jail_audio.h @@ -25,6 +25,8 @@ void JA_PauseChannel(const int channel); void JA_ResumeChannel(const int channel); void JA_StopChannel(const int channel); JA_Channel_state JA_GetChannelState(const int channel); +int JA_SetChannelVolume(const int channel, int volume); + void JA_DeleteSound(JA_Sound sound); int JA_SetVolume(int volume); \ No newline at end of file