Navigation Menu

Skip to content

Commit

Permalink
Fixed alignment issue when doing conversion between 44100 Hz and 4800…
Browse files Browse the repository at this point in the history
…0 Hz
  • Loading branch information
slouken committed Aug 21, 2017
1 parent fec42d0 commit cee6585
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions wavestream.c
Expand Up @@ -211,9 +211,13 @@ static int PlaySome(Uint8 *stream, int len)
}

if (music->cvt.needed) {
int original_len;

original_len = (int)((double)len/music->cvt.len_ratio);
int original_len = (int)((double)len/music->cvt.len_ratio);
/* Make sure the length is a multiple of the sample size */
{
const int bytes_per_sample = (SDL_AUDIO_BITSIZE(music->spec.format) / 8) * music->spec.channels;
const int alignment_mask = (bytes_per_sample - 1);
original_len &= ~alignment_mask;
}
if (music->cvt.len != original_len) {
int worksize;
if (music->cvt.buf != NULL) {
Expand All @@ -230,15 +234,6 @@ static int PlaySome(Uint8 *stream, int len)
original_len = (int)(stop - pos);
}
original_len = SDL_RWread(music->src, music->cvt.buf, 1, original_len);
/* At least at the time of writing, SDL_ConvertAudio()
does byte-order swapping starting at the end of the
buffer. Thus, if we are reading 16-bit samples, we
had better make damn sure that we get an even
number of bytes, or we'll get garbage.
*/
if ((music->cvt.src_format & 0x0010) && (original_len & 1)) {
original_len--;
}
music->cvt.len = original_len;
SDL_ConvertAudio(&music->cvt);
SDL_MixAudioFormat(stream, music->cvt.buf, mixer.format,music->cvt.len_cvt, wavestream_volume);
Expand Down

0 comments on commit cee6585

Please sign in to comment.