Skip to content

Commit

Permalink
fix rate converters mono/stereo output buffer copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 11, 2023
1 parent 9a59385 commit 920a9c3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions sdl2-hyper-sonic-drivers/examples/pcm-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ int main(int argc, char* argv[])
delayMillis(100);
}

/* drv.play(wavSound);
drv.play(wavSound);
while(drv.isPlaying(wavSound))
{
cout << "is playing" << endl;
delayMillis(1000);
}*/
}

delayMillis(500);

Expand All @@ -59,13 +59,13 @@ int main(int argc, char* argv[])

drv.play(wavSound, 150, 127);
drv.play(vocSound, 255, -127);
/*for (int i = 0, sig = +1; i < 3; i++, sig *= -1)
for (int i = 0, sig = +1; i < 3; i++, sig *= -1)
{
cout << i << ". playing same sound again reversed balance" << endl;
delayMillis(200);
drv.play(wavSound, 150, 127 * sig);
drv.play(vocSound, 255, -127 * sig);
}*/
}

while(drv.isPlaying())
{
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 ? 1 : 0], out0, vol_l);
output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l);
// output right channel
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
obuf += 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace HyperSonicDrivers::audio::converters
inLen -= (stereo ? 2 : 1);
ilast0 = icur0;
icur0 = *inPtr++;
if (stereo)
if constexpr (stereo)
{
ilast1 = icur1;
icur1 = *inPtr++;
Expand All @@ -114,12 +114,12 @@ namespace HyperSonicDrivers::audio::converters
while (opos < fracOneLow && obuf < oend)
{
// interpolate
int16_t out0 = interpolate(ilast0, icur0, opos);
int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0;
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 right channel
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
obuf += 2;

// Increment output position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace HyperSonicDrivers::files
// timeConstant = 65536 - (256000000 / (channels * sampleRate);
// sampleRate = 256000000 / ((65536 - (timeConstant<<8))*channels)
m_sampleRate = 256000000L / ((65536 - (timeConstant << 8)) * m_channels);
//_sampleRate = 1000000 / (256 - timeConstant);
//m_sampleRate = 1000000 / (256 - timeConstant);
assertValid_(m_sampleRate == (1000000 / (256 - timeConstant)));
// pack Method
switch (packMethod)
Expand Down Expand Up @@ -131,10 +131,10 @@ namespace HyperSonicDrivers::files
case 7:
logW("end loop block not-implemented");
break;
case 8:
case 8: // extended
logW("special block 8 not-implemented");
break;
case 9:
case 9: // extended 2
{
assertValid_(m_version >= 0x0114);
m_sampleRate = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24);
Expand Down

0 comments on commit 920a9c3

Please sign in to comment.