Add main volume option to settings (#267)

* This commit adds the option to control the main volume game via a slider
added to the "Sound" tab in the settings menu.
This commit is contained in:
Parker
2024-05-25 21:59:15 -07:00
committed by GitHub
parent 41e737249e
commit 169155953e
6 changed files with 49 additions and 11 deletions
+4 -2
View File
@@ -23,6 +23,7 @@
#include "recomp_input.h"
#include "recomp_config.h"
#include "recomp_game.h"
#include "recomp_sound.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@@ -191,9 +192,10 @@ void queue_samples(int16_t* audio_data, size_t sample_count) {
// Convert the audio from 16-bit values to floats and swap the audio channels into the
// swap buffer to correct for the address xor caused by endianness handling.
float cur_main_volume = recomp::get_main_volume() / 100.0f; // Get the current main volume, normalized to 0.0-1.0.
for (size_t i = 0; i < sample_count; i += input_channels) {
swap_buffer[i + 0 + duplicated_input_frames * input_channels] = audio_data[i + 1] * (0.5f / 32768.0f);
swap_buffer[i + 1 + duplicated_input_frames * input_channels] = audio_data[i + 0] * (0.5f / 32768.0f);
swap_buffer[i + 0 + duplicated_input_frames * input_channels] = audio_data[i + 1] * (0.5f / 32768.0f) * cur_main_volume;
swap_buffer[i + 1 + duplicated_input_frames * input_channels] = audio_data[i + 0] * (0.5f / 32768.0f) * cur_main_volume;
}
// TODO handle cases where a chunk is smaller than the duplicated frame count.