Skip to content

Commit

Permalink
Added a function to get the master volume
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Sep 8, 2023
1 parent cd3dbac commit 2cc0cb4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void main_loop() {
float dt = binocle_window_get_frame_time(window) / 1000.0f;

binocle_input_update(&input);
binocle_audio_update_music_stream(&music);
binocle_audio_update_music_stream(&audio, &music);

if (input.resized) {
kmVec2 oldWindowSize;
Expand Down Expand Up @@ -171,10 +171,14 @@ void main_loop() {
}

if (binocle_input_is_key_pressed(&input, KEY_1)) {
binocle_audio_set_master_volume(&audio, audio.master_volume-0.2f);
float volume;
binocle_audio_get_master_volume(&audio, &volume);
binocle_audio_set_master_volume(&audio, volume-0.2f);
}
if (binocle_input_is_key_pressed(&input, KEY_2)) {
binocle_audio_set_master_volume(&audio, audio.master_volume+0.2f);
float volume;
binocle_audio_get_master_volume(&audio, &volume);
binocle_audio_set_master_volume(&audio, volume+0.2f);
}

kmVec2 mouse_pos;
Expand Down
4 changes: 4 additions & 0 deletions src/binocle/core/binocle_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ void binocle_audio_set_master_volume(binocle_audio *audio, float volume) {
ma_device_set_master_volume(&audio->device, volume);
}

void binocle_audio_get_master_volume(binocle_audio *audio, float *volume) {
ma_device_get_master_volume(&audio->device, volume);
}

binocle_audio_buffer *binocle_audio_load_audio_buffer(binocle_audio *audio, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 sizeInFrames, int usage)
{
binocle_audio_buffer *audioBuffer = (binocle_audio_buffer *)calloc(1, sizeof(binocle_audio_buffer));
Expand Down
7 changes: 7 additions & 0 deletions src/binocle/core/binocle_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ bool binocle_audio_is_audio_device_ready(binocle_audio *audio);
*/
void binocle_audio_set_master_volume(binocle_audio *audio, float volume);

/**
* \brief Gets the master volume of the audio system
* @param audio the audio system
* @param volume a reference to the variable where the volume will be written [0..1]
*/
void binocle_audio_get_master_volume(binocle_audio *audio, float *volume);

/**
* \brief Returns true if the audio buffer is playing
* @param audio_buffer the audio buffer
Expand Down

0 comments on commit 2cc0cb4

Please sign in to comment.