Skip to content

Commit

Permalink
Fixed bug 3833 - Silent MP3 playback using included smpeg2 library
Browse files Browse the repository at this point in the history
Holger Schemel

Summary: When playing MP3 files using the included smpeg2 library, audio output is silent.

How to reproduce the problem: Build latest SDL2_mixer and smpeg2 (from directory "external/smpeg2-2.0.0") and play MP3 file using included music player "playmus". (Tested on Ubuntu 12.04 and Mac OS X 10.11.)

Expected behaviour: "playmus" plays MP3 music through the computer's audio device.

Observed behaviour: "playmus" appears to be playing, but the computer's audio device remains silent.

The problem was introduced with changeset 718:fb0562cc1559, which replaces legacy functions like SDL_OpenAudio(), SDL_LockAudio(), SDL_PauseAudio(), SDL_MixAudio() etc. with their non-legacy counterparts like SDL_OpenAudioDevice(), SDL_LockAudioDevice(), SDL_PauseAudioDevice() and SDL_MixAudioFormat() in the SDL2_mixer code, while the smpeg2 code still uses the legacy functions.

Replacing SDL_MixAudio() with SDL_MixAudioFormat() in the smpeg2 code fixes the problem, and MP3 playback using SDL2_mixer with smpeg2 works fine again (from both "playmus" and from my SDL2/SDL2_mixer/smpeg2 based games).

The attached patch fixes the problem.
  • Loading branch information
slouken committed Sep 18, 2017
1 parent dd370f3 commit e84500b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions external/smpeg2-2.0.0/MPEGaudio.h
Expand Up @@ -186,6 +186,7 @@ class MPEGaudio : public MPEGerror, public MPEGaudioaction {
double rate_in_s;
Uint32 frags_playing;
Uint32 frag_time;
SDL_AudioFormat format;
#ifdef THREADED_AUDIO
bool decoding;
SDL_Thread *decode_thread;
Expand Down
3 changes: 3 additions & 0 deletions external/smpeg2-2.0.0/audio/MPEGaudio.cpp
Expand Up @@ -34,6 +34,7 @@ MPEGaudio:: MPEGaudio(MPEGstream *stream, bool initSDL)
, rate_in_s(0.0)
, frags_playing(0)
, frag_time(0)
, format(0)
#ifdef THREADED_AUDIO
, decoding(false)
, decode_thread(NULL)
Expand Down Expand Up @@ -155,6 +156,8 @@ MPEGaudio:: ActualSpec(const SDL_AudioSpec *actual)
}
rate_in_s=((double)((actual->format&0xFF)/8)*actual->channels*actual->freq);
stereo=((actual->channels-1) > 0);

format = actual->format;
}

#ifdef THREADED_AUDIO
Expand Down
14 changes: 7 additions & 7 deletions external/smpeg2-2.0.0/audio/mpegtoraw.cpp
Expand Up @@ -429,15 +429,15 @@ int Play_MPEGaudio(MPEGaudio *audio, Uint8 *stream, int len)
quite right */
copylen = audio->ring->NextReadBuffer(&rbuf);
if ( copylen > len ) {
SDL_MixAudio(stream, rbuf, len, volume);
SDL_MixAudioFormat(stream, rbuf, audio->format, len, volume);
mixed += len;
audio->ring->ReadSome(len);
len = 0;
for (int i=0; i < N_TIMESTAMPS -1; i++)
audio->timestamp[i] = audio->timestamp[i+1];
audio->timestamp[N_TIMESTAMPS-1] = audio->ring->ReadTimeStamp();
} else {
SDL_MixAudio(stream, rbuf, copylen, volume);
SDL_MixAudioFormat(stream, rbuf, audio->format, copylen, volume);
mixed += copylen;
++audio->currentframe;
audio->ring->ReadDone();
Expand Down Expand Up @@ -477,14 +477,14 @@ int Play_MPEGaudio(MPEGaudio *audio, Uint8 *stream, int len)
copylen = (audio->rawdatawriteoffset-audio->rawdatareadoffset);
assert(copylen >= 0);
if ( copylen >= len ) {
SDL_MixAudio(stream, (Uint8 *)&audio->spillover[audio->rawdatareadoffset],
len*2, volume);
SDL_MixAudioFormat(stream, (Uint8 *)&audio->spillover[audio->rawdatareadoffset],
audio->format, len*2, volume);
mixed += len*2;
audio->rawdatareadoffset += len;
goto finished_mixing;
}
SDL_MixAudio(stream, (Uint8 *)&audio->spillover[audio->rawdatareadoffset],
copylen*2, volume);
SDL_MixAudioFormat(stream, (Uint8 *)&audio->spillover[audio->rawdatareadoffset],
audio->format, copylen*2, volume);
mixed += copylen*2;
len -= copylen;
stream += copylen*2;
Expand All @@ -503,7 +503,7 @@ int Play_MPEGaudio(MPEGaudio *audio, Uint8 *stream, int len)
audio->rawdatawriteoffset = 0;
if ( audio->run(1) ) {
assert(audio->rawdatawriteoffset > len);
SDL_MixAudio(stream, (Uint8 *) audio->spillover, len*2, volume);
SDL_MixAudioFormat(stream, (Uint8 *) audio->spillover, audio->format, len*2, volume);
mixed += len*2;
audio->rawdatareadoffset = len;
} else {
Expand Down

0 comments on commit e84500b

Please sign in to comment.