Skip to content

Commit 27e1519

Browse files
committed
Remove NaNs from Audio Buffer
Fixes #73 Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
1 parent 5abe6e4 commit 27e1519

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

MarathonRecomp/apu/driver/sdl2_driver.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ void XAudioSubmitFrame(void* samples)
131131
float ch4 = floatSamples[4 * XAUDIO_NUM_SAMPLES + i];
132132
float ch5 = floatSamples[5 * XAUDIO_NUM_SAMPLES + i];
133133

134-
audioFrames[i * 2 + 0] = (ch0 + ch2 * 0.75f + ch4) * Config::MasterVolume;
135-
audioFrames[i * 2 + 1] = (ch1 + ch2 * 0.75f + ch5) * Config::MasterVolume;
134+
float samp0 = (ch0 + ch2 * 0.75f + ch4) * Config::MasterVolume;
135+
float samp1 = (ch1 + ch2 * 0.75f + ch5) * Config::MasterVolume;
136+
137+
audioFrames[i * 2 + 0] = isnan(samp0) ? 0.0f : samp0;
138+
audioFrames[i * 2 + 1] = isnan(samp1) ? 0.0f : samp1;
136139
}
137140

138141
SDL_QueueAudio(g_audioDevice, &audioFrames, sizeof(audioFrames));
@@ -143,8 +146,10 @@ void XAudioSubmitFrame(void* samples)
143146

144147
for (size_t i = 0; i < XAUDIO_NUM_SAMPLES; i++)
145148
{
146-
for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++)
147-
audioFrames[i * XAUDIO_NUM_CHANNELS + j] = floatSamples[j * XAUDIO_NUM_SAMPLES + i] * Config::MasterVolume;
149+
for (size_t j = 0; j < XAUDIO_NUM_CHANNELS; j++) {
150+
float samp = floatSamples[j * XAUDIO_NUM_SAMPLES + i] * Config::MasterVolume;
151+
audioFrames[i * 2 + j] = isnan(samp) ? 0.0f : samp;
152+
}
148153
}
149154

150155
SDL_QueueAudio(g_audioDevice, &audioFrames, sizeof(audioFrames));

0 commit comments

Comments
 (0)