Skip to content

Commit

Permalink
id_sd_sdl: Fixes to stereo support
Browse files Browse the repository at this point in the history
Two fixes here:
1. Technically, it's not valid C to access *stream while incrementing it
   with *stream++. Oops!
2. Forgot a multiply by numChannels, so we were using the wrong offset
   when copying pre-rendered stereo buffers. This caused some stereo
   crackle.

The latter's the only problem, and irritatingly affects OSI v1.02
  • Loading branch information
sulix committed Jan 1, 2023
1 parent ba32ce6 commit 110a84d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/id_sd_sdl.c
Expand Up @@ -279,9 +279,13 @@ static inline void PCSpeakerUpdateOne(int16_t *stream, int length)
{
for (int loopVar = 0; loopVar < length; loopVar++)
{
*stream++ = (*stream + SD_SDL_CurrentBeepSample) / 2; // Mix
*stream = (*stream + SD_SDL_CurrentBeepSample) / 2; // Mix
stream++;
if (numChannels == 2)
*stream++ = (*stream + SD_SDL_CurrentBeepSample) / 2; // Mix
{
*stream = (*stream + SD_SDL_CurrentBeepSample) / 2; // Mix
stream++;
}
SD_SDL_BeepHalfCycleCounter += 2 * PC_PIT_RATE;
if (SD_SDL_BeepHalfCycleCounter >= SD_SDL_BeepHalfCycleCounterUpperBound)
{
Expand Down Expand Up @@ -325,7 +329,7 @@ void SD_SDL_CallBack(void *unused, Uint8 *stream, int len)
{
// Copy sound generated by alOut
if (SD_ALOut_SamplesEnd - SD_ALOut_SamplesStart > 0)
memcpy(currSamplePtr, &SD_ALOut_Samples[SD_ALOut_SamplesStart], numChannels * 2 * (SD_ALOut_SamplesEnd - SD_ALOut_SamplesStart));
memcpy(currSamplePtr, &SD_ALOut_Samples[SD_ALOut_SamplesStart * numChannels], numChannels * 2 * (SD_ALOut_SamplesEnd - SD_ALOut_SamplesStart));
// Generate what's left
if (currNumOfSamples - (SD_ALOut_SamplesEnd - SD_ALOut_SamplesStart) > 0)
YM3812UpdateOne(&oplChip, currSamplePtr + (SD_ALOut_SamplesEnd - SD_ALOut_SamplesStart) * numChannels, currNumOfSamples - (SD_ALOut_SamplesEnd - SD_ALOut_SamplesStart));
Expand Down

0 comments on commit 110a84d

Please sign in to comment.