From 085c7a2f18c94e656c73e9f93651e1b9e63da522 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Thu, 8 Jun 2017 17:32:17 +0000 Subject: [PATCH] Update mixer volume calculations for the SBPRO1,2 and SB16. Thanks for the measurements James-F. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4022 --- src/hardware/sblaster.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/hardware/sblaster.cpp b/src/hardware/sblaster.cpp index 15f87e7b..836f5c81 100644 --- a/src/hardware/sblaster.cpp +++ b/src/hardware/sblaster.cpp @@ -1098,21 +1098,33 @@ static Bit8u DSP_ReadData(void) { return sb.dsp.out.lastval; } -//The soundblaster manual says 2.0 Db steps but we'll go for a bit less -#define CALCVOL(_VAL) (float)pow(10.0f,((float)(31-_VAL)*-1.3f)/20) +static float calc_vol(Bit8u amount) { + Bit8u count = 31 - amount; + float db = static_cast(count); + if (sb.type == SBT_PRO1 || sb.type == SBT_PRO2) { + if (count) { + if (count < 16) db -= 1.0f; + else if (count > 16) db += 1.0f; + if (count == 24) db += 2.0f; + if (count > 27) return 0.0f; //turn it off. + } + } else { //Give the rest, the SB16 scale, as we don't have data. + db *= 2.0f; + if (count > 20) db -= 1.0f; + } + return (float) pow (10.0f,-0.05f * db); +} static void CTMIXER_UpdateVolumes(void) { if (!sb.mixer.enabled) return; MixerChannel * chan; - //adjust to get linear master volume slider in trackers - chan=MIXER_FindChannel("SB"); - if (chan) chan->SetVolume(float(sb.mixer.master[0])/31.0f*CALCVOL(sb.mixer.dac[0]), - float(sb.mixer.master[1])/31.0f*CALCVOL(sb.mixer.dac[1])); - chan=MIXER_FindChannel("FM"); - if (chan) chan->SetVolume(float(sb.mixer.master[0])/31.0f*CALCVOL(sb.mixer.fm[0]), - float(sb.mixer.master[1])/31.0f*CALCVOL(sb.mixer.fm[1])); - chan=MIXER_FindChannel("CDAUDIO"); - if (chan) chan->SetVolume(float(sb.mixer.master[0])/31.0f*CALCVOL(sb.mixer.cda[0]), - float(sb.mixer.master[1])/31.0f*CALCVOL(sb.mixer.cda[1])); + float m0 = calc_vol(sb.mixer.master[0]); + float m1 = calc_vol(sb.mixer.master[1]); + chan = MIXER_FindChannel("SB"); + if (chan) chan->SetVolume(m0 * calc_vol(sb.mixer.dac[0]), m1 * calc_vol(sb.mixer.dac[1])); + chan = MIXER_FindChannel("FM"); + if (chan) chan->SetVolume(m0 * calc_vol(sb.mixer.fm[0]) , m1 * calc_vol(sb.mixer.fm[1]) ); + chan = MIXER_FindChannel("CDAUDIO"); + if (chan) chan->SetVolume(m0 * calc_vol(sb.mixer.cda[0]), m1 * calc_vol(sb.mixer.cda[1])); } static void CTMIXER_Reset(void) {