Skip to content

Commit

Permalink
Fix pan and IRateConverters
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 12, 2023
1 parent 1ceb2a6 commit 48159d2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sdl2-hyper-sonic-drivers/examples/pcm-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char* argv[])
for (int i = 0, sig = +1; i < 3; i++, sig *= -1)
{
cout << i << ". playing same sound again reversed balance" << endl;
delayMillis(200);
delayMillis(500);
drv.play(wavSound, 150, 127 * sig);
drv.play(vocSound, 255, -127 * sig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ namespace HyperSonicDrivers::audio::converters
int16_t out1 = (stereo ? *it++ : out0);

// output left channel
output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l);
output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l);
// output right channel
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
obuf += 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ namespace HyperSonicDrivers::audio::converters
const int16_t out0 = interpolate(ilast0, icur0, opos);
const int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0;
// output left channel
output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l);
output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l);
// output right channel
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
obuf += 2;

// Increment output position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ namespace HyperSonicDrivers::audio::converters
opos += opos_inc;

// output left channel
output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l);
output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l);
// output right channel
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
obuf += 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ namespace HyperSonicDrivers::audio::mixer
const float pan = (127.5f + m_pan) / 255.0f;
// TODO: create different selectable pan laws
// -3dB pan law
m_volL = static_cast<uint16_t>(std::round(sqrt(pan) * vol / ch_max_vol));
m_volR = static_cast<uint16_t>(std::round(sqrt(1 - pan) * vol / ch_max_vol));
m_volL = static_cast<uint16_t>(std::round(sqrt(1 - pan) * vol / ch_max_vol));
m_volR = static_cast<uint16_t>(std::round(sqrt(pan) * vol / ch_max_vol));

// adjust for master volume
const auto m_vol = m_mixer.getMasterVolume();
Expand Down

0 comments on commit 48159d2

Please sign in to comment.