Ensure all MSU-1 reads are stereo channel aligned

This commit is contained in:
qwertymodo 2018-05-26 20:02:16 -07:00
parent 3fba3492d2
commit 15f76f7eca
2 changed files with 17 additions and 11 deletions

View File

@ -530,7 +530,7 @@ bool8 S9xInitSound (int buffer_ms, int lag_ms)
return (FALSE);
if (msu::landing_buffer)
delete[] msu::landing_buffer;
msu::landing_buffer = new uint8[msu::buffer_size * 2];
msu::landing_buffer = (uint8*) new uint32[msu::buffer_size / 2]; // Ensure 4-byte alignment
if (!msu::landing_buffer)
return (FALSE);

View File

@ -420,21 +420,27 @@ bool S9xMSU1ROMExists(void)
void S9xMSU1Generate(size_t sample_count)
{
partial_samples += 4410 * sample_count;
partial_samples += 4410 * ((sample_count + 1) &~(size_t)(1));
bufPos = (int16*)(((long long)bufPos + 1) &~(long long)(3));
while (((uintptr_t)bufPos < (uintptr_t)bufEnd) && partial_samples > 3204)
while (((uintptr_t)bufPos < (uintptr_t)bufEnd) && partial_samples > 6408)
{
if (MSU1.MSU1_STATUS & AudioPlaying && audioStream)
{
int16 sample;
int bytes_read = READ_STREAM((char *)&sample, 2, audioStream);
if (bytes_read == 2)
{
sample = (int16)((double)(int16)GET_LE16(&sample) * (double)MSU1.MSU1_VOLUME / 255.0);
int32 sample;
int16* left = (int16*)&sample;
int16* right = left + 1;
*(bufPos++) = sample;
MSU1.MSU1_AUDIO_POS += 2;
partial_samples -= 3204;
int bytes_read = READ_STREAM((char *)&sample, 4, audioStream);
if (bytes_read == 4)
{
*left = (int16)((double)(int16)GET_LE16(left) * (double)MSU1.MSU1_VOLUME / 255.0);
*right = (int16)((double)(int16)GET_LE16(right) * (double)MSU1.MSU1_VOLUME / 255.0);
*(bufPos++) = *left;
*(bufPos++) = *right;
MSU1.MSU1_AUDIO_POS += 4;
partial_samples -= 6408;
}
else
if (bytes_read >= 0)