@@ -279,17 +279,15 @@ static bool one_shot_resample(const float* in, size_t samples_in,
279279 resampler_ident , quality , ratio ))
280280 return false;
281281
282- /*
283- * Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
282+ /* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
284283 * add four more samples in the formula below just as safeguard, because
285284 * resampler->process sometimes reports more output samples than the
286285 * formula below calculates. Ideally, audio resamplers should have a
287286 * function to return the number of samples they will output given a
288- * count of input samples.
289- */
290- * samples_out = samples_in * ratio + 4 ;
287+ * count of input samples. */
288+ * samples_out = (size_t )(samples_in * ratio );
291289 * out = (float * )memalign_alloc (16 ,
292- ((* samples_out + 15 ) & ~15 ) * sizeof (float ));
290+ ((( * samples_out + 4 ) + 15 ) & ~15 ) * sizeof (float ));
293291
294292 if (* out == NULL )
295293 return false;
@@ -547,9 +545,15 @@ static bool audio_mixer_play_ogg(
547545 goto error ;
548546 }
549547
548+ /* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
549+ * add four more samples in the formula below just as safeguard, because
550+ * resampler->process sometimes reports more output samples than the
551+ * formula below calculates. Ideally, audio resamplers should have a
552+ * function to return the number of samples they will output given a
553+ * count of input samples. */
550554 samples = (unsigned )(AUDIO_MIXER_TEMP_BUFFER * ratio );
551555 ogg_buffer = (float * )memalign_alloc (16 ,
552- ((samples + 15 ) & ~15 ) * sizeof (float ));
556+ ((( samples + 4 ) + 15 ) & ~15 ) * sizeof (float ));
553557
554558 if (!ogg_buffer )
555559 {
@@ -690,9 +694,15 @@ static bool audio_mixer_play_flac(
690694 goto error ;
691695 }
692696
697+ /* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
698+ * add four more samples in the formula below just as safeguard, because
699+ * resampler->process sometimes reports more output samples than the
700+ * formula below calculates. Ideally, audio resamplers should have a
701+ * function to return the number of samples they will output given a
702+ * count of input samples. */
693703 samples = (unsigned )(AUDIO_MIXER_TEMP_BUFFER * ratio );
694- flac_buffer = (float * )memalign_alloc (16 ,
695- ((samples + 15 ) & ~15 ) * sizeof (float ));
704+ flac_buffer = (float * )memalign_alloc (16 ,
705+ ((( samples + 4 ) + 15 ) & ~15 ) * sizeof (float ));
696706
697707 if (!flac_buffer )
698708 {
@@ -762,9 +772,15 @@ static bool audio_mixer_play_mp3(
762772 goto error ;
763773 }
764774
775+ /* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
776+ * add four more samples in the formula below just as safeguard, because
777+ * resampler->process sometimes reports more output samples than the
778+ * formula below calculates. Ideally, audio resamplers should have a
779+ * function to return the number of samples they will output given a
780+ * count of input samples. */
765781 samples = (unsigned )(AUDIO_MIXER_TEMP_BUFFER * ratio );
766782 mp3_buffer = (float * )memalign_alloc (16 ,
767- ((samples + 15 ) & ~15 ) * sizeof (float ));
783+ ((( samples + 4 ) + 15 ) & ~15 ) * sizeof (float ));
768784
769785 if (!mp3_buffer )
770786 {
0 commit comments