From 0d135926e38f0571c03113f44c9b94f6d8310bb1 Mon Sep 17 00:00:00 2001 From: dedmen Date: Fri, 30 Sep 2016 22:14:01 +0200 Subject: [PATCH] Fixed local radio sounds ignored volume settings --- ts/src/helpers.cpp | 12 ++++++------ ts/src/plugin.cpp | 14 ++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ts/src/helpers.cpp b/ts/src/helpers.cpp index 9dbac9b51..453e45910 100644 --- a/ts/src/helpers.cpp +++ b/ts/src/helpers.cpp @@ -7,21 +7,21 @@ #include #include -void helpers::applyGain(short * samples, int channels, int sampleCount, float directTalkingVolume) -{ +void helpers::applyGain(short * samples, int channels, int sampleCount, float directTalkingVolume) { if (directTalkingVolume == 0.0f) { - memset(samples, 0, sampleCount* channels); + memset(samples, 0, sampleCount * channels * sizeof(short)); return; } + if (directTalkingVolume == 1.0f) //no change in gain + return; for (int i = 0; i < sampleCount * channels; i++) samples[i] = (short) (samples[i] * directTalkingVolume); } -void helpers::applyILD(short * samples, int channels, int sampleCount, TS3_VECTOR position, float viewAngle) -{ +void helpers::applyILD(short * samples, int channels, int sampleCount, TS3_VECTOR position, float viewAngle) { if (channels == 2) { viewAngle = viewAngle * static_cast((M_PI)) / 180.0f; float dir = atan2(position.y, position.x) + viewAngle; - while (dir > static_cast((M_PI))) { + while (dir > static_cast((M_PI))) { dir = dir - 2 * static_cast((M_PI)); } diff --git a/ts/src/plugin.cpp b/ts/src/plugin.cpp index d9135f18c..7d0b571df 100644 --- a/ts/src/plugin.cpp +++ b/ts/src/plugin.cpp @@ -270,8 +270,7 @@ void playWavFile(uint64 serverConnectionHandlerID, const char* fileNameWithoutEx helpers::applyGain(input, wave->_spec.channels, samples, gain); std::string id = to_play + std::to_string(rand()); - if (stereoMode == 0) { - } else if (stereoMode == 1) { + if (stereoMode == 1) { for (int q = 0; q < samples * wave->_spec.channels; q += wave->_spec.channels) { input[q + 1] = 0; //mute right channel } @@ -1089,7 +1088,8 @@ std::string processGameCommand(std::string command) { switch (PTTDelayArguments::subtypeToString(subtype)) { case PTTDelayArguments::subtypes::digital_lr: if (serverIdToData[currentServerConnectionHandlerID].myLrFrequencies.count(frequency)) { - playWavFile(currentServerConnectionHandlerID, "radio-sounds/lr/local_start", 1, serverIdToData[currentServerConnectionHandlerID].myLrFrequencies[frequency].stereoMode); + FREQ_SETTINGS& freq = serverIdToData[currentServerConnectionHandlerID].myLrFrequencies[frequency]; + playWavFile(currentServerConnectionHandlerID, "radio-sounds/lr/local_start", helpers::volumeMultiplifier(static_cast(freq.volume)) * serverIdToData[currentServerConnectionHandlerID].globalVolume, freq.stereoMode); } else { playWavFile("radio-sounds/lr/local_start"); } @@ -1097,14 +1097,16 @@ std::string processGameCommand(std::string command) { case PTTDelayArguments::subtypes::dd: playWavFile("radio-sounds/dd/local_start"); break; case PTTDelayArguments::subtypes::digital: if (serverIdToData[currentServerConnectionHandlerID].mySwFrequencies.count(frequency)) { - playWavFile(currentServerConnectionHandlerID, "radio-sounds/sw/local_start", 1, serverIdToData[currentServerConnectionHandlerID].mySwFrequencies[frequency].stereoMode); + FREQ_SETTINGS& freq = serverIdToData[currentServerConnectionHandlerID].mySwFrequencies[frequency]; + playWavFile(currentServerConnectionHandlerID, "radio-sounds/sw/local_start", helpers::volumeMultiplifier(static_cast(freq.volume)) * serverIdToData[currentServerConnectionHandlerID].globalVolume, freq.stereoMode); } else { playWavFile("radio-sounds/sw/local_start"); } break; case PTTDelayArguments::subtypes::airborne: if (serverIdToData[currentServerConnectionHandlerID].myLrFrequencies.count(frequency)) { - playWavFile(currentServerConnectionHandlerID, "radio-sounds/ab/local_start", 1, serverIdToData[currentServerConnectionHandlerID].myLrFrequencies[frequency].stereoMode); + FREQ_SETTINGS& freq = serverIdToData[currentServerConnectionHandlerID].myLrFrequencies[frequency]; + playWavFile(currentServerConnectionHandlerID, "radio-sounds/ab/local_start", helpers::volumeMultiplifier(static_cast(freq.volume)) * serverIdToData[currentServerConnectionHandlerID].globalVolume, freq.stereoMode); } else { playWavFile("radio-sounds/ab/local_start"); } @@ -1136,7 +1138,7 @@ std::string processGameCommand(std::string command) { case PTTDelayArguments::subtypes::dd: playWavFile("radio-sounds/dd/local_start"); break; case PTTDelayArguments::subtypes::digital: if (serverIdToData[currentServerConnectionHandlerID].mySwFrequencies.count(frequency)) { - playWavFile(currentServerConnectionHandlerID, "radio-sounds/sw/local_end", 1, serverIdToData[currentServerConnectionHandlerID].mySwFrequencies[frequency].stereoMode); + playWavFile(currentServerConnectionHandlerID, "radio-sounds/sw/local_end", 0.3f, serverIdToData[currentServerConnectionHandlerID].mySwFrequencies[frequency].stereoMode); } else { playWavFile("radio-sounds/sw/local_end"); }