music_modplug.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 23 Aug 2014 10:57:26 -0700
changeset 696 9599bb0ff844
parent 695 6a5e6d8d6a35
child 711 f40c5ac95b12
permissions -rw-r--r--
Fixed bug 2690 - Floating point exception in Mix_Volume()

Francisco de la Peña

This happens rarely under uncertain circunstances, as it doesn't crash always and does it randomly. Fortunately, I've got a backtrace when running a GDB session. Might be a divide by zero issue in SDL or SDL_mixer.

Program received signal SIGFPE, Arithmetic exception.
0x00000038e8c08a7d in mix_channels (udata=<optimized out>, stream=0x24e11b0 "", len=2048) at mixer.c:345
345 Mix_Volume(i, (mix_channel[i].fade_volume * ticks) / mix_channel[i].fade_length );
(gdb) bt f
#0 0x00000038e8c08a7d in mix_channels (udata=<optimized out>, stream=0x24e11b0 "", len=2048) at mixer.c:345
ticks = 0
mix_input = <optimized out>
i = 0
mixable = <optimized out>
volume = <optimized out>
sdl_ticks = 129373

Using SDL 2.0.3 and SDL_Mixer 2.0.0, PulseAudio, Fedora 20 x86_64 but looks like can be reproduced on other platforms.
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #ifdef MODPLUG_MUSIC
    23 
    24 #ifdef MODPLUG_HEADER
    25 #include MODPLUG_HEADER
    26 #else
    27 #include <libmodplug/modplug.h>
    28 #endif
    29 #include "SDL_rwops.h"
    30 #include "SDL_audio.h"
    31 #include "SDL_mixer.h"
    32 
    33 typedef struct {
    34     ModPlugFile *file;
    35     int playing;
    36 } modplug_data;
    37 
    38 int modplug_init(SDL_AudioSpec *mixer);
    39 
    40 /* Uninitialize the music players */
    41 void modplug_exit(void);
    42 
    43 /* Set the volume for a modplug stream */
    44 void modplug_setvolume(modplug_data *music, int volume);
    45 
    46 /* Load a modplug stream from an SDL_RWops object */
    47 modplug_data *modplug_new_RW(SDL_RWops *rw, int freerw);
    48 
    49 /* Start playback of a given modplug stream */
    50 void modplug_play(modplug_data *music);
    51 
    52 /* Return non-zero if a stream is currently playing */
    53 int modplug_playing(modplug_data *music);
    54 
    55 /* Play some of a stream previously started with modplug_play() */
    56 int modplug_playAudio(modplug_data *music, Uint8 *stream, int len);
    57 
    58 /* Stop playback of a stream previously started with modplug_play() */
    59 void modplug_stop(modplug_data *music);
    60 
    61 /* Close the given modplug stream */
    62 void modplug_delete(modplug_data *music);
    63 
    64 /* Jump (seek) to a given position (time is in seconds) */
    65 void modplug_jump_to_time(modplug_data *music, double time);
    66 
    67 #endif /* MODPLUG_MUSIC */