Bye bye SoundManager, you are officially obsolete...
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Sep 2009 09:03:35 +0000
changeset 3242af4a5af3cd2b
parent 3241 08c5964f2a34
child 3243 5db962a9a991
Bye bye SoundManager, you are officially obsolete...
configure.in
include/SDL_config.h.in
include/SDL_config_macosx.h
src/audio/SDL_audio.c
src/audio/macosx/SDL_coreaudio.c
src/audio/macrom/SDL_romaudio.c
src/audio/macrom/SDL_romaudio.h
     1.1 --- a/configure.in	Sat Sep 05 07:33:54 2009 +0000
     1.2 +++ b/configure.in	Sat Sep 05 09:03:35 2009 +0000
     1.3 @@ -2883,8 +2883,6 @@
     1.4          if test x$enable_audio = xyes; then
     1.5              AC_DEFINE(SDL_AUDIO_DRIVER_COREAUDIO)
     1.6              SOURCES="$SOURCES $srcdir/src/audio/macosx/*.c"
     1.7 -            AC_DEFINE(SDL_AUDIO_DRIVER_SNDMGR)
     1.8 -            SOURCES="$SOURCES $srcdir/src/audio/macrom/*.c"
     1.9              have_audio=yes
    1.10          fi
    1.11          # Set up files for the atomic operations library
     2.1 --- a/include/SDL_config.h.in	Sat Sep 05 07:33:54 2009 +0000
     2.2 +++ b/include/SDL_config.h.in	Sat Sep 05 09:03:35 2009 +0000
     2.3 @@ -199,7 +199,6 @@
     2.4  #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
     2.5  #undef SDL_AUDIO_DRIVER_PAUDIO
     2.6  #undef SDL_AUDIO_DRIVER_QSA
     2.7 -#undef SDL_AUDIO_DRIVER_SNDMGR
     2.8  #undef SDL_AUDIO_DRIVER_SUNAUDIO
     2.9  #undef SDL_AUDIO_DRIVER_WINWAVEOUT
    2.10  #undef SDL_AUDIO_DRIVER_FUSIONSOUND
     3.1 --- a/include/SDL_config_macosx.h	Sat Sep 05 07:33:54 2009 +0000
     3.2 +++ b/include/SDL_config_macosx.h	Sat Sep 05 09:03:35 2009 +0000
     3.3 @@ -103,7 +103,6 @@
     3.4  
     3.5  /* Enable various audio drivers */
     3.6  #define SDL_AUDIO_DRIVER_COREAUDIO	1
     3.7 -#define SDL_AUDIO_DRIVER_SNDMGR	1
     3.8  #define SDL_AUDIO_DRIVER_DISK	1
     3.9  #define SDL_AUDIO_DRIVER_DUMMY	1
    3.10  
     4.1 --- a/src/audio/SDL_audio.c	Sat Sep 05 07:33:54 2009 +0000
     4.2 +++ b/src/audio/SDL_audio.c	Sat Sep 05 09:03:35 2009 +0000
     4.3 @@ -127,9 +127,6 @@
     4.4  #if SDL_AUDIO_DRIVER_COREAUDIOIPHONE
     4.5      &COREAUDIOIPHONE_bootstrap,
     4.6  #endif
     4.7 -#if SDL_AUDIO_DRIVER_SNDMGR
     4.8 -    &SNDMGR_bootstrap,
     4.9 -#endif
    4.10  #if SDL_AUDIO_DRIVER_MINT
    4.11      &MINTAUDIO_GSXB_bootstrap,
    4.12      &MINTAUDIO_MCSN_bootstrap,
     5.1 --- a/src/audio/macosx/SDL_coreaudio.c	Sat Sep 05 07:33:54 2009 +0000
     5.2 +++ b/src/audio/macosx/SDL_coreaudio.c	Sat Sep 05 09:03:35 2009 +0000
     5.3 @@ -22,8 +22,9 @@
     5.4  #include "SDL_config.h"
     5.5  
     5.6  #include <CoreAudio/CoreAudio.h>
     5.7 +#include <CoreServices/CoreServices.h>
     5.8  #include <AudioUnit/AudioUnit.h>
     5.9 -#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
    5.10 +#if MAC_OS_X_VERSION_MAX_ALLOWED == 1050
    5.11  #include <AudioUnit/AUNTComponent.h>
    5.12  #endif
    5.13  
     6.1 --- a/src/audio/macrom/SDL_romaudio.c	Sat Sep 05 07:33:54 2009 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,319 +0,0 @@
     6.4 -/*
     6.5 -    SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997-2009 Sam Lantinga
     6.7 -
     6.8 -    This library is free software; you can redistribute it and/or
     6.9 -    modify it under the terms of the GNU Lesser General Public
    6.10 -    License as published by the Free Software Foundation; either
    6.11 -    version 2.1 of the License, or (at your option) any later version.
    6.12 -
    6.13 -    This library is distributed in the hope that it will be useful,
    6.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 -    Lesser General Public License for more details.
    6.17 -
    6.18 -    You should have received a copy of the GNU Lesser General Public
    6.19 -    License along with this library; if not, write to the Free Software
    6.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 -
    6.22 -    Sam Lantinga
    6.23 -    slouken@libsdl.org
    6.24 -*/
    6.25 -#include "SDL_config.h"
    6.26 -
    6.27 -/* This should work on PowerPC and Intel Mac OS X, and Carbonized Mac OS 9. */
    6.28 -
    6.29 -#if defined(__APPLE__) && defined(__MACH__)
    6.30 -#  define SDL_MACOS_NAME "Mac OS X"
    6.31 -#  include <Carbon/Carbon.h>
    6.32 -#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
    6.33 -#  define SDL_MACOS_NAME "Mac OS 9"
    6.34 -#  include <Carbon.h>
    6.35 -#else
    6.36 -#  define SDL_MACOS_NAME "Mac OS 9"
    6.37 -#  include <Sound.h>            /* SoundManager interface */
    6.38 -#  include <Gestalt.h>
    6.39 -#  include <DriverServices.h>
    6.40 -#endif
    6.41 -
    6.42 -#if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335)
    6.43 -#if !defined(NewSndCallBackProc)        /* avoid circular redefinition... */
    6.44 -#define NewSndCallBackUPP NewSndCallBackProc
    6.45 -#endif
    6.46 -#if !defined(NewSndCallBackUPP)
    6.47 -#define NewSndCallBackUPP NewSndCallBackProc
    6.48 -#endif
    6.49 -#endif
    6.50 -
    6.51 -#include "SDL_audio.h"
    6.52 -#include "../SDL_audio_c.h"
    6.53 -#include "../SDL_sysaudio.h"
    6.54 -#include "SDL_romaudio.h"
    6.55 -
    6.56 -#pragma options align=power
    6.57 -
    6.58 -static volatile SInt32 audio_is_locked = 0;
    6.59 -static volatile SInt32 need_to_mix = 0;
    6.60 -
    6.61 -static UInt8 *buffer[2];
    6.62 -static volatile UInt32 running = 0;
    6.63 -static CmpSoundHeader header;
    6.64 -static volatile Uint32 fill_me = 0;
    6.65 -
    6.66 -
    6.67 -static void
    6.68 -mix_buffer(SDL_AudioDevice * audio, UInt8 * buffer)
    6.69 -{
    6.70 -    if (!audio->paused) {
    6.71 -#ifdef __MACOSX__
    6.72 -        SDL_mutexP(audio->mixer_lock);
    6.73 -#endif
    6.74 -        if (audio->convert.needed) {
    6.75 -            audio->spec.callback(audio->spec.userdata,
    6.76 -                                 (Uint8 *) audio->convert.buf,
    6.77 -                                 audio->convert.len);
    6.78 -            SDL_ConvertAudio(&audio->convert);
    6.79 -            if (audio->convert.len_cvt != audio->spec.size) {
    6.80 -                /* Uh oh... probably crashes here */ ;
    6.81 -            }
    6.82 -            SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
    6.83 -        } else {
    6.84 -            audio->spec.callback(audio->spec.userdata, buffer,
    6.85 -                                 audio->spec.size);
    6.86 -        }
    6.87 -#ifdef __MACOSX__
    6.88 -        SDL_mutexV(audio->mixer_lock);
    6.89 -#endif
    6.90 -    }
    6.91 -
    6.92 -    DecrementAtomic((SInt32 *) & need_to_mix);
    6.93 -}
    6.94 -
    6.95 -#ifndef __MACOSX__
    6.96 -static void
    6.97 -SNDMGR_LockDevice(_THIS)
    6.98 -{
    6.99 -    IncrementAtomic((SInt32 *) & audio_is_locked);
   6.100 -}
   6.101 -
   6.102 -static void
   6.103 -SNDMGR_UnlockDevice(_THIS)
   6.104 -{
   6.105 -    SInt32 oldval;
   6.106 -
   6.107 -    oldval = DecrementAtomic((SInt32 *) & audio_is_locked);
   6.108 -    if (oldval != 1)            /* != 1 means audio is still locked. */
   6.109 -        return;
   6.110 -
   6.111 -    /* Did we miss the chance to mix in an interrupt? Do it now. */
   6.112 -    if (BitAndAtomic(0xFFFFFFFF, (UInt32 *) & need_to_mix)) {
   6.113 -        /*
   6.114 -         * Note that this could be a problem if you missed an interrupt
   6.115 -         *  while the audio was locked, and get preempted by a second
   6.116 -         *  interrupt here, but that means you locked for way too long anyhow.
   6.117 -         */
   6.118 -        mix_buffer(this, buffer[fill_me]);
   6.119 -    }
   6.120 -}
   6.121 -#endif // __MACOSX__
   6.122 -
   6.123 -static void
   6.124 -callBackProc(SndChannel * chan, SndCommand * cmd_passed)
   6.125 -{
   6.126 -    UInt32 play_me;
   6.127 -    SndCommand cmd;
   6.128 -    SDL_AudioDevice *audio = (SDL_AudioDevice *) chan->userInfo;
   6.129 -
   6.130 -    IncrementAtomic((SInt32 *) & need_to_mix);
   6.131 -
   6.132 -    fill_me = cmd_passed->param2;       /* buffer that has just finished playing, so fill it */
   6.133 -    play_me = !fill_me;         /* filled buffer to play _now_ */
   6.134 -
   6.135 -    if (!audio->enabled) {
   6.136 -        return;
   6.137 -    }
   6.138 -
   6.139 -    /* queue previously mixed buffer for playback. */
   6.140 -    header.samplePtr = (Ptr) buffer[play_me];
   6.141 -    cmd.cmd = bufferCmd;
   6.142 -    cmd.param1 = 0;
   6.143 -    cmd.param2 = (long) &header;
   6.144 -    SndDoCommand(chan, &cmd, 0);
   6.145 -
   6.146 -    SDL_memset(buffer[fill_me], 0, audio->spec.size);
   6.147 -
   6.148 -    /*
   6.149 -     * if audio device isn't locked, mix the next buffer to be queued in
   6.150 -     *  the memory block that just finished playing.
   6.151 -     */
   6.152 -    if (!BitAndAtomic(0xFFFFFFFF, (UInt32 *) & audio_is_locked)) {
   6.153 -        mix_buffer(audio, buffer[fill_me]);
   6.154 -    }
   6.155 -
   6.156 -    /* set this callback to run again when current buffer drains. */
   6.157 -    if (running) {
   6.158 -        cmd.cmd = callBackCmd;
   6.159 -        cmd.param1 = 0;
   6.160 -        cmd.param2 = play_me;
   6.161 -
   6.162 -        SndDoCommand(chan, &cmd, 0);
   6.163 -    }
   6.164 -}
   6.165 -
   6.166 -static void
   6.167 -SNDMGR_CloseDevice(_THIS)
   6.168 -{
   6.169 -    running = 0;
   6.170 -
   6.171 -    if (this->hidden != NULL) {
   6.172 -        if (this->hidden->channel) {
   6.173 -            SndDisposeChannel(this->hidden->channel, true);
   6.174 -            this->hidden->channel = NULL;
   6.175 -        }
   6.176 -
   6.177 -        SDL_free(buffer[0]);
   6.178 -        SDL_free(buffer[1]);
   6.179 -        buffer[0] = buffer[1] = NULL;
   6.180 -
   6.181 -        SDL_free(this->hidden);
   6.182 -        this->hidden = NULL;
   6.183 -    }
   6.184 -}
   6.185 -
   6.186 -static int
   6.187 -SNDMGR_OpenDevice(_THIS, const char *devname, int iscapture)
   6.188 -{
   6.189 -    SDL_AudioSpec *spec = &this->spec;
   6.190 -    SndChannelPtr channel = NULL;
   6.191 -    SndCallBackUPP callback;
   6.192 -    int sample_bits;
   6.193 -    int i;
   6.194 -    long initOptions;
   6.195 -
   6.196 -    /* Initialize all variables that we clean on shutdown */
   6.197 -    this->hidden = (struct SDL_PrivateAudioData *)
   6.198 -        SDL_malloc((sizeof *this->hidden));
   6.199 -    if (this->hidden == NULL) {
   6.200 -        SDL_OutOfMemory();
   6.201 -        return 0;
   6.202 -    }
   6.203 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   6.204 -
   6.205 -    /* !!! FIXME: iterate through format matrix... */
   6.206 -    /* Very few conversions are required, but... */
   6.207 -    switch (spec->format) {
   6.208 -    case AUDIO_S8:
   6.209 -        spec->format = AUDIO_U8;
   6.210 -        break;
   6.211 -    case AUDIO_U16LSB:
   6.212 -        spec->format = AUDIO_S16LSB;
   6.213 -        break;
   6.214 -    case AUDIO_U16MSB:
   6.215 -        spec->format = AUDIO_S16MSB;
   6.216 -        break;
   6.217 -    case AUDIO_F32LSB:
   6.218 -        spec->format = AUDIO_F32MSB;
   6.219 -        break;
   6.220 -    }
   6.221 -    SDL_CalculateAudioSpec(&this->spec);
   6.222 -
   6.223 -    /* initialize bufferCmd header */
   6.224 -    SDL_memset(&header, 0, sizeof(header));
   6.225 -    callback = (SndCallBackUPP) NewSndCallBackUPP(callBackProc);
   6.226 -    sample_bits = spec->size / spec->samples / spec->channels * 8;
   6.227 -
   6.228 -#ifdef DEBUG_AUDIO
   6.229 -    fprintf(stderr,
   6.230 -            "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n",
   6.231 -            spec->format, spec->channels, sample_bits, spec->freq);
   6.232 -#endif /* DEBUG_AUDIO */
   6.233 -
   6.234 -    header.numChannels = spec->channels;
   6.235 -    header.sampleSize = sample_bits;
   6.236 -    header.sampleRate = spec->freq << 16;
   6.237 -    header.numFrames = spec->samples;
   6.238 -    header.encode = cmpSH;
   6.239 -
   6.240 -    /* Note that we install the 16bitLittleEndian Converter if needed. */
   6.241 -    if (spec->format == AUDIO_S16LSB) {
   6.242 -        header.compressionID = fixedCompression;
   6.243 -        header.format = k16BitLittleEndianFormat;
   6.244 -    } else if (spec->format == AUDIO_S32MSB) {
   6.245 -        header.compressionID = fixedCompression;
   6.246 -        header.format = k32BitFormat;
   6.247 -    } else if (spec->format == AUDIO_S32LSB) {
   6.248 -        header.compressionID = fixedCompression;
   6.249 -        header.format = k32BitLittleEndianFormat;
   6.250 -    } else if (spec->format == AUDIO_F32MSB) {
   6.251 -        header.compressionID = fixedCompression;
   6.252 -        header.format = kFloat32Format;
   6.253 -    }
   6.254 -
   6.255 -    /* allocate 2 buffers */
   6.256 -    for (i = 0; i < 2; i++) {
   6.257 -        buffer[i] = (UInt8 *) SDL_malloc(sizeof(UInt8) * spec->size);
   6.258 -        if (buffer[i] == NULL) {
   6.259 -            SNDMGR_CloseDevice(this);
   6.260 -            SDL_OutOfMemory();
   6.261 -            return 0;
   6.262 -        }
   6.263 -        SDL_memset(buffer[i], 0, spec->size);
   6.264 -    }
   6.265 -
   6.266 -    /* Create the sound manager channel */
   6.267 -    channel = (SndChannelPtr) SDL_malloc(sizeof(*channel));
   6.268 -    if (channel == NULL) {
   6.269 -        SNDMGR_CloseDevice(this);
   6.270 -        SDL_OutOfMemory();
   6.271 -        return 0;
   6.272 -    }
   6.273 -    this->hidden->channel = channel;
   6.274 -    if (spec->channels >= 2) {
   6.275 -        initOptions = initStereo;
   6.276 -    } else {
   6.277 -        initOptions = initMono;
   6.278 -    }
   6.279 -    channel->userInfo = (long) this;
   6.280 -    channel->qLength = 128;
   6.281 -    if (SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr) {
   6.282 -        SNDMGR_CloseDevice(this);
   6.283 -        SDL_SetError("Unable to create audio channel");
   6.284 -        return 0;
   6.285 -    }
   6.286 -
   6.287 -    /* start playback */
   6.288 -    {
   6.289 -        SndCommand cmd;
   6.290 -        cmd.cmd = callBackCmd;
   6.291 -        cmd.param2 = 0;
   6.292 -        running = 1;
   6.293 -        SndDoCommand(channel, &cmd, 0);
   6.294 -    }
   6.295 -
   6.296 -    return 1;
   6.297 -}
   6.298 -
   6.299 -static int
   6.300 -SNDMGR_Init(SDL_AudioDriverImpl * impl)
   6.301 -{
   6.302 -    /* Set the function pointers */
   6.303 -    impl->OpenDevice = SNDMGR_OpenDevice;
   6.304 -    impl->CloseDevice = SNDMGR_CloseDevice;
   6.305 -    impl->ProvidesOwnCallbackThread = 1;
   6.306 -    impl->OnlyHasDefaultOutputDevice = 1;
   6.307 -
   6.308 -/* Mac OS X uses threaded audio, so normal thread code is okay */
   6.309 -#ifndef __MACOSX__
   6.310 -    impl->LockDevice = SNDMGR_LockDevice;
   6.311 -    impl->UnlockDevice = SNDMGR_UnlockDevice;
   6.312 -    impl->SkipMixerLock = 1;
   6.313 -#endif
   6.314 -
   6.315 -    return 1;
   6.316 -}
   6.317 -
   6.318 -AudioBootStrap SNDMGR_bootstrap = {
   6.319 -    "sndmgr", SDL_MACOS_NAME " SoundManager", SNDMGR_Init, 0
   6.320 -};
   6.321 -
   6.322 -/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/audio/macrom/SDL_romaudio.h	Sat Sep 05 07:33:54 2009 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,39 +0,0 @@
     7.4 -/*
     7.5 -    SDL - Simple DirectMedia Layer
     7.6 -    Copyright (C) 1997-2009 Sam Lantinga
     7.7 -
     7.8 -    This library is free software; you can redistribute it and/or
     7.9 -    modify it under the terms of the GNU Lesser General Public
    7.10 -    License as published by the Free Software Foundation; either
    7.11 -    version 2.1 of the License, or (at your option) any later version.
    7.12 -
    7.13 -    This library is distributed in the hope that it will be useful,
    7.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 -    Lesser General Public License for more details.
    7.17 -
    7.18 -    You should have received a copy of the GNU Lesser General Public
    7.19 -    License along with this library; if not, write to the Free Software
    7.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 -
    7.22 -    Sam Lantinga
    7.23 -    slouken@libsdl.org
    7.24 -*/
    7.25 -#include "SDL_config.h"
    7.26 -
    7.27 -#ifndef _SDL_romaudio_h
    7.28 -#define _SDL_romaudio_h
    7.29 -
    7.30 -#include "../SDL_sysaudio.h"
    7.31 -
    7.32 -/* Hidden "this" pointer for the audio functions */
    7.33 -#define _THIS	SDL_AudioDevice *this
    7.34 -
    7.35 -struct SDL_PrivateAudioData
    7.36 -{
    7.37 -    /* Sound manager audio channel */
    7.38 -    SndChannelPtr channel;
    7.39 -};
    7.40 -
    7.41 -#endif /* _SDL_romaudio_h */
    7.42 -/* vi: set ts=4 sw=4 expandtab: */