Skip to content

Commit

Permalink
Fixed local radio sounds ignored volume settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Sep 30, 2016
1 parent 7259e62 commit 0d13592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions ts/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
#include <algorithm>
#include <sstream>

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<float>((M_PI)) / 180.0f;
float dir = atan2(position.y, position.x) + viewAngle;
while (dir > static_cast<float>((M_PI))) {
while (dir > static_cast<float>((M_PI))) {
dir = dir - 2 * static_cast<float>((M_PI));
}

Expand Down
14 changes: 8 additions & 6 deletions ts/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -1089,22 +1088,25 @@ 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<float>(freq.volume)) * serverIdToData[currentServerConnectionHandlerID].globalVolume, freq.stereoMode);
} else {
playWavFile("radio-sounds/lr/local_start");
}
break;
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<float>(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<float>(freq.volume)) * serverIdToData[currentServerConnectionHandlerID].globalVolume, freq.stereoMode);
} else {
playWavFile("radio-sounds/ab/local_start");
}
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 0d13592

Please sign in to comment.