From f7e9925195c3943d02cdfd1cf4ff622a415ff19c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 29 Jan 2016 12:44:13 -0800 Subject: [PATCH] Added Mix_OpenAudioDevice() so you can specify the audio device to open --- CHANGES.txt | 4 ++ SDL_mixer.h | 3 + effect_position.c | 33 +++++----- mixer.c | 110 ++++++++++++++++++------------- mixer.h | 25 +++++++ music.c | 49 +++++++------- native_midi/native_midi_mac.c | 5 +- native_midi/native_midi_macosx.c | 11 ++-- wavestream.c | 4 +- 9 files changed, 150 insertions(+), 94 deletions(-) create mode 100644 mixer.h diff --git a/CHANGES.txt b/CHANGES.txt index 1eb08349..f56a7369 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +2.0.1: +Juha Kuikka - Fri Jan 29 12:44:01 PST 2016 + * Added Mix_OpenAudioDevice() so you can specify the audio device to open + 2.0.1: Sam Lantinga - Tue Jul 7 11:40:33 PDT 2015 * Added support for 'smpl' format loop points in music WAV files diff --git a/SDL_mixer.h b/SDL_mixer.h index 71c1f5c7..866dc1b6 100644 --- a/SDL_mixer.h +++ b/SDL_mixer.h @@ -133,6 +133,9 @@ typedef struct _Mix_Music Mix_Music; /* Open the mixer with a certain audio format */ extern DECLSPEC int SDLCALL Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize); +/* Open the mixer with specific device and certain audio format */ +extern DECLSPEC int SDLCALL Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char* device, int allowed_changes); + /* Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels are stopped. diff --git a/effect_position.c b/effect_position.c index 2ec1c42d..c18eda8b 100644 --- a/effect_position.c +++ b/effect_position.c @@ -31,8 +31,9 @@ #include #include "SDL.h" -#include "SDL_mixer.h" #include "SDL_endian.h" +#include "SDL_mixer.h" +#include "mixer.h" #define __MIX_INTERNAL_EFFECT__ #include "effects_internal.h" @@ -1453,10 +1454,10 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) if (f == NULL) return(0); - SDL_LockAudio(); + Mix_LockAudio(); args = get_position_arg(channel); if (!args) { - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(0); } @@ -1464,10 +1465,10 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) if ((args->distance_u8 == 255) && (left == 255) && (right == 255)) { if (args->in_use) { retval = _Mix_UnregisterEffect_locked(channel, f); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } else { - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(1); } } @@ -1483,7 +1484,7 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) retval=_Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void*)args); } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } @@ -1501,10 +1502,10 @@ int Mix_SetDistance(int channel, Uint8 distance) if (f == NULL) return(0); - SDL_LockAudio(); + Mix_LockAudio(); args = get_position_arg(channel); if (!args) { - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(0); } @@ -1514,10 +1515,10 @@ int Mix_SetDistance(int channel, Uint8 distance) if ((distance == 255) && (args->left_u8 == 255) && (args->right_u8 == 255)) { if (args->in_use) { retval = _Mix_UnregisterEffect_locked(channel, f); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } else { - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(1); } } @@ -1529,7 +1530,7 @@ int Mix_SetDistance(int channel, Uint8 distance) retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args); } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } @@ -1550,10 +1551,10 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) angle = SDL_abs(angle) % 360; /* make angle between 0 and 359. */ - SDL_LockAudio(); + Mix_LockAudio(); args = get_position_arg(channel); if (!args) { - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(0); } @@ -1561,10 +1562,10 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) if ((!distance) && (!angle)) { if (args->in_use) { retval = _Mix_UnregisterEffect_locked(channel, f); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } else { - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(1); } } @@ -1610,7 +1611,7 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args); } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } diff --git a/mixer.c b/mixer.c index bebb6c09..af4d0335 100644 --- a/mixer.c +++ b/mixer.c @@ -30,6 +30,7 @@ #include "SDL_timer.h" #include "SDL_mixer.h" +#include "mixer.h" #include "load_aiff.h" #include "load_voc.h" #include "load_mp3.h" @@ -55,6 +56,7 @@ static int audio_opened = 0; static SDL_AudioSpec mixer; +static SDL_AudioDeviceID audio_device; typedef struct _Mix_effectinfo { @@ -257,7 +259,7 @@ static int _Mix_remove_all_effects(int channel, effect_info **e); /* * rcg06122001 Cleanup effect callbacks. - * MAKE SURE SDL_LockAudio() is called before this (or you're in the + * MAKE SURE Mix_LockAudio() is called before this (or you're in the * audio callback). */ static void _Mix_channel_done_playing(int channel) @@ -362,7 +364,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len) } mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable); - SDL_MixAudio(stream+index,mix_input,mixable,volume); + SDL_MixAudioFormat(stream+index,mix_input,mixer.format,mixable,volume); if (mix_input != mix_channel[i].samples) SDL_free(mix_input); @@ -386,7 +388,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len) } mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining); - SDL_MixAudio(stream+index, mix_input, remaining, volume); + SDL_MixAudioFormat(stream+index, mix_input, mixer.format, remaining, volume); if (mix_input != mix_channel[i].chunk->abuf) SDL_free(mix_input); @@ -426,9 +428,9 @@ static void PrintFormat(char *title, SDL_AudioSpec *fmt) } #endif - /* Open the mixer with a certain desired audio format */ -int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize) +int Mix_OpenAudioDevice(int frequency, Uint16 format, int nchannels, int chunksize, + const char* device, int allowed_changes) { int i; SDL_AudioSpec desired; @@ -453,7 +455,7 @@ int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize) desired.userdata = NULL; /* Accept nearly any audio format */ - if ( SDL_OpenAudio(&desired, &mixer) < 0 ) { + if ( (audio_device = SDL_OpenAudioDevice(device, 0, &desired, &mixer, allowed_changes)) == 0 ) { return(-1); } #if 0 @@ -462,7 +464,7 @@ int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize) /* Initialize the music players */ if ( open_music(&mixer) < 0 ) { - SDL_CloseAudio(); + SDL_CloseAudioDevice(audio_device); return(-1); } @@ -502,10 +504,17 @@ int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize) #endif audio_opened = 1; - SDL_PauseAudio(0); + SDL_PauseAudioDevice(audio_device, 0); return(0); } +/* Open the mixer with a certain desired audio format */ +int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize) +{ + return Mix_OpenAudioDevice(frequency, format, nchannels, chunksize, + NULL, SDL_AUDIO_ALLOW_ANY_CHANGE); +} + /* Dynamically change the number of channels managed by the mixer. If decreasing the number of channels, the upper channels are stopped. @@ -523,7 +532,7 @@ int Mix_AllocateChannels(int numchans) Mix_HaltChannel(i); } } - SDL_LockAudio(); + Mix_LockAudio(); mix_channel = (struct _Mix_Channel *) SDL_realloc(mix_channel, numchans * sizeof(struct _Mix_Channel)); if ( numchans > num_channels ) { /* Initialize the new channels */ @@ -543,7 +552,7 @@ int Mix_AllocateChannels(int numchans) } } num_channels = numchans; - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(num_channels); } @@ -786,7 +795,7 @@ void Mix_FreeChunk(Mix_Chunk *chunk) /* Caution -- if the chunk is playing, the mixer will crash */ if ( chunk ) { /* Guarantee that this chunk isn't playing */ - SDL_LockAudio(); + Mix_LockAudio(); if ( mix_channel ) { for ( i=0; iallocated ) { SDL_free(chunk->abuf); @@ -811,10 +820,10 @@ void Mix_FreeChunk(Mix_Chunk *chunk) void Mix_SetPostMix(void (*mix_func) (void *udata, Uint8 *stream, int len), void *arg) { - SDL_LockAudio(); + Mix_LockAudio(); mix_postmix_data = arg; mix_postmix = mix_func; - SDL_UnlockAudio(); + Mix_UnlockAudio(); } /* Add your own music player or mixer function. @@ -823,7 +832,7 @@ void Mix_SetPostMix(void (*mix_func) void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len), void *arg) { - SDL_LockAudio(); + Mix_LockAudio(); if ( mix_func != NULL ) { music_data = arg; mix_music = mix_func; @@ -831,7 +840,7 @@ void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len), music_data = NULL; mix_music = music_mixer; } - SDL_UnlockAudio(); + Mix_UnlockAudio(); } void *Mix_GetMusicHookData(void) @@ -841,9 +850,9 @@ void *Mix_GetMusicHookData(void) void Mix_ChannelFinished(void (*channel_finished)(int channel)) { - SDL_LockAudio(); + Mix_LockAudio(); channel_done_callback = channel_finished; - SDL_UnlockAudio(); + Mix_UnlockAudio(); } @@ -890,7 +899,7 @@ int Mix_PlayChannelTimed(int which, Mix_Chunk *chunk, int loops, int ticks) } /* Lock the mixer while modifying the playing channels */ - SDL_LockAudio(); + Mix_LockAudio(); { /* If which is -1, play on the first free channel */ if ( which == -1 ) { @@ -921,7 +930,7 @@ int Mix_PlayChannelTimed(int which, Mix_Chunk *chunk, int loops, int ticks) mix_channel[which].expire = (ticks>0) ? (sdl_ticks + ticks) : 0; } } - SDL_UnlockAudio(); + Mix_UnlockAudio(); /* Return the channel on which the sound is being played */ return(which); @@ -938,9 +947,9 @@ int Mix_ExpireChannel(int which, int ticks) status += Mix_ExpireChannel(i, ticks); } } else if ( which < num_channels ) { - SDL_LockAudio(); + Mix_LockAudio(); mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0; - SDL_UnlockAudio(); + Mix_UnlockAudio(); ++ status; } return(status); @@ -961,7 +970,7 @@ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int t } /* Lock the mixer while modifying the playing channels */ - SDL_LockAudio(); + Mix_LockAudio(); { /* If which is -1, play on the first free channel */ if ( which == -1 ) { @@ -995,7 +1004,7 @@ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int t mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0; } } - SDL_UnlockAudio(); + Mix_UnlockAudio(); /* Return the channel on which the sound is being played */ return(which); @@ -1048,7 +1057,7 @@ int Mix_HaltChannel(int which) Mix_HaltChannel(i); } } else if ( which < num_channels ) { - SDL_LockAudio(); + Mix_LockAudio(); if (mix_channel[which].playing) { _Mix_channel_done_playing(which); mix_channel[which].playing = 0; @@ -1058,7 +1067,7 @@ int Mix_HaltChannel(int which) if(mix_channel[which].fading != MIX_NO_FADING) /* Restore volume */ mix_channel[which].volume = mix_channel[which].fade_volume_reset; mix_channel[which].fading = MIX_NO_FADING; - SDL_UnlockAudio(); + Mix_UnlockAudio(); } return(0); } @@ -1090,7 +1099,7 @@ int Mix_FadeOutChannel(int which, int ms) status += Mix_FadeOutChannel(i, ms); } } else if ( which < num_channels ) { - SDL_LockAudio(); + Mix_LockAudio(); if ( mix_channel[which].playing && (mix_channel[which].volume > 0) && (mix_channel[which].fading != MIX_FADING_OUT) ) { @@ -1105,7 +1114,7 @@ int Mix_FadeOutChannel(int which, int ms) } ++status; } - SDL_UnlockAudio(); + Mix_UnlockAudio(); } } return(status); @@ -1186,7 +1195,8 @@ void Mix_CloseAudio(void) close_music(); Mix_HaltChannel(-1); _Mix_DeinitEffects(); - SDL_CloseAudio(); + SDL_CloseAudioDevice(audio_device); + audio_device = 0; SDL_free(mix_channel); mix_channel = NULL; @@ -1223,7 +1233,7 @@ void Mix_Resume(int which) { Uint32 sdl_ticks = SDL_GetTicks(); - SDL_LockAudio(); + Mix_LockAudio(); if ( which == -1 ) { int i; @@ -1241,7 +1251,7 @@ void Mix_Resume(int which) mix_channel[which].paused = 0; } } - SDL_UnlockAudio(); + Mix_UnlockAudio(); } int Mix_Paused(int which) @@ -1268,9 +1278,9 @@ int Mix_GroupChannel(int which, int tag) if ( which < 0 || which > num_channels ) return(0); - SDL_LockAudio(); + Mix_LockAudio(); mix_channel[which].tag = tag; - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(1); } @@ -1347,7 +1357,7 @@ int Mix_GroupNewer(int tag) * as Mix_SetPanning(). */ -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */ +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg) { @@ -1392,7 +1402,7 @@ static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f, } -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */ +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ static int _Mix_remove_effect(int channel, effect_info **e, Mix_EffectFunc_t f) { effect_info *cur; @@ -1427,7 +1437,7 @@ static int _Mix_remove_effect(int channel, effect_info **e, Mix_EffectFunc_t f) } -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */ +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ static int _Mix_remove_all_effects(int channel, effect_info **e) { effect_info *cur; @@ -1451,7 +1461,7 @@ static int _Mix_remove_all_effects(int channel, effect_info **e) } -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */ +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ int _Mix_RegisterEffect_locked(int channel, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg) { @@ -1474,14 +1484,14 @@ int Mix_RegisterEffect(int channel, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg) { int retval; - SDL_LockAudio(); + Mix_LockAudio(); retval = _Mix_RegisterEffect_locked(channel, f, d, arg); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return retval; } -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */ +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ int _Mix_UnregisterEffect_locked(int channel, Mix_EffectFunc_t f) { effect_info **e = NULL; @@ -1502,13 +1512,13 @@ int _Mix_UnregisterEffect_locked(int channel, Mix_EffectFunc_t f) int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f) { int retval; - SDL_LockAudio(); + Mix_LockAudio(); retval = _Mix_UnregisterEffect_locked(channel, f); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */ +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ int _Mix_UnregisterAllEffects_locked(int channel) { effect_info **e = NULL; @@ -1529,11 +1539,21 @@ int _Mix_UnregisterAllEffects_locked(int channel) int Mix_UnregisterAllEffects(int channel) { int retval; - SDL_LockAudio(); + Mix_LockAudio(); retval = _Mix_UnregisterAllEffects_locked(channel); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } +void Mix_LockAudio() +{ + SDL_LockAudioDevice(audio_device); +} + +void Mix_UnlockAudio() +{ + SDL_UnlockAudioDevice(audio_device); +} + /* end of mixer.c ... */ diff --git a/mixer.h b/mixer.h new file mode 100644 index 00000000..c095f628 --- /dev/null +++ b/mixer.h @@ -0,0 +1,25 @@ +/* + SDL_mixer: An audio mixer library based on the SDL library + Copyright (C) 1997-2016 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* Locking wrapper functions */ +void Mix_LockAudio(); +void Mix_UnlockAudio(); + diff --git a/music.c b/music.c index bbaf4a31..373543ed 100644 --- a/music.c +++ b/music.c @@ -30,6 +30,7 @@ #include "SDL_timer.h" #include "SDL_mixer.h" +#include "mixer.h" #ifdef CMD_MUSIC #include "music_cmd.h" @@ -185,9 +186,9 @@ static void (*music_finished_hook)(void) = NULL; void Mix_HookMusicFinished(void (*music_finished)(void)) { - SDL_LockAudio(); + Mix_LockAudio(); music_finished_hook = music_finished; - SDL_UnlockAudio(); + Mix_UnlockAudio(); } @@ -765,19 +766,19 @@ void Mix_FreeMusic(Mix_Music *music) { if ( music ) { /* Stop the music if it's currently playing */ - SDL_LockAudio(); + Mix_LockAudio(); if ( music == music_playing ) { /* Wait for any fade out to finish */ while ( music->fading == MIX_FADING_OUT ) { - SDL_UnlockAudio(); + Mix_UnlockAudio(); SDL_Delay(100); - SDL_LockAudio(); + Mix_LockAudio(); } if ( music == music_playing ) { music_internal_halt(); } } - SDL_UnlockAudio(); + Mix_UnlockAudio(); switch (music->type) { #ifdef CMD_MUSIC case MUS_CMD: @@ -861,11 +862,11 @@ Mix_MusicType Mix_GetMusicType(const Mix_Music *music) if ( music ) { type = music->type; } else { - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing ) { type = music_playing->type; } - SDL_UnlockAudio(); + Mix_UnlockAudio(); } return(type); } @@ -1018,12 +1019,12 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) music->fade_steps = ms/ms_per_step; /* Play the puppy */ - SDL_LockAudio(); + Mix_LockAudio(); /* If the current music is fading out, wait for the fade to complete */ while ( music_playing && (music_playing->fading == MIX_FADING_OUT) ) { - SDL_UnlockAudio(); + Mix_UnlockAudio(); SDL_Delay(100); - SDL_LockAudio(); + Mix_LockAudio(); } music_active = 1; if (loops == 1) { @@ -1032,7 +1033,7 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) } music_loops = loops; retval = music_internal_play(music, position); - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } @@ -1096,7 +1097,7 @@ int Mix_SetMusicPosition(double position) { int retval; - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing ) { retval = music_internal_position(position); if ( retval < 0 ) { @@ -1106,7 +1107,7 @@ int Mix_SetMusicPosition(double position) Mix_SetError("Music isn't playing"); retval = -1; } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } @@ -1204,11 +1205,11 @@ int Mix_VolumeMusic(int volume) volume = SDL_MIX_MAXVOLUME; } music_volume = volume; - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing ) { music_internal_volume(music_volume); } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(prev_volume); } @@ -1289,14 +1290,14 @@ static void music_internal_halt(void) } int Mix_HaltMusic(void) { - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing ) { music_internal_halt(); if ( music_finished_hook ) { music_finished_hook(); } } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(0); } @@ -1316,7 +1317,7 @@ int Mix_FadeOutMusic(int ms) return 1; } - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing) { int fade_steps = (ms + ms_per_step - 1)/ms_per_step; if ( music_playing->fading == MIX_NO_FADING ) { @@ -1337,7 +1338,7 @@ int Mix_FadeOutMusic(int ms) music_playing->fade_steps = fade_steps; retval = 1; } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(retval); } @@ -1346,11 +1347,11 @@ Mix_Fading Mix_FadingMusic(void) { Mix_Fading fading = MIX_NO_FADING; - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing ) { fading = music_playing->fading; } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(fading); } @@ -1478,11 +1479,11 @@ int Mix_PlayingMusic(void) { int playing = 0; - SDL_LockAudio(); + Mix_LockAudio(); if ( music_playing ) { playing = music_loops || music_internal_playing(); } - SDL_UnlockAudio(); + Mix_UnlockAudio(); return(playing); } diff --git a/native_midi/native_midi_mac.c b/native_midi/native_midi_mac.c index 0a632868..bc5f1079 100644 --- a/native_midi/native_midi_mac.c +++ b/native_midi/native_midi_mac.c @@ -20,6 +20,7 @@ */ #include "SDL_config.h" #include "SDL_endian.h" +#include "../mixer.h" #if __MACOS__ /*|| __MACOSX__ */ @@ -187,7 +188,7 @@ void native_midi_start(NativeMidiSong *song, int loops) assert (loops == 0); SDL_PauseAudio(1); - SDL_UnlockAudio(); + Mix_UnlockAudio(); /* First, stop the currently playing music */ native_midi_stop(); @@ -237,7 +238,7 @@ void native_midi_start(NativeMidiSong *song, int loops) } done: - SDL_LockAudio(); + Mix_LockAudio(); SDL_PauseAudio(0); } diff --git a/native_midi/native_midi_macosx.c b/native_midi/native_midi_macosx.c index fa48680d..27585e87 100644 --- a/native_midi/native_midi_macosx.c +++ b/native_midi/native_midi_macosx.c @@ -31,8 +31,9 @@ #include #include -#include "../SDL_mixer.h" #include "SDL_endian.h" +#include "../SDL_mixer.h" +#include "../mixer.h" #include "native_midi.h" /* Native Midi song */ @@ -264,7 +265,7 @@ void native_midi_start(NativeMidiSong *song, int loops) return; SDL_PauseAudio(1); - SDL_UnlockAudio(); + Mix_UnlockAudio(); if (currentsong) MusicPlayerStop(currentsong->player); @@ -282,7 +283,7 @@ void native_midi_start(NativeMidiSong *song, int loops) latched_volume++; /* just make this not match. */ native_midi_setvolume(vol); - SDL_LockAudio(); + Mix_LockAudio(); SDL_PauseAudio(0); } @@ -290,10 +291,10 @@ void native_midi_stop() { if (currentsong) { SDL_PauseAudio(1); - SDL_UnlockAudio(); + Mix_UnlockAudio(); MusicPlayerStop(currentsong->player); currentsong = NULL; - SDL_LockAudio(); + Mix_LockAudio(); SDL_PauseAudio(0); } } diff --git a/wavestream.c b/wavestream.c index 8dc1683e..cd039a59 100644 --- a/wavestream.c +++ b/wavestream.c @@ -241,7 +241,7 @@ static int PlaySome(Uint8 *stream, int len) } music->cvt.len = original_len; SDL_ConvertAudio(&music->cvt); - SDL_MixAudio(stream, music->cvt.buf, music->cvt.len_cvt, wavestream_volume); + SDL_MixAudioFormat(stream, music->cvt.buf, mixer.format,music->cvt.len_cvt, wavestream_volume); consumed = music->cvt.len_cvt; } else { Uint8 *data; @@ -251,7 +251,7 @@ static int PlaySome(Uint8 *stream, int len) data = SDL_stack_alloc(Uint8, len); if (data) { len = SDL_RWread(music->src, data, 1, len); - SDL_MixAudio(stream, data, len, wavestream_volume); + SDL_MixAudioFormat(stream, data, mixer.format, len, wavestream_volume); SDL_stack_free(data); } consumed = len;