We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2094 - Resampling music produces garbage
Summary: Resampling music produces garbage
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: x86_64 All
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-07 17:15 UTC by Lauri Kenttä
Modified: 2017-10-21 20:11 UTC (History)
3 users (show)

See Also:


Attachments
Test program, plays first Mix_Chunk and then Mix_Music. (1.16 KB, text/x-csrc)
2013-09-07 17:15 UTC, Lauri Kenttä
Details
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 16000 Hz (169.69 KB, audio/wave)
2014-08-25 02:33 UTC, Francisco de la Peña
Details
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 16000 Hz (64.27 KB, audio/wave)
2014-08-25 02:33 UTC, Francisco de la Peña
Details
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 43000 Hz (345.25 KB, audio/wave)
2014-09-22 01:32 UTC, Francisco de la Peña
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lauri Kenttä 2013-09-07 17:15:07 UTC
Created attachment 1325 [details]
Test program, plays first Mix_Chunk and then Mix_Music.

If the audio device is opened at 48000 Hz and a music file is at 44100 Hz, the resampler produces garbage (unrecognizable noise). This only happens with Mix_Music. If the same file is opened as Mix_Chunk, it works fine. Apparently this is not bug #58 anymore but something new instead.

I'm using SDL2 and SDL2_mixer from 64-bit Arch Linux repository, both versions reported as 2.0.0.

Steps to reproduce:
Mix_OpenAudio(48000, ...);
Mix_PlayMusic(Mix_LoadMUS("music_at_44100.wav"), 0);

Expected result: music
Actual result: garbage
Comment 1 Francisco de la Peña 2014-08-25 02:33:42 UTC
Created attachment 1849 [details]
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 16000 Hz

Tests with attached file:
playmus  -r 22050 0000_226.wav # plays garbage
playwave -r 22050 0000_226.wav # plays OK
playmus  -r 44100 0000_226.wav # plays garbage
playwave -r 44100 0000_226.wav # plays garbage
Comment 2 Francisco de la Peña 2014-08-25 02:33:45 UTC
Created attachment 1850 [details]
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 16000 Hz

Tests with attached file:
playmus  -r 22050 0000_227.wav # plays garbage
playwave -r 22050 0000_227.wav # plays garbage
playmus  -r 44100 0000_227.wav # plays garbage
playwave -r 44100 0000_227.wav # plays OK
Comment 3 Francisco de la Peña 2014-08-25 02:44:46 UTC
(In reply to Lauri Kenttä from comment #0)
> If the audio device is opened at 48000 Hz and a music file is at 44100 Hz,
> the resampler produces garbage (unrecognizable noise). This only happens
> with Mix_Music. If the same file is opened as Mix_Chunk, it works fine.
> Apparently this is not bug #58 anymore but something new instead.

According with tests it fails with Mix_PlayWAV too under different wave files. I guess is related with #58 and might be about buffer size issues.
Comment 4 Francisco de la Peña 2014-09-21 21:28:56 UTC
Looks like this issue got resolved at #2389. Works for me in SDL Hg.
Comment 5 Francisco de la Peña 2014-09-22 01:32:56 UTC
Created attachment 1876 [details]
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 43000 Hz

Though the bug #2389 fixes all playwave (Mix_Channel) tests it still plays alternated garbage between buffer chunks with playmus (Mix_PlayMusic), most noticeable when mixer playback frequency is lower:

playmus -r 11025 0000_227-43000Hz.wav # plays garbage between buffer chunks
playmus -r 22050 0000_227-43000Hz.wav # plays garbage between buffer chunks
playmus -r 44100 0000_227-43000Hz.wav # plays garbage between buffer chunks
playmus -r 48000 0000_227-43000Hz.wav # plays garbage between buffer chunks
playmus -r 96000 0000_227-43000Hz.wav # plays garbage between buffer chunks
Comment 6 jpakkane 2015-04-11 20:30:31 UTC
This seems to be a bit more complicated than the comments here indicate.

I'm trying to play a 48 kHz ogg file (Mix_LoadMUS) and a wav effect file (Mix_LoadWAV). This seems to be broken in several different ways. Tested on Ubuntu 64 bit, OSX Yosemite and Windows XP (under VirtualBox).

If the selected output rate of Mix_OpenAudio is not exactly 48k (for example 44.1) then the music plays back as noise on every platform.

If the wav effect file is 44.1, then both Linux and OSX play it just fine. However on Windows, it produces just static noise. Using a 48k wav file works on all platforms.
Comment 7 Sam Lantinga 2017-10-21 20:11:04 UTC
This is fixed in the latest code in SDL and SDL_mixer Mercurial:
http://hg.libsdl.org/

Thanks!