From 2cc0cb436205eb6e2b4448e7d19497ca02b974a0 Mon Sep 17 00:00:00 2001 From: Valerio Santinelli Date: Fri, 8 Sep 2023 09:32:44 +0200 Subject: [PATCH] Added a function to get the master volume --- example/main.c | 10 +++++++--- src/binocle/core/binocle_audio.c | 4 ++++ src/binocle/core/binocle_audio.h | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/example/main.c b/example/main.c index b99dbf01..494bff0b 100644 --- a/example/main.c +++ b/example/main.c @@ -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; @@ -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; diff --git a/src/binocle/core/binocle_audio.c b/src/binocle/core/binocle_audio.c index 415eb54a..b654f943 100644 --- a/src/binocle/core/binocle_audio.c +++ b/src/binocle/core/binocle_audio.c @@ -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)); diff --git a/src/binocle/core/binocle_audio.h b/src/binocle/core/binocle_audio.h index f22c358c..fdac2388 100644 --- a/src/binocle/core/binocle_audio.h +++ b/src/binocle/core/binocle_audio.h @@ -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