SDL_mixer 2.0 The latest version of this library is available from: http://www.libsdl.org/projects/SDL_mixer/ Due to popular demand, here is a simple multi-channel audio mixer. It supports 8 channels of 16 bit stereo audio, plus a single channel of music. See the header file SDL_mixer.h and the examples playwave.c and playmus.c for documentation on this mixer library. The mixer can currently load Microsoft WAVE files and Creative Labs VOC files as audio samples, it can load FLAC files with libFLAC, it can load Ogg Vorbis files with Ogg Vorbis or Tremor libraries, it can load MP3 files using mpg123 or libmad, and it can load MIDI files with Timidity, FluidSynth, and natively on Windows, Mac OSX, and Linux, and finally it can load the following file formats via ModPlug or MikMod: .MOD .S3M .IT .XM. Tremor decoding is disabled by default; you can enable it by passing --enable-music-ogg-tremor to configure, or by defining MUSIC_OGG and OGG_USE_TREMOR. libmad decoding is disabled by default; you can enable it by passing --enable-music-mp3-mad to configure, or by defining MUSIC_MP3_MAD vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv WARNING: The license for libmad is GPL, which means that in order to use it your application must also be GPL! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The process of mixing MIDI files to wave output is very CPU intensive, so if playing regular WAVE files sound great, but playing MIDI files sound choppy, try using 8-bit audio, mono audio, or lower frequencies. To play MIDI files using FluidSynth, you'll need to set the SDL_SOUNDFONTS environment variable to a Sound Font 2 (.sf2) file containing the musical instruments you want to use for MIDI playback. (On some Linux distributions you can install the fluid-soundfont-gm package) To play MIDI files using Timidity, you'll need to get a complete set of GUS patches from: http://www.libsdl.org/projects/mixer/timidity/timidity.tar.gz and unpack them in /usr/local/lib under UNIX, and C:\ under Win32. iOS: In order to use this library on iOS, you should include the SDL.xcodeproj and Xcode-iOS/SDL_mixer.xcodeproj in your application, add the SDL/include and SDL_mixer directories to your "Header Search Paths" setting, then add the libSDL2.a and libSDL2_mixer.a to your "Link Binary with Libraries" setting. This library is under the zlib license, see the file "COPYING.txt" for details.
This update I developed a while ago for the MixerX fork. It allows reporting the song duration and the current time position while playing the song.
#233
This bug report was migrated from our old Bugzilla tracker.
Reported in version: 2.0.4 Reported for operating system, platform: Windows 7, x86
Comments on the original bug report:
On 2019-05-31 15:31:31 +0000, AltairPL wrote:
- all loops in _Eff_position_u8_c4() look like this:
for (i = 0; i < len; i += sizeof (Uint8) * 6)
Shouldn't multiplier be 4 here (as in other _c4 functions)?
- IMHO, angle adjustment in Mix_SetPosition() is incorrect, since passing -90 angle will simply change it to 90 instead of 270. I think it should be something like:
angle %= 360; if (angle < 0) angle += 360;
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
Reported in version: 2.0.2 Reported for operating system, platform: Linux, x86_64
Comments on the original bug report:
On 2017-11-10 12:33:20 +0000, Fabian Greffrath wrote:
Created attachment 3078 MinGW: help ./configure find shared libraries for dynamic loading
We apply the attached patch to the mingw-w64-SDL2_mixer package in MSYS2:
https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-SDL2_mixer
When using the 64-bit variant of the MinGW compiler, the configure script fails to find any of the installed shared libraries for dynamic linking. The patch fixes this issue by replacing the "--mingw32*" search pattern with "--mingw*".
Then, some libraries are installed with a "lib" prefix while others are not. I have extended the problematic cases with both alternatives.
Last but not least, libraries might have been installed into any of the directories accessible via the PATH environment variable, so we search in these paths as well.
Best regards,
- Fabian
timidity/instrum.c
load_instrument
line 672 (and likewise 825 I think) only allocates an extra +1 byte, but line 788 copies the last sample (2 bytes) to the position one past the size. This causes a write one byte past the end of the buffer, which is caught by musl libc's mallocng at free time and presumably caught by instrumentation like ASan, valgrind, etc. Changing the +1's to +2 should fix it.
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
Reported in version: unspecified Reported for operating system, platform: All, All
Comments on the original bug report:
On 2012-06-15 08:27:38 +0000, wrote:
Created attachment 878 Patch to add Mix_EnableModLooping to the api. Currently only available for mikmod replayed modules.
I'd really like control over whether pattern jump commands are allowed in a module. The current (sensible) default is, that these commands are not allowed and the module just ignores any pattern jump commands. But sometimes it is better to put multiple looping subsongs into one module and then just set the pattern to play with Mix_FadeInMusicPos et al. However currently with jump commands disabled all subsongs simply play one after the other.
I'd thus suggest adding something like Mix_EnableModLooping(Mix_Music *, enable) to the api which controls if pattern jump commands are allowed for a given module.
I supply a patch which does exactly that for modules played my the mikmod replayer code.
On 2017-10-21 22:22:55 +0000, Sam Lantinga wrote:
I just switched the default to allow looping: https://hg.libsdl.org/SDL_mixer/rev/4359e193d93f
Does that fix your use case, or do you need it on sometimes and off other times?
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
Reported in version: 2.0.4 Reported for operating system, platform: Windows 10, x86_64
Comments on the original bug report:
On 2018-12-15 23:27:08 +0000, wrote:
Created attachment 3549 From CF2 Soundtrack
Related to this topic: https://discourse.libsdl.org/t/back-to-integrate-mikmod-into-sdl2-mixer/25465/2
Some Cannon Fodder 2 soundtrack .AMF musics aren't played good by lib ModPlug.
File "02 - Menu.amf": you can heard some "biiip" whistle near at 38sec and 40sec File "03 - Heli Animation.amf": same "biip" at the very start of song
I known ModPlug is a plugin/codec for modern Players (like VLC, Winamp, etc), but could it be fixed to play AMF correctly, like MikMod lib does, or even old dos Dual Module Player does?
Otherwise put back again LibMikMod on SDL2_mixer and use it for AMF format.
On 2018-12-16 07:17:21 +0000, Ozkan Sezer wrote:
(In reply to drnovice from comment # 0)
I known ModPlug is a plugin/codec for modern Players (like VLC, Winamp, etc),
It may be, but it has been always full of serious bugs, some of which has only recently fixed.
but could it be fixed to play AMF correctly, like MikMod lib does, or even old dos Dual Module Player does?
Otherwise put back again LibMikMod on SDL2_mixer and use it for AMF format.
This should be reported at https://github.com/Konstanty/libmodplug but let's keep this open too: Maybe I can find some time and find the source of the issue.
On 2018-12-16 13:47:41 +0000, wrote:
Yes, LibMikMod is release version 3.3.11.1, series 3: http://mikmod.sourceforge.net/
I think it could be possibile maintain both MikMod & ModPlug, compiling dynamic or static linking to SDL2_Mixer, and give a priority to play same managed audio formats in case both libs are present.
I can PR on github an update of sln and visual studio project to using latest versions of them.
On 2021-02-07 18:15:09 +0000, Ozkan Sezer wrote:
FWIW, I tried running current SDL_mixer development tree with the attached amf file here, I cannot hear that 'beep' when playing it with the playmus example app.
Do you still experience your issue with current development source?
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
Reported in version: 2.0.4 Reported for operating system, platform: Linux, All
Comments on the original bug report:
On 2021-01-28 21:40:53 +0000, Ralph Versteegen wrote:
Created attachment 4730 A zero-length MIDI file
When playing the attached MIDI file using SDL_mixer's Timidity backend the "SDLAudioP2" thread gets stuck in an infinite loop in music_pcm_getaudio and the program will freeze when calling Mix_LockAudio
Happens on both x86 and x86_64 Linux (presumably OS-independent). Present in latest SDL_mixer hg rev, 2.0.3 and 2.0.4.
(gdb) bt
0 0xf7f3b8e8 in __lll_lock_wait () from /lib/libpthread.so.0
1 0xf7f32459 in pthread_mutex_lock () from /lib/libpthread.so.0
2 0xf7e5dccf in ?? () from /usr/lib/libSDL2-2.0.so.0
3 0xf7d85636 in ?? () from /usr/lib/libSDL2-2.0.so.0
4 0xf7d52812 in Mix_LockAudio () from /usr/lib/libSDL2_mixer-2.0.so.0
5 0xf7d539c5 in Mix_FreeMusic () from /usr/lib/libSDL2_mixer-2.0.so.0
(gdb) bt
0 0xf7d5adf3 in Timidity_Start () from /usr/lib/libSDL2_mixer-2.0.so.0
1 0xf7d57ad0 in TIMIDITY_GetSome () from /usr/lib/libSDL2_mixer-2.0.so.0
2 0xf7d52d9a in music_pcm_getaudio () from /usr/lib/libSDL2_mixer-2.0.so.0
3 0xf7d5799c in TIMIDITY_GetAudio () from /usr/lib/libSDL2_mixer-2.0.so.0
4 0xf7d52ee8 in music_mixer () from /usr/lib/libSDL2_mixer-2.0.so.0
5 0xf7d50ffa in mix_channels () from /usr/lib/libSDL2_mixer-2.0.so.0
6 0xf7d844f6 in ?? () from /usr/lib/libSDL2-2.0.so.0
7 0xf7de861b in ?? () from /usr/lib/libSDL2-2.0.so.0
8 0xf7e5d54b in ?? () from /usr/lib/libSDL2-2.0.so.0
9 0xf7f2f517 in start_thread () from /lib/libpthread.so.0
10 0xf77bd146 in clone () from /lib/libc.so.6
There's likely something wrong with the file. Timidity plays a single note, ADLMIDI plays nothing.
On 2021-01-28 21:42:42 +0000, Ralph Versteegen wrote:
I forgot to say: I stepped through music_pcm_getaudio with gdb and saw that in the following loop len = 8192, volume = MIX_MAX_VOLUME but consumed = 0.
while (len > 0 && !done) { int consumed = GetSome(context, dst, len, &done); if (consumed < 0) { break; } if (volume == MIX_MAX_VOLUME) { dst += consumed; } else { SDL_MixAudioFormat(snd, dst, music_spec.format, (Uint32)consumed, volume); snd += consumed; } len -= consumed; }
On 2021-01-28 21:44:34 +0000, Ralph Versteegen wrote:
Also forgot: repro steps: play with "playmus -l GURGU.mid", then try to quit with Ctrl-C. It won't.
This bug report was migrated from our old Bugzilla tracker.
Reported in version: 2.0.4 Reported for operating system, platform: Mac OS X (All), ARM
Comments on the original bug report:
On 2021-01-18 08:46:19 +0000, wrote:
Not a bug per se, but the MacOS .dmg for SDL_mixer 2.0.4 doesn't include support for Apple Silicon. Quite logical since the last release was in 2018.
Could you perhaps update the .dmg to include arm, so all projects that depend on it don't have to recompile the framework themselves when they want to support Apple Silicon macs natively?
This bug report was migrated from our old Bugzilla tracker.
Reported in version: 2.0.4 Reported for operating system, platform: macOS 10.15, x86_64
Comments on the original bug report:
On 2020-06-20 15:25:08 +0000, ioanch wrote:
The following frameworks embedded in SDL2_mixer.framework are "not signed at all" and require me to put something like "codesign -f -s -
" to allow bundling into an .app (my bundle contains a separate executable as a resource, and THAT executable links to those frameworks): FLAC Ogg Opus OpusFile Vorbis modplug mpg123
The following frameworks have incorrect Info.plist files. They're missing the mandatory "
CFBundleSupportedPlatforms " string: MacOSX FLAC Opus OpusFile modplug mpg123
On 2020-06-24 20:32:53 +0000, Ozkan Sezer wrote:
The mandatory CFBundleSupportedPlatforms key issue is already fixed in the hg repository: https://hg.libsdl.org/SDL_mixer/rev/58707cd78f95
This bug report was migrated from our old Bugzilla tracker.
Reported in version: 2.0.4 Reported for operating system, platform: Linux, x86_64
Comments on the original bug report:
On 2020-03-23 19:56:58 +0000, wrote:
Hi, I am from the Doom community. Most Doom source ports (modernized engines) use SDL2 and for many of them, Fluidsynth is the simplest way to use a soundfont for MIDI music playback, by setting SDL_SOUNDFONTS.
Unfortunately some of the Fluidsynth default settings can sound quite bad with lots of community-created music. In particular, Fluidsynth's chorus effect makes any instrument that uses it MUCH LOUDER than it ought to be. This generally makes using it unsuitable for anyone trying to do more than play the original levels.
It would be great if the user could set the values for Fluidsynth parameters themselves, either through another environment variable, or some config file. An alternative solution would just be to set more conservative values for the effects. Here is what I use for myself:
fluidsynth.fluid_settings_setnum(settings, "synth.chorus.depth", (double) 5); fluidsynth.fluid_settings_setnum(settings, "synth.chorus.level", (double) 0.35); fluidsynth.fluid_settings_setnum(settings, "synth.reverb.damp", (double) 0.4); fluidsynth.fluid_settings_setnum(settings, "synth.reverb.level", (double) 0.15); fluidsynth.fluid_settings_setnum(settings, "synth.reverb.width", (double) 4); fluidsynth.fluid_settings_setnum(settings, "synth.reverb.room-size", (double) 0.6);
A simple better-than-nothing solution would just be to allow disabling of the chorus effect.
I also find Fluidsynth to be much louder than other MIDI playback engines. Currently SDL2_mixer just adjusts Fluidsynth's gain between 0 and 1.2; it would be nice if it took a user set "master volume" into account.
A test I have been using is the song "Drop the Wombat" by James Paddock, a prolific composer in the Doom community. The MIDI is available at http://jamespaddockmusic.com/midi-files/SpeedMIDIs/30in30/3/Drop%20the%20Wombat.mid, and you can listen to a rendered version of it with the Windows GM synth at https://jamespaddock.bandcamp.com/track/drop-the-wombat. If desired I can provide renders with default and adjusted FluidSynth settings.
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
- sdl.py (sdl.py, text/x-python, 2020-02-07 00:18:56 +0000, 1312 bytes)
- the mp3 file (sdl.mp3, application/octet-stream, 2020-02-07 00:19:41 +0000, 14061 bytes)
Reported in version: 2.0.4 Reported for operating system, platform: Linux, x86_64
Comments on the original bug report:
On 2020-02-07 00:18:56 +0000, Sven wrote:
Created attachment 4194 sdl.py
So find attached a very simple test program (python, PySDL2 0.9.6) that loads and plays an mp3. The mp3 is the sound of somebody saying "Please play this message". If the chunksize passed to Mix_OpenAudio is 8192, the problem is most severe. The end of the word "message" is cut off. If I change the chunksize to 4096, the problem is less severe. In both cases, I assume that the last chunk of the mp3 is not played. The larger the chunksize, the more of the mp3 is not played.
This should not happen, regardless of the chunksize.
If I change the chunksize to 4000, I can work around the problem. I assume, there might be mp3 files for which the problem will persists.
Sorry that the program is python. I'm on Arch Linux using sdl2_mixer 2.0.4-3 and python-pysdl2 0.9.6-4 from Arch's AUR. As far as I can see, python is a rather thin layer on top the C API. So I assume the bug persists if I would rewrite the program in C.
On 2020-02-07 00:19:41 +0000, Sven wrote:
Created attachment 4195 the mp3 file
This bug report was migrated from our old Bugzilla tracker.
Reported in version: 2.0.4 Reported for operating system, platform: Android (All), x86_64
Comments on the original bug report:
On 2019-08-06 05:46:52 +0000, Kostyarezkiy wrote:
Ia m sorry in advance as it's somewhat difficult for me to describe the bug that I am seeing because I have the same code working on multiple platforms. I can provide a github link where code can be tested . I will do my best to be clear and provide code examples where the Music portion for android will fail.
Ok I have noticed some weird behaviour which only leads me to believe that Music connected functions don't function properly in Android. I cannot quite put my finger on it because , I noticed that as a solution I can play a wav as a sound effect , but as I try to use the music_mixer, the function returns null.
I will provide some code examples to prove a point . I have a few projects that work fine on multiple platforms but once in Android I have to convert Mix_Music to a Mix_Chunk. In another code base , I noticed that Mix_LoadMUS_RW always returns null.
/* Code Sample 1------------------------------*/
Mix_Music *music; SDL_RWops *musicRw; char *musicBuffer; sound_create_primary_buffer(sgpMusicTrack); if (!success) { sgpMusicTrack = NULL; } else { int bytestoread = SFileGetFileSize(sgpMusicTrack, 0); musicBuffer = (char *)MusicAllocPtr(bytestoread); SFileReadFile(sgpMusicTrack, musicBuffer, bytestoread, NULL, 0); musicRw = SDL_RWFromConstMem(musicBuffer, bytestoread); if (musicRw == NULL) { SDL_Log(SDL_GetError()); } music = Mix_LoadMUS_RW(musicRw, 1); // This function always returns null despite musicRw always having a pointer Mix_VolumeMusic(MIX_MAX_VOLUME - MIX_MAX_VOLUME * sglMusicVolume / VOLUME_MIN); Mix_PlayMusic(music, -1);// this will never play because there is no music loaded in the mixer. sgnMusicTrack = nTrack;
/CODE SAMPLE2----------------------------------------------------------------/
#include <SDL.h> #include <SDL_image.h> #include <SDL_mixer.h> #include <stdio.h> #include <android/log.h>
#include
#include Mix_Music *gMusic = NULL; Mix_Chunk *gHigh = NULL;
int main(int /argc/, char* /argv/[]) {
bool success = true; SDL_Window *window; // Declare a pointer SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); // Initialize SDL2 // Create an application window with the following settings: window = SDL_CreateWindow( "An SDL2 window", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position 640, // width, in pixels 480, // height, in pixels SDL_WINDOW_OPENGL // flags - see below ); // Check that the window was successfully created if (window == NULL) { // In the case that the window could not be made... printf("Could not create window: %s\n", SDL_GetError()); return 1; } // The window is open: could enter program loop here (see SDL_PollEvent()) // Setup renderer SDL_Renderer *renderer = NULL; renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); // Set render color to red ( background will be rendered in this color ) SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); // Clear winow SDL_RenderClear(renderer); if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ) { __android_log_print(ANDROID_LOG_VERBOSE, "DEBUGSOUND", Mix_GetError(), 1); success = false; }
//THIS FAILS gMusic = Mix_LoadMUS("/sdcard/music/test.wav");///// THIS FAILS if (gMusic == NULL) { //char * error [100] = {0}; //sprintf(error,Mix_GetError()) printf("Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError()); __android_log_print(ANDROID_LOG_VERBOSE, "DEBUGSOUND", Mix_GetError(), 1);
success = false; }
//THIS Succeeds! gHigh = Mix_LoadWAV( "/sdcard/music/test.wav" ); if( gHigh == NULL ) { printf( "Failed to load high sound effect! SDL_mixer Error: %s\n", Mix_GetError() ); __android_log_print(ANDROID_LOG_VERBOSE, "DEBUGSOUND", Mix_GetError(), 1); success = false; }
// bouyatest // Creat a rect at pos ( 50, 50 ) that's 50 pixels wide and 50 pixels high. SDL_Rect r; r.x = 50; r.y = 50; r.w = 500; r.h = 500; // Set render color to blue ( rect will be rendered in this color ) SDL_SetRenderDrawColor( renderer, 0, 0, 255, 255 ); // Render image SDL_Surface *loadedImage = IMG_Load("res/hello.png"); SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, loadedImage); SDL_FreeSurface(loadedImage); SDL_RenderCopy(renderer, texture, NULL, &r); // Render the rect to the screen SDL_RenderPresent(renderer); bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Handle key press else if( e.type == SDL_MOUSEBUTTONDOWN ) { if( Mix_PlayingMusic() == 0 ) { //Play the music Mix_PlayChannel( -1, gHigh, 0 ); } } }
}
SDL_Delay(8000); // Pause execution for 3000 milliseconds, for example // Close and destroy the window SDL_DestroyWindow(window); // Clean up SDL_Quit(); return 0;
}
On 2019-08-22 06:59:11 +0000, Sylvain wrote:
I'd say add printf in SDL_mixer/mixer.c, function Mix_LoadMusic_RW() so that you find more precisely why it returns null.
(Maybe there are issue with Android File functions. in bug # 4297, the is a patch that changes all the file functions to use the standard ones from the NDK. you can try it, though I am not sure it will helps ...
On 2020-10-07 07:12:37 +0000, Sylvain wrote:
Do you have more information ?