Skip to content

Commit

Permalink
Fixed the Radio volume sliders - now logarithmic not linear
Browse files Browse the repository at this point in the history
  • Loading branch information
ciribob committed May 27, 2024
1 parent be27010 commit 94d2a63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions DCS-SR-Client/Network/UDPVoiceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Ciribob.DCS.SimpleRadio.Standalone.Client.Singletons;
using Ciribob.DCS.SimpleRadio.Standalone.Client.Utils;
using Ciribob.DCS.SimpleRadio.Standalone.Common;
using Ciribob.DCS.SimpleRadio.Standalone.Common.Helpers;
using Ciribob.DCS.SimpleRadio.Standalone.Common.Network;
using Ciribob.DCS.SimpleRadio.Standalone.Common.Setting;
using FragLabs.Audio.Codecs;
Expand Down Expand Up @@ -458,7 +459,7 @@ private void UdpAudioDecode()
ReceiveTime = DateTime.Now.Ticks,
Frequency = destinationRadio.Frequency,
Modulation = destinationRadio.Modulation,
Volume = destinationRadio.ReceivingRadio.volume,
Volume = VolumeConversionHelper.ConvertRadioVolumeSlider(destinationRadio.ReceivingRadio.volume),
ReceivedRadio = destinationRadio.ReceivingState.ReceivedOn,
UnitId = udpVoicePacket.UnitId,
Encryption = destinationRadio.Encryption,
Expand Down Expand Up @@ -1005,7 +1006,7 @@ public ClientAudio Send(byte[] bytes, int len, bool voice)
{
_audioManager.PlaySoundEffectStartTransmit(sendingOn,
currentlySelectedRadio.enc && (currentlySelectedRadio.encKey > 0),
currentlySelectedRadio.volume, currentlySelectedRadio.modulation);
VolumeConversionHelper.ConvertRadioVolumeSlider(currentlySelectedRadio.volume), currentlySelectedRadio.modulation);
}

//set radio overlay state
Expand Down Expand Up @@ -1050,7 +1051,7 @@ public ClientAudio Send(byte[] bytes, int len, bool voice)
{
var radio = _clientStateSingleton.DcsPlayerRadioInfo.radios[_clientStateSingleton.RadioSendingState.SendingOn];

_audioManager.PlaySoundEffectEndTransmit(_clientStateSingleton.RadioSendingState.SendingOn, radio.volume, radio.modulation);
_audioManager.PlaySoundEffectEndTransmit(_clientStateSingleton.RadioSendingState.SendingOn, VolumeConversionHelper.ConvertRadioVolumeSlider(radio.volume), radio.modulation);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions DCS-SR-Common/Helpers/VolumeConversionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,30 @@ public static double CalculateRMS(float[] buffer, int offset, int sampleCount)

return 20 * Math.Log10(rms);
}

public static float ConvertRadioVolumeSlider(float sliderValue)
{
double dB = ConvertSliderToVolume(sliderValue);
return (float) dBToLinearScale(dB);
}

static double ConvertSliderToVolume(double sliderValue)
{
if (sliderValue <= 0)
{
sliderValue = 0.000001;
}
else if (sliderValue > 1)
{
sliderValue = 1;
}
return 20 * Math.Log10(sliderValue);
}

static float dBToLinearScale(double dB)
{
return (float)Math.Pow(10, dB / 20);
}

}
}

0 comments on commit 94d2a63

Please sign in to comment.