diff --git a/sc2/src/sc2code/libs/sound/mixsdl/Makeinfo b/sc2/src/sc2code/libs/sound/mixsdl/Makeinfo deleted file mode 100644 index a8e2b304a..000000000 --- a/sc2/src/sc2code/libs/sound/mixsdl/Makeinfo +++ /dev/null @@ -1 +0,0 @@ -uqm_CFILES="mixer.c sound_mixsdl.c" diff --git a/sc2/src/sc2code/libs/sound/mixsdl/mixer.c b/sc2/src/sc2code/libs/sound/mixsdl/mixer.c deleted file mode 100644 index f7645ae4f..000000000 --- a/sc2/src/sc2code/libs/sound/mixsdl/mixer.c +++ /dev/null @@ -1,2221 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Simple mixer for use with SDL_audio. - * some initialization code is borrowed - * from SDL_mixer - */ - -#include "starcon.h" -#include -#include "mixer.h" -#include "libs/misc.h" -#include "SDL.h" -#include "SDL_types.h" -#include "SDL_thread.h" -#include "SDL_byteorder.h" -#include "SDL_audio.h" -#include "SDL_version.h" -#include "mixerint.h" - -#define DEBUG - -/* stanard SDL_audio driver */ -static const -mixSDL_DriverInfo mixer_SDLdriver = -{ - mixSDL_DriverGetName, - mixSDL_DriverGetError, - mixSDL_DriverOpenAudio, - SDL_CloseAudio, - SDL_PauseAudio -}; -/* SDL_audio driver is the default */ -static mixSDL_Driver mixer_driver = &mixer_SDLdriver; -static mixSDL_DriverFlags mixer_driverflags = 0; - -static uint32 audio_opened = 0; -static SDL_AudioSpec mixer_spec; -static uint32 last_error = MIX_NO_ERROR; -static uint32 mixer_format; /* format in mixer enumeration */ -static uint32 mixer_chansize; -static uint32 mixer_sampsize; -static sint32 mixer_silence; -static uint32 mixer_freq; -static mixSDL_Quality mixer_quality; - -/* mixer interim work-buffer; size in one-channel samples */ -static uint32 mixer_datasize; -static sint32 *mixer_data = 0; - -/* when locking more than one mutex - * you must lock them in this order - */ -static RecursiveMutex src_mutex; -static RecursiveMutex buf_mutex; -static RecursiveMutex act_mutex; - -#define MAX_SOURCES 8 -mixSDL_Source *active_sources[MAX_SOURCES]; - - -/************************************************* - * Internals - */ - -static void -mixSDL_SetError (uint32 error) -{ - last_error = error; -} - -static const char* -mixSDL_DriverGetName () -{ - return "SDL_audio"; -} - -static const char* -mixSDL_DriverGetError (void) -{ - return SDL_GetError(); -} - -static int -mixSDL_DriverOpenAudio (void *desired, void *obtained) -{ - return SDL_OpenAudio ((SDL_AudioSpec *) desired, - (SDL_AudioSpec *) obtained); -} - -/************************************************* - * General interface - */ - -uint32 -mixSDL_GetError (void) -{ - uint32 error = last_error; - last_error = MIX_NO_ERROR; - return error; -} - -void -mixSDL_UseDriver (mixSDL_Driver driver, mixSDL_DriverFlags flags) -{ - if (!driver) - return; - - if (driver == (mixSDL_Driver)~0) - driver = &mixer_SDLdriver; /* default */ - - mixer_driver = driver; - mixer_driverflags = flags; -} - -/* Open the mixer with a certain desired audio format */ -bool -mixSDL_OpenAudio (uint32 frequency, uint32 format, uint32 samples_buf, - mixSDL_Quality quality) -{ - SDL_AudioSpec desired; - - /* If the mixer is already opened, increment open count */ - if (audio_opened) - { - ++audio_opened; - return true; - } - - last_error = MIX_NO_ERROR; - memset (active_sources, 0, sizeof(mixSDL_Source*) * MAX_SOURCES); - - desired.channels = MIX_FORMAT_CHANS (format); - if (MIX_FORMAT_BPC (format) == 1) - desired.format = AUDIO_U8; - else if (MIX_FORMAT_BPC (format) == 2) - desired.format = AUDIO_S16SYS; - else - { - mixSDL_SetError (MIX_INVALID_VALUE); - fprintf (stderr, "mixSDL_OpenAudio: invalid format\n"); - return false; - } - - fprintf (stderr, "MixSDL using driver '%s'\n", - mixer_driver->GetDriverName()); - - /* Set the desired format and frequency */ - desired.freq = frequency; - desired.samples = samples_buf; - if (mixer_driverflags & MIX_DRIVER_FAKE_PLAY) - desired.callback = mixSDL_mix_fake; - else if (quality == MIX_QUALITY_LOW) - desired.callback = mixSDL_mix_lowq; - else - desired.callback = mixSDL_mix_channels; - desired.userdata = NULL; - - /* Accept nearly any audio format */ - if (mixer_driver->OpenAudio (&desired, &mixer_spec) < 0) - { - mixSDL_SetError (MIX_SDL_FAILURE); - return false; - } - - if (mixer_spec.format == AUDIO_U8) - { - mixer_chansize = 1; - mixer_silence = 128; - } - else if (mixer_spec.format == AUDIO_S16SYS) - { - mixer_chansize = 2; - mixer_silence = 0; - } - else - mixer_chansize = 0; - - if (mixer_chansize == 0 || - mixer_spec.channels < 1 || mixer_spec.channels > 2) - { - mixSDL_SetError (MIX_SDL_FAILURE); - mixer_driver->CloseAudio (); - fprintf (stderr, "mixSDL_OpenAudio: unable to aquire " - "desired format\n"); - return false; - } - - mixer_format = MIX_FORMAT_MAKE ( - mixer_chansize, mixer_spec.channels); - mixer_sampsize = mixer_chansize * mixer_spec.channels; - mixer_freq = mixer_spec.freq; - mixer_quality = quality; - - /* 2x size the sound playback buffer should be enough for anything */ - mixer_datasize = samples_buf * mixer_spec.channels * 2; - mixer_data = (sint32 *) HMalloc (sizeof (uint32) * mixer_datasize); - - src_mutex = CreateRecursiveMutex("mixSDL_SourceMutex", SYNC_CLASS_AUDIO); - buf_mutex = CreateRecursiveMutex("mixSDL_BufferMutex", SYNC_CLASS_AUDIO); - act_mutex = CreateRecursiveMutex("mixSDL_ActiveMutex", SYNC_CLASS_AUDIO); - - audio_opened = 1; - mixer_driver->PauseAudio (0); - - return true; -} - -/* Close the mixer, halting all playing audio */ -void -mixSDL_CloseAudio (void) -{ - if (audio_opened) - { - if (audio_opened == 1) - { - SDL_CloseAudio(); - - if (mixer_data) - { - HFree (mixer_data); - mixer_data = 0; - } - - DestroyRecursiveMutex (src_mutex); - DestroyRecursiveMutex (buf_mutex); - DestroyRecursiveMutex (act_mutex); - } - --audio_opened; - } -} - -/* Return the actual mixer parameters */ -bool -mixSDL_QuerySpec (uint32 *frequency, uint32 *format, uint32 *channels) -{ - if (!audio_opened) - { -#ifdef DEBUG - fprintf (stderr, "mixSDL_QuerySpec() called when audio closed\n"); -#endif - return false; - } - - if (frequency) - *frequency = mixer_spec.freq; - if (format) - *format = mixer_spec.format; - if (channels) - *channels = mixer_spec.channels; - - return true; -} - - -/************************************************* - * Sources interface - */ - -/* generate n sources */ -void -mixSDL_GenSources (uint32 n, mixSDL_Object *psrcobj) -{ - if (n == 0) - return; /* do nothing per OpenAL */ - - if (!psrcobj) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GenSources() called with null ptr\n"); -#endif - return; - } - for (; n; n--, psrcobj++) - { - mixSDL_Source *src; - - src = (mixSDL_Source *) HMalloc (sizeof (mixSDL_Source)); - src->magic = mixSDL_srcMagic; - src->locked = false; - src->state = MIX_INITIAL; - src->looping = false; - src->gain = MIX_GAIN_ADJ; - src->cqueued = 0; - src->cprocessed = 0; - src->firstqueued = 0; - src->nextqueued = 0; - src->prevqueued = 0; - src->lastqueued = 0; - src->curbufofs = 0; - src->curbufdelta = 0; - - *psrcobj = (mixSDL_Object) src; - } -} - -/* delete n sources */ -void -mixSDL_DeleteSources (uint32 n, mixSDL_Object *psrcobj) -{ - uint32 i; - mixSDL_Object *pcurobj; - - if (n == 0) - return; /* do nothing per OpenAL */ - - if (!psrcobj) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_DeleteSources() called with null ptr\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - /* check to make sure we can delete all sources */ - for (i = n, pcurobj = psrcobj; i && pcurobj; i--, pcurobj++) - { - mixSDL_Source *src = (mixSDL_Source *) *pcurobj; - - if (!src) - continue; - - if (src->magic != mixSDL_srcMagic) - break; - } - - if (i) - { /* some source failed */ - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_DeleteSources(): not a source\n"); -#endif - } - else - { /* all sources checked out */ - for (; n; n--, psrcobj++) - { - mixSDL_Source *src = (mixSDL_Source *) *psrcobj; - - if (!src) - continue; - - /* stopping should not be necessary - * under ideal circumstances - */ - if (src->state != MIX_INITIAL) - mixSDL_SourceStop_internal (src); - - /* unqueueing should not be necessary - * under ideal circumstances - */ - mixSDL_SourceUnqueueAll (src); - HFree (src); - *psrcobj = 0; - } - } - - UnlockRecursiveMutex (src_mutex); -} - -/* check if really is a source */ -bool -mixSDL_IsSource (mixSDL_Object srcobj) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - bool ret; - - if (!src) - return false; - - LockRecursiveMutex (src_mutex); - ret = src->magic == mixSDL_srcMagic; - UnlockRecursiveMutex (src_mutex); - - return ret; -} - -/* set source integer property */ -void -mixSDL_Sourcei (mixSDL_Object srcobj, mixSDL_SourceProp pname, - mixSDL_IntVal value) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_Sourcei() called with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_Sourcei(): not a source\n"); -#endif - } - else - { - switch (pname) - { - case MIX_LOOPING: - src->looping = value; - break; - case MIX_BUFFER: - { - mixSDL_Buffer *buf = (mixSDL_Buffer *) value; - - if (src->cqueued > 0) - mixSDL_SourceUnqueueAll (src); - - if (buf && !mixSDL_CheckBufferState (buf, "mixSDL_Sourcei")) - break; - - src->firstqueued = buf; - src->nextqueued = src->firstqueued; - src->prevqueued = 0; - src->lastqueued = src->nextqueued; - if (src->lastqueued) - src->lastqueued->next = 0; - src->cqueued = 1; - } - break; - case MIX_SOURCE_STATE: - if (value == MIX_INITIAL) - { - mixSDL_SourceRewind_internal (src); - } - else - { - fprintf (stderr, "mixSDL_Sourcei(MIX_SOURCE_STATE): " - "unsupported state, call ignored\n"); - } - break; - default: - mixSDL_SetError (MIX_INVALID_ENUM); - fprintf (stderr, "mixSDL_Sourcei() called " - "with unsupported property %u\n", pname); - } - } - - UnlockRecursiveMutex (src_mutex); -} - -/* set source float property */ -void -mixSDL_Sourcef (mixSDL_Object srcobj, mixSDL_SourceProp pname, float value) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_Sourcef() called with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_Sourcef(): not a source\n"); -#endif - } - else - { - switch (pname) - { - case MIX_GAIN: - src->gain = value * MIX_GAIN_ADJ; - break; - default: - fprintf (stderr, "mixSDL_Sourcei() called " - "with unsupported property %u\n", pname); - } - } - - UnlockRecursiveMutex (src_mutex); -} - -/* set source float array property (CURRENTLY NOT IMPLEMENTED) */ -void mixSDL_Sourcefv (mixSDL_Object srcobj, mixSDL_SourceProp pname, float *value) -{ - (void)srcobj; - (void)pname; - (void)value; -} - - -/* get source integer property */ -void -mixSDL_GetSourcei (mixSDL_Object srcobj, mixSDL_SourceProp pname, - mixSDL_IntVal *value) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src || !value) - { - mixSDL_SetError (src ? MIX_INVALID_VALUE : MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetSourcei() called with null param\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetSourcei(): not a source\n"); -#endif - } - else - { - switch (pname) - { - case MIX_LOOPING: - *value = src->looping; - break; - case MIX_BUFFER: - *value = (mixSDL_IntVal) src->firstqueued; - break; - case MIX_SOURCE_STATE: - *value = src->state; - break; - case MIX_BUFFERS_QUEUED: - *value = src->cqueued; - break; - case MIX_BUFFERS_PROCESSED: - *value = src->cprocessed; - break; - default: - mixSDL_SetError (MIX_INVALID_ENUM); - fprintf (stderr, "mixSDL_GetSourcei() called " - "with unsupported property %u\n", pname); - } - } - - UnlockRecursiveMutex (src_mutex); -} - -/* get source float property */ -void -mixSDL_GetSourcef (mixSDL_Object srcobj, mixSDL_SourceProp pname, - float *value) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src || !value) - { - mixSDL_SetError (src ? MIX_INVALID_VALUE : MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetSourcef() called with null param\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetSourcef(): not a source\n"); -#endif - } - else - { - switch (pname) - { - case MIX_GAIN: - *value = src->gain / MIX_GAIN_ADJ; - break; - default: - fprintf (stderr, "mixSDL_GetSourcef() called " - "with unsupported property %u\n", pname); - } - } - - UnlockRecursiveMutex (src_mutex); -} - -/* start the source; add it to active array */ -void -mixSDL_SourcePlay (mixSDL_Object srcobj) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourcePlay() called with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourcePlay(): not a source\n"); -#endif - } - else /* should make the source active */ - { - if (src->state < MIX_PLAYING) - { - if (src->firstqueued && !src->nextqueued) - mixSDL_SourceRewind_internal (src); - mixSDL_SourceActivate (src); - } - src->state = MIX_PLAYING; - } - - UnlockRecursiveMutex (src_mutex); -} - -/* stop the source; remove it from active array and requeue buffers */ -void -mixSDL_SourceRewind (mixSDL_Object srcobj) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceRewind() called with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourcePlay(): not a source\n"); -#endif - } - else - { - mixSDL_SourceRewind_internal (src); - } - - UnlockRecursiveMutex (src_mutex); -} - -/* pause the source; keep in active array */ -void -mixSDL_SourcePause (mixSDL_Object srcobj) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourcePause() called with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourcePause(): not a source\n"); -#endif - } - else /* should keep all buffers and offsets */ - { - if (src->state < MIX_PLAYING) - mixSDL_SourceActivate (src); - src->state = MIX_PAUSED; - } - - UnlockRecursiveMutex (src_mutex); -} - -/* stop the source; remove it from active array - * and unqueue 'queued' buffers - */ -void -mixSDL_SourceStop (mixSDL_Object srcobj) -{ - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceStop() called with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceStop(): not a source\n"); -#endif - } - else /* should remove queued buffers */ - { - if (src->state >= MIX_PLAYING) - mixSDL_SourceDeactivate (src); - mixSDL_SourceStop_internal (src); - src->state = MIX_STOPPED; - } - - UnlockRecursiveMutex (src_mutex); -} - -/* queue buffers on the source */ -void -mixSDL_SourceQueueBuffers (mixSDL_Object srcobj, uint32 n, - mixSDL_Object* pbufobj) -{ - uint32 i; - mixSDL_Object* pobj; - mixSDL_Source *src = (mixSDL_Source *) srcobj; - - if (!src || !pbufobj) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceQueueBuffers() called " - "with null param\n"); -#endif - return; - } - - LockRecursiveMutex (buf_mutex); - /* check to make sure we can safely queue all buffers */ - for (i = n, pobj = pbufobj; i; i--, pobj++) - { - mixSDL_Buffer *buf = (mixSDL_Buffer *) *pobj; - if (!buf || !mixSDL_CheckBufferState (buf, - "mixSDL_SourceQueueBuffers")) - { - break; - } - } - UnlockRecursiveMutex (buf_mutex); - - if (i == 0) - { /* all buffers checked out */ - LockRecursiveMutex (src_mutex); - LockRecursiveMutex (buf_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceQueueBuffers(): not a source\n"); -#endif - } - else - { - for (i = n, pobj = pbufobj; i; i--, pobj++) - { - mixSDL_Buffer *buf = (mixSDL_Buffer *) *pobj; - - /* add buffer to the chain */ - if (src->lastqueued) - src->lastqueued->next = buf; - src->lastqueued = buf; - - if (!src->firstqueued) - { - src->firstqueued = buf; - src->nextqueued = buf; - src->prevqueued = 0; - } - src->cqueued++; - buf->state = MIX_BUF_QUEUED; - } - } - - UnlockRecursiveMutex (buf_mutex); - UnlockRecursiveMutex (src_mutex); - } -} - -/* unqueue buffers from the source */ -void -mixSDL_SourceUnqueueBuffers (mixSDL_Object srcobj, uint32 n, - mixSDL_Object* pbufobj) -{ - uint32 i; - mixSDL_Source *src = (mixSDL_Source *) srcobj; - mixSDL_Buffer *curbuf = 0; - - if (!src || !pbufobj) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceUnqueueBuffers() called " - "with null source\n"); -#endif - return; - } - - LockRecursiveMutex (src_mutex); - - if (src->magic != mixSDL_srcMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceUnqueueBuffers(): not a source\n"); -#endif - } - else if (n > src->cqueued) - { - mixSDL_SetError (MIX_INVALID_OPERATION); - } - else - { - LockRecursiveMutex (buf_mutex); - - /* check to make sure we can unqueue all buffers */ - for (i = n, curbuf = src->firstqueued; - i && curbuf && curbuf->state != MIX_BUF_PLAYING; - i--, curbuf = curbuf->next) - ; - - if (i) - { - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceUnqueueBuffers(): " - "active buffer attempted\n"); -#endif - } - else - { /* all buffers checked out */ - for (i = n; i; i--, pbufobj++) - { - mixSDL_Buffer *buf = src->firstqueued; - - /* remove buffer from the chain */ - if (src->nextqueued == buf) - src->nextqueued = buf->next; - if (src->prevqueued == buf) - src->prevqueued = 0; - if (src->lastqueued == buf) - src->lastqueued = 0; - src->firstqueued = buf->next; - src->cqueued--; - - if (buf->state == MIX_BUF_PROCESSED) - src->cprocessed--; - - buf->state = MIX_BUF_FILLED; - buf->next = 0; - *pbufobj = (mixSDL_Object) buf; - } - } - - UnlockRecursiveMutex (buf_mutex); - } - - UnlockRecursiveMutex (src_mutex); -} - -/************************************************* - * Sources internals - */ - -static void -mixSDL_SourceUnqueueAll (mixSDL_Source *src) -{ - mixSDL_Buffer *buf; - mixSDL_Buffer *nextbuf; - - if (!src) - { -#ifdef DEBUG - fprintf (stderr, "mixSDL_SourceUnqueueAll() called " - "with null source\n"); -#endif - return; - } - - LockRecursiveMutex (buf_mutex); - - for (buf = src->firstqueued; buf; buf = nextbuf) - { -#ifdef DEBUG - if (buf->state == MIX_BUF_PLAYING) - { - fprintf (stderr, "mixSDL_SourceUnqueueAll(): " - "attempted on active buffer\n"); - } -#endif - nextbuf = buf->next; - buf->state = MIX_BUF_FILLED; - buf->next = 0; - } - - UnlockRecursiveMutex (buf_mutex); - - src->firstqueued = 0; - src->nextqueued = 0; - src->prevqueued = 0; - src->lastqueued = 0; - src->cqueued = 0; - src->cprocessed = 0; - src->curbufofs = 0; - src->curbufdelta = 0; -} - -/* add the source to the active array */ -static void -mixSDL_SourceActivate (mixSDL_Source* src) -{ - uint32 i; - - LockRecursiveMutex (act_mutex); - -#ifdef DEBUG - /* check active sources, see if this source is there already */ - for (i = 0; i < MAX_SOURCES && active_sources[i] != src; i++) - ; - if (i < MAX_SOURCES) - { /* source found */ - fprintf (stderr, "mixSDL_SourceActivate(): " - "source already active in slot %u\n", i); - UnlockRecursiveMutex (act_mutex); - return; - } -#endif - - /* find an empty slot */ - for (i = 0; i < MAX_SOURCES && active_sources[i] != 0; i++) - ; - if (i < MAX_SOURCES) - { /* slot found */ - active_sources[i] = src; - } -#ifdef DEBUG - else - { - fprintf (stderr, "mixSDL_SourceActivate(): " - "no more slots available (max=%d)\n", MAX_SOURCES); - } -#endif - - UnlockRecursiveMutex (act_mutex); -} - -/* remove the source from the active array */ -static void -mixSDL_SourceDeactivate (mixSDL_Source* src) -{ - uint32 i; - - LockRecursiveMutex (act_mutex); - - /* check active sources, see if this source is there */ - for (i = 0; i < MAX_SOURCES && active_sources[i] != src; i++) - ; - if (i < MAX_SOURCES) - { /* source found */ - active_sources[i] = 0; - } -#ifdef DEBUG - else - { /* source not found */ - fprintf (stderr, "mixSDL_SourceDeactivate(): source not active\n"); - } -#endif - - UnlockRecursiveMutex (act_mutex); -} - -static void -mixSDL_SourceStop_internal (mixSDL_Source *src) -{ - mixSDL_Buffer *buf; - mixSDL_Buffer *nextbuf; - - if (!src->firstqueued) - return; - -#ifdef DEBUG - /* assert the source buffers state */ - if (!src->lastqueued) - { - fprintf (stderr, "mixSDL_SourceStop_internal(): " - "desynced source state\n"); - return; - } -#endif - - LockRecursiveMutex (buf_mutex); - - /* find last 'processed' buffer */ - for (buf = src->firstqueued; - buf && buf->next && buf->next != src->nextqueued; - buf = buf->next) - ; - src->lastqueued = buf; - if (buf) - buf->next = 0; /* break the chain */ - - /* unqueue all 'queued' buffers */ - for (buf = src->nextqueued; buf; buf = nextbuf) - { - nextbuf = buf->next; - buf->state = MIX_BUF_FILLED; - buf->next = 0; - src->cqueued--; - } - - if (src->cqueued == 0) - { /* all buffers were removed */ - src->firstqueued = 0; - src->lastqueued = 0; - } - src->nextqueued = 0; - src->prevqueued = 0; - src->curbufofs = 0; - src->curbufdelta = 0; - - UnlockRecursiveMutex (buf_mutex); -} - -static void -mixSDL_SourceRewind_internal (mixSDL_Source *src) -{ - /* should change the processed buffers to queued */ - mixSDL_Buffer *buf; - - if (src->state >= MIX_PLAYING) - mixSDL_SourceDeactivate (src); - - LockRecursiveMutex (buf_mutex); - - for (buf = src->firstqueued; - buf && buf->state != MIX_BUF_QUEUED; - buf = buf->next) - { - buf->state = MIX_BUF_QUEUED; - } - - UnlockRecursiveMutex (buf_mutex); - - src->curbufofs = 0; - src->curbufdelta = 0; - src->cprocessed = 0; - src->nextqueued = src->firstqueued; - src->prevqueued = 0; - src->state = MIX_INITIAL; -} - -/* get the sample next in queue in internal format */ -static __inline__ bool -mixSDL_SourceGetNextSample (mixSDL_Source *src, sint32* psamp, bool left) -{ - /* fake the data if requested */ - if (mixer_driverflags & MIX_DRIVER_FAKE_DATA) - return mixSDL_SourceGetFakeSample (src, psamp, left); - - while (src->nextqueued) - { - mixSDL_Buffer *buf = src->nextqueued; - uint8* data; - double samp; - - if (!buf->data || buf->size < mixer_sampsize) - { - /* buffer invalid, go next */ - buf->state = MIX_BUF_PROCESSED; - src->curbufofs = 0; - src->nextqueued = src->nextqueued->next; - src->cprocessed++; - continue; - } - - if (mixer_freq == buf->orgfreq) - { - data = buf->data + (uint32)src->curbufofs; - samp = mixSDL_GetSampleInt (data, mixer_chansize); - src->curbufofs += mixer_chansize; - } - else if (mixer_freq > buf->orgfreq) - { - if (mixer_quality == MIX_QUALITY_DEFAULT) - samp = mixSDL_GetResampledInt_linear (src, left); - else if (mixer_quality == MIX_QUALITY_HIGH) - samp = mixSDL_GetResampledInt_cubic (src, left); - else - samp = mixSDL_GetResampledInt_nearest (src, left); - } - else - { - /* because currently linear and cubic resamplers do not work - for downsampling */ - samp = mixSDL_GetResampledInt_nearest (src, left); - } - - samp *= src->gain; - - if (mixer_chansize == 2) - { - /* check S16 clipping */ - if (samp > MIX_S16_MAX) - *psamp = SINT16_MAX; - else if (samp < MIX_S16_MIN) - *psamp = SINT16_MIN; - else - *psamp = (sint32)samp; - } - else - { - /* check S8 clipping */ - if (samp > MIX_S8_MAX) - *psamp = SINT8_MAX; - else if (samp < MIX_S8_MIN) - *psamp = SINT8_MIN; - else - *psamp = (sint32)samp; - } - - if (src->curbufofs >= buf->size) - { - /* buffer exhausted, go next */ - buf->state = MIX_BUF_PROCESSED; - src->curbufofs = 0; - src->prevqueued = src->nextqueued; - src->nextqueued = src->nextqueued->next; - src->cprocessed++; - } - else - { - buf->state = MIX_BUF_PLAYING; - } - - return true; - } - - /* no more playable buffers */ - if (src->state >= MIX_PLAYING) - mixSDL_SourceDeactivate (src); - - src->state = MIX_STOPPED; - - return false; -} - -/* fake the next sample, but process buffers and states */ -static __inline__ bool -mixSDL_SourceGetFakeSample (mixSDL_Source *src, sint32* psamp, bool left) -{ - while (src->nextqueued) - { - mixSDL_Buffer *buf = src->nextqueued; - - if (mixer_freq == buf->orgfreq) - { - src->curbufofs += mixer_chansize; - } - else - { - double offset, intoffset; - if (MIX_FORMAT_CHANS (mixer_format) == 2) - { - if (!left) - { - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - } - else - { - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - } - - *psamp = 0; - - if (src->curbufofs >= buf->size) - { - /* buffer exhausted, go next */ - buf->state = MIX_BUF_PROCESSED; - src->curbufofs = 0; - src->curbufdelta = 0; - src->prevqueued = src->nextqueued; - src->nextqueued = src->nextqueued->next; - src->cprocessed++; - } - else - { - buf->state = MIX_BUF_PLAYING; - } - - return true; - } - - /* no more playable buffers */ - if (src->state >= MIX_PLAYING) - mixSDL_SourceDeactivate (src); - - src->state = MIX_STOPPED; - - return false; -} - -/************************************************* - * Buffers interface - */ - -/* generate n buffer objects */ -void -mixSDL_GenBuffers (uint32 n, mixSDL_Object *pbufobj) -{ - if (n == 0) - return; /* do nothing per OpenAL */ - - if (!pbufobj) - { - mixSDL_SetError (MIX_INVALID_VALUE); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GenBuffers() called with null ptr\n"); -#endif - return; - } - for (; n; n--, pbufobj++) - { - mixSDL_Buffer *buf; - - buf = (mixSDL_Buffer *) HMalloc (sizeof (mixSDL_Buffer)); - buf->magic = mixSDL_bufMagic; - buf->locked = false; - buf->state = MIX_BUF_INITIAL; - buf->data = 0; - buf->size = 0; - buf->next = 0; - buf->orgdata = 0; - buf->orgfreq = 0; - buf->orgsize = 0; - buf->orgchannels = 0; - buf->orgchansize = 0; - - *pbufobj = (mixSDL_Object) buf; - } -} - -/* delete n buffer objects */ -void -mixSDL_DeleteBuffers (uint32 n, mixSDL_Object *pbufobj) -{ - uint32 i; - mixSDL_Object *pcurobj; - - if (n == 0) - return; /* do nothing per OpenAL */ - - if (!pbufobj) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_DeleteBuffers() called with null ptr\n"); -#endif - return; - } - - LockRecursiveMutex (buf_mutex); - - /* check to make sure we can delete all buffers */ - for (i = n, pcurobj = pbufobj; i && pcurobj; i--, pcurobj++) - { - mixSDL_Buffer *buf = (mixSDL_Buffer *) *pcurobj; - - if (!buf) - continue; - - if (buf->magic != mixSDL_bufMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_DeleteBuffers(): not a buffer\n"); -#endif - break; - } - else if (buf->locked) - { - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "mixSDL_DeleteBuffers(): locked buffer\n"); -#endif - break; - } - else if (buf->state >= MIX_BUF_QUEUED) - { - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "mixSDL_DeleteBuffers(): " - "attempted on queued/active buffer\n"); -#endif - break; - } - } - - if (i == 0) - { - /* all buffers check out */ - for (; n; n--, pbufobj++) - { - mixSDL_Buffer *buf = (mixSDL_Buffer *) *pbufobj; - - if (!buf) - continue; - - if (buf->data) - HFree (buf->data); - HFree (buf); - - *pbufobj = 0; - } - } - UnlockRecursiveMutex (buf_mutex); -} - -/* check if really a buffer object */ -bool -mixSDL_IsBuffer (mixSDL_Object bufobj) -{ - mixSDL_Buffer *buf = (mixSDL_Buffer *) bufobj; - bool ret; - - if (!buf) - return false; - - LockRecursiveMutex (buf_mutex); - ret = buf->magic == mixSDL_bufMagic; - UnlockRecursiveMutex (buf_mutex); - - return ret; -} - -/* get buffer property */ -void -mixSDL_GetBufferi (mixSDL_Object bufobj, mixSDL_BufferProp pname, - mixSDL_IntVal *value) -{ - mixSDL_Buffer *buf = (mixSDL_Buffer *) bufobj; - - if (!buf || !value) - { - mixSDL_SetError (buf ? MIX_INVALID_VALUE : MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetBufferi() called with null param\n"); -#endif - return; - } - - LockRecursiveMutex (buf_mutex); - - if (buf->locked) - { - UnlockRecursiveMutex (buf_mutex); - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetBufferi() called with locked buffer\n"); -#endif - return; - } - - if (buf->magic != mixSDL_bufMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_GetBufferi(): not a buffer\n"); -#endif - } - else - { - /* Return original buffer values - */ - switch (pname) - { - case MIX_FREQUENCY: - *value = buf->orgfreq; - break; - case MIX_BITS: - *value = buf->orgchansize << 3; - break; - case MIX_CHANNELS: - *value = buf->orgchannels; - break; - case MIX_SIZE: - *value = buf->orgsize; - break; - case MIX_DATA: - *value = (mixSDL_IntVal) buf->orgdata; - break; - default: - mixSDL_SetError (MIX_INVALID_ENUM); - fprintf (stderr, "mixSDL_GetBufferi() called " - "with invalid property %u\n", pname); - } - } - - UnlockRecursiveMutex (buf_mutex); -} - -/* fill buffer with external data */ -void -mixSDL_BufferData (mixSDL_Object bufobj, uint32 format, void* data, - uint32 size, uint32 freq) -{ - mixSDL_Buffer *buf = (mixSDL_Buffer *) bufobj; - mixSDL_Convertion conv; - uint32 dstsize; - - if (!buf || !data || !size) - { - mixSDL_SetError (buf ? MIX_INVALID_VALUE : MIX_INVALID_NAME); -#ifdef DEBUG -// fprintf (stderr, "mixSDL_BufferData() called with bad param\n"); -#endif - return; - } - - LockRecursiveMutex (buf_mutex); - - if (buf->locked) - { - UnlockRecursiveMutex (buf_mutex); - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "mixSDL_BufferData() called " - "with locked buffer\n"); -#endif - return; - } - - if (buf->magic != mixSDL_bufMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "mixSDL_BufferData(): not a buffer\n"); -#endif - } - else if (buf->state > MIX_BUF_FILLED) - { - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "mixSDL_BufferData() attempted " - "on in-use buffer\n"); -#endif - } - else - { - if (buf->data) - HFree (buf->data); - buf->data = 0; - buf->size = 0; - /* Store original buffer values for OpenAL compatibility */ - buf->orgdata = data; - buf->orgfreq = freq; - buf->orgsize = size; - buf->orgchannels = MIX_FORMAT_CHANS (format); - buf->orgchansize = MIX_FORMAT_BPC (format); - - conv.srcsamples = conv.dstsamples = - size / MIX_FORMAT_SAMPSIZE (format); - - if (conv.dstsamples > - UINT32_MAX / MIX_FORMAT_SAMPSIZE (format)) - { - mixSDL_SetError (MIX_INVALID_VALUE); - } - else - { - dstsize = conv.dstsamples * - MIX_FORMAT_SAMPSIZE (mixer_format); - - buf->size = dstsize; - /* only copy/convert the data if not faking */ - if (! (mixer_driverflags & MIX_DRIVER_FAKE_DATA)) - { - buf->data = HMalloc (dstsize); - - if (format == mixer_format) - { - /* format identical to internal */ - buf->locked = true; - UnlockRecursiveMutex (buf_mutex); - - memcpy (buf->data, data, size); - if (MIX_FORMAT_SAMPSIZE (mixer_format) == 1) - { - /* convert buffer to S8 format internally */ - uint8* dst; - for (dst = buf->data; dstsize; dstsize--, dst++) - *dst ^= 0x80; - } - - LockRecursiveMutex (buf_mutex); - buf->locked = false; - } - else - { - /* needs convertion */ - conv.srcfmt = format; - conv.srcdata = data; - conv.srcsize = size; - conv.dstfmt = mixer_format; - conv.dstdata = buf->data; - conv.dstsize = dstsize; - - buf->locked = true; - UnlockRecursiveMutex (buf_mutex); - - mixSDL_ConvertBuffer_internal (&conv); - - LockRecursiveMutex (buf_mutex); - buf->locked = false; - } - } - - buf->state = MIX_BUF_FILLED; - } - } - - UnlockRecursiveMutex (buf_mutex); -} - - -/************************************************* - * Buffer internals - */ - -static __inline__ bool -mixSDL_CheckBufferState (mixSDL_Buffer *buf, const char* FuncName) -{ - if (!buf) - return false; - - if (buf->magic != mixSDL_bufMagic) - { - mixSDL_SetError (MIX_INVALID_NAME); -#ifdef DEBUG - fprintf (stderr, "%s(): not a buffer\n", FuncName); -#endif - return false; - } - - if (buf->locked) - { - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "%s(): locked buffer attempted\n", FuncName); -#endif - return false; - } - - if (buf->state != MIX_BUF_FILLED) - { - mixSDL_SetError (MIX_INVALID_OPERATION); -#ifdef DEBUG - fprintf (stderr, "%s: invalid buffer attempted\n", FuncName); -#endif - return false; - } - return true; -} - -static void -mixSDL_ConvertBuffer_internal (mixSDL_Convertion *conv) -{ - conv->srcbpc = MIX_FORMAT_BPC (conv->srcfmt); - conv->srcchans = MIX_FORMAT_CHANS (conv->srcfmt); - conv->dstbpc = MIX_FORMAT_BPC (conv->dstfmt); - conv->dstchans = MIX_FORMAT_CHANS (conv->dstfmt); - - conv->flags = 0; - if (conv->srcbpc > conv->dstbpc) - conv->flags |= mixConvSizeDown; - else if (conv->srcbpc < conv->dstbpc) - conv->flags |= mixConvSizeUp; - if (conv->srcchans > conv->dstchans) - conv->flags |= mixConvStereoDown; - else if (conv->srcchans < conv->dstchans) - conv->flags |= mixConvStereoUp; - - mixSDL_ResampleFlat (conv); -} - -/************************************************* - * Resampling routines - */ - -/* get a sample from external buffer - * in internal format - */ -static __inline__ sint32 -mixSDL_GetSampleExt (void *src, uint32 bpc) -{ - if (bpc == 2) - return *(sint16 *)src; - else - return (*(uint8 *)src) - 128; -} - -/* get a sample from internal buffer */ -static __inline__ sint32 -mixSDL_GetSampleInt (void *src, uint32 bpc) -{ - if (bpc == 2) - return *(sint16 *)src; - else - return *(sint8 *)src; -} - -/* put a sample into an external buffer - * from internal format - */ -static __inline__ void -mixSDL_PutSampleExt (void *dst, uint32 bpc, sint32 samp) -{ - if (bpc == 2) - *(sint16 *)dst = samp; - else - *(uint8 *)dst = samp ^ 0x80; -} - -/* put a sample into an internal buffer - * in internal format - */ -static __inline__ void -mixSDL_PutSampleInt (void *dst, uint32 bpc, sint32 samp) -{ - if (bpc == 2) - *(sint16 *)dst = samp; - else - *(sint8 *)dst = samp; -} - -/* get a resampled sample from internal buffer (nearest neighbor) */ -static __inline__ sint32 -mixSDL_GetResampledInt_nearest (mixSDL_Source *src, bool left) -{ - uint8 *d0 = src->nextqueued->data + src->curbufofs; - double offset, intoffset; - - if (MIX_FORMAT_CHANS (mixer_format) == 2) - { - if (!left) - { - d0 += mixer_chansize; - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - } - else - { - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - - return mixSDL_GetSampleInt (d0, mixer_chansize); -} - -/* get a resampled sample from internal buffer (linear interpolation) */ -static __inline__ sint32 -mixSDL_GetResampledInt_linear (mixSDL_Source *src, bool left) -{ - // TODO: support for downsampling - - mixSDL_Buffer *curr = src->nextqueued; - mixSDL_Buffer *next = src->nextqueued->next; - uint8 *d0, *d1; - sint32 s0, s1, samp; - double offset, intoffset, delta; - - delta = src->curbufdelta; - d0 = curr->data + src->curbufofs; - - if (MIX_FORMAT_CHANS (mixer_format) == 2) - { - if (!left) - { - d0 += mixer_chansize; - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - } - else - { - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - - if (d0 + mixer_sampsize >= curr->data + curr->size) - { - if (next && next->data && next->size >= mixer_sampsize) - { - d1 = next->data; - if (!left) - d1 += mixer_chansize; - } - else - d1 = d0; - } - else - d1 = d0 + mixer_sampsize; - - s0 = mixSDL_GetSampleInt (d0, mixer_chansize); - s1 = mixSDL_GetSampleInt (d1, mixer_chansize); - samp = s0 + (sint32)(delta * (s1 - s0)); - - return samp; -} - -/* get a resampled sample from internal buffer (cubic interpolation) */ -static __inline__ sint32 -mixSDL_GetResampledInt_cubic (mixSDL_Source *src, bool left) -{ - // TODO: support for downsampling - - mixSDL_Buffer *prev = src->prevqueued; - mixSDL_Buffer *curr = src->nextqueued; - mixSDL_Buffer *next = src->nextqueued->next; - uint8 *d0, *d1, *d2, *d3; /* prev, curr, next, next + 1 */ - sint32 samp; - double offset, intoffset; - float delta, delta2, a, b, c, s0, s1, s2, s3; - - delta = (float)src->curbufdelta; - delta2 = delta * delta; - d1 = curr->data + src->curbufofs; - - if (MIX_FORMAT_CHANS (mixer_format) == 2) - { - if (!left) - { - d1 += mixer_chansize; - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - } - else - { - offset = src->curbufdelta + - (double)src->nextqueued->orgfreq / mixer_freq; - src->curbufdelta = modf (offset, &intoffset); - src->curbufofs += (uint32)intoffset * mixer_sampsize; - } - - if (d1 - mixer_sampsize < curr->data) - { - if (prev && prev->data && prev->size >= mixer_sampsize) - { - d0 = prev->data + prev->size - mixer_sampsize; - if (!left) - d0 += mixer_chansize; - } - else - d0 = d1; - } - else - d0 = d1 - mixer_sampsize; - - if (d1 + mixer_sampsize >= curr->data + curr->size) - { - if (next && next->data && next->size >= mixer_sampsize * 2) - { - d2 = next->data; - if (!left) - d2 += mixer_chansize; - d3 = d2 + mixer_sampsize; - } - else - d2 = d3 = d1; - } - else - { - d2 = d1 + mixer_sampsize; - if (d2 + mixer_sampsize >= curr->data + curr->size) - { - if (next && next->data && next->size >= mixer_sampsize) - { - d3 = next->data; - if (!left) - d3 += mixer_chansize; - } - else - d3 = d2; - } - else - d3 = d2 + mixer_sampsize; - } - - s0 = (float)mixSDL_GetSampleInt (d0, mixer_chansize); - s1 = (float)mixSDL_GetSampleInt (d1, mixer_chansize); - s2 = (float)mixSDL_GetSampleInt (d2, mixer_chansize); - s3 = (float)mixSDL_GetSampleInt (d3, mixer_chansize); - - a = (3.0f * (s1 - s2) - s0 + s3) * 0.5f; - b = 2.0f * s2 + s0 - ((5.0f * s1 + s3) * 0.5f); - c = (s2 - s0) * 0.5f; - - samp = (sint32)(a * delta2 * delta + b * delta2 + c * delta + s1); - return samp; -} - -/* get next sample from external buffer - * in internal format, while performing - * convertion if necessary - */ -static __inline__ sint32 -mixSDL_GetConvSample (uint8 **psrc, uint32 bpc, uint32 flags) -{ - sint32 samp; - - samp = mixSDL_GetSampleExt (*psrc, bpc); - *psrc += bpc; - if (flags & mixConvStereoDown) - { - /* downmix to mono - average up channels */ - samp = (samp + mixSDL_GetSampleExt (*psrc, bpc)) / 2; - *psrc += bpc; - } - - if (flags & mixConvSizeUp) - { - /* convert S8 to S16 */ - samp <<= 8; - } - else if (flags & mixConvSizeDown) - { - /* convert S16 to S8 - * if arithmetic shift is available to the compiler - * it will use it to optimize this - */ - samp /= 0x100; - } - - return samp; -} - -/* put next sample into an internal buffer - * in internal format, while performing - * convertion if necessary - */ -static __inline__ void -mixSDL_PutConvSample (uint8 **pdst, uint32 bpc, uint32 flags, sint32 samp) -{ - mixSDL_PutSampleInt (*pdst, bpc, samp); - *pdst += bpc; - if (flags & mixConvStereoUp) - { - mixSDL_PutSampleInt (*pdst, bpc, samp); - *pdst += bpc; - } -} - -/* resampling with respect to sample size only */ -static void -mixSDL_ResampleFlat (mixSDL_Convertion *conv) -{ - mixSDL_ConvFlags flags = conv->flags; - uint8 *src = conv->srcdata; - uint8 *dst = conv->dstdata; - uint32 srcbpc = conv->srcbpc; - uint32 dstbpc = conv->dstbpc; - uint32 samples; - - samples = conv->srcsamples; - if ( !(conv->flags & (mixConvStereoUp | mixConvStereoDown))) - samples *= conv->srcchans; - - for (; samples; samples--) - { - sint32 samp; - - samp = mixSDL_GetConvSample (&src, srcbpc, flags); - mixSDL_PutConvSample (&dst, dstbpc, flags, samp); - } -} - - -/********************************************************** - * THE mixer - higher quality; smoothed-out clipping - * - * This could use some optimization perhaps - */ - -static void -mixSDL_mix_channels (void *userdata, uint8 *stream, sint32 len) -{ - uint32 samples = len / mixer_chansize; - sint32 *end_data = mixer_data + samples; - sint32 *data; - uint32 step; - bool left = true; - uint32 chans = MIX_FORMAT_CHANS (mixer_format); - - /* mixer_datasize < samples should not happen ever, but for now.. */ - if (mixer_datasize < samples) - { -#ifdef DEBUG - fprintf (stderr, "mixSDL_mix_channels(): " - "WARNING: work-buffer too small\n"); -#endif - mixSDL_mix_lowq (userdata, stream, len); - } - - /* keep this order or die */ - LockRecursiveMutex (src_mutex); - LockRecursiveMutex (buf_mutex); - LockRecursiveMutex (act_mutex); - - /* first, collect data from sources and put into work-buffer */ - for (data = mixer_data; data < end_data; ++data) - { - uint32 i; - sint32 fullsamp; - - fullsamp = 0; - - for (i = 0; i < MAX_SOURCES; i++) - { - mixSDL_Source *src; - sint32 samp; - - /* find next source */ - for (; i < MAX_SOURCES && ( - (src = active_sources[i]) == 0 - || src->state != MIX_PLAYING - || !mixSDL_SourceGetNextSample (src, &samp, left)); - i++) - ; - - if (i < MAX_SOURCES) - { - /* sample aquired */ - fullsamp += samp; - } - } - - *data = fullsamp; - if (chans == 2) - left = !left; - } - - /* unclip work-buffer */ - step = mixer_spec.channels; - mixSDL_UnclipWorkBuffer (mixer_data, end_data, step); - if (step == 2) - { /* also, for the second channel */ - mixSDL_UnclipWorkBuffer (mixer_data + 1, end_data, step); - } - - /* copy data into driver buffer */ - for (data = mixer_data; data < end_data; ++data) - { - mixSDL_PutSampleExt (stream, mixer_chansize, *data); - stream += mixer_chansize; - } - - /* keep this order or die */ - UnlockRecursiveMutex (act_mutex); - UnlockRecursiveMutex (buf_mutex); - UnlockRecursiveMutex (src_mutex); - - (void) userdata; // satisfying compiler - unused arg -} - -/* data unclipping - smooth out the areas that need to be clipped */ -static void -mixSDL_UnclipWorkBuffer (sint32 *data, sint32 *end_data, uint32 step) -{ - while (data < end_data) - { - uint32 len; - sint32 extremum; - sint32 *chunk; - sint32 threshold, origin, range_end; - double gain_mult; - sint32 samp = *data; - - if (mixer_chansize == 2) - { /* S16 */ - if (samp < MIX_UNCLIP_S16_MIN) - { - origin = MIX_UNCLIP_S16_MIN; - range_end = -SINT16_MIN; - threshold = -MIX_UNCLIP_S16_MIN; - } - else if (samp > MIX_UNCLIP_S16_MAX) - { - origin = MIX_UNCLIP_S16_MAX; - range_end = SINT16_MAX; - threshold = MIX_UNCLIP_S16_MAX; - } - else - { - data += step; - continue; - } - } - else - { /* S8 */ - if (samp < MIX_UNCLIP_S8_MIN) - { - origin = MIX_UNCLIP_S8_MIN; - range_end = -SINT8_MIN; - threshold = -MIX_UNCLIP_S8_MIN; - } - else if (samp > MIX_UNCLIP_S8_MAX) - { - origin = MIX_UNCLIP_S8_MAX; - range_end = SINT8_MAX; - threshold = MIX_UNCLIP_S8_MAX; - } - else - { - data += step; - continue; - } - } - - chunk = data; - - /* seek to next sample not in clipping area */ - extremum = 0; - for (len = 0; data < end_data; data += step, ++len) - { - samp = *data; - if (samp < 0) - samp = -samp; - if (samp > extremum) - extremum = samp; - if (samp <= threshold) - break; - } - - if (extremum < range_end) - continue; /* nothing to do really */ - - gain_mult = (double) (range_end - threshold) - / (double) (extremum - threshold); - - /* apply unclipping filter - clipping smooth-out */ - for (data = chunk; len; data += step, --len) - { - *data = origin + (sint32) (gain_mult * (*data - origin)); - } - } -} - -/* low quality faster version */ -static void -mixSDL_mix_lowq (void *userdata, uint8 *stream, sint32 len) -{ - uint8 *end_stream = stream + len; - bool left = true; - uint32 chans = MIX_FORMAT_CHANS (mixer_format); - - /* keep this order or die */ - LockRecursiveMutex (src_mutex); - LockRecursiveMutex (buf_mutex); - LockRecursiveMutex (act_mutex); - - for (; stream < end_stream; stream += mixer_chansize) - { - uint32 i; - sint32 fullsamp; - - fullsamp = 0; - - for (i = 0; i < MAX_SOURCES; i++) - { - mixSDL_Source *src; - sint32 samp; - - /* find next source */ - for (; i < MAX_SOURCES && ( - (src = active_sources[i]) == 0 - || src->state != MIX_PLAYING - || !mixSDL_SourceGetNextSample (src, &samp, left)); - i++) - ; - - if (i < MAX_SOURCES) - { - /* sample aquired */ - fullsamp += samp; - } - } - - /* clip the sample */ - if (mixer_chansize == 2) - { - /* check S16 clipping */ - if (fullsamp > SINT16_MAX) - fullsamp = SINT16_MAX; - else if (fullsamp < SINT16_MIN) - fullsamp = SINT16_MIN; - } - else - { - /* check S8 clipping */ - if (fullsamp > SINT8_MAX) - fullsamp = SINT8_MAX; - else if (fullsamp < SINT8_MIN) - fullsamp = SINT8_MIN; - } - - mixSDL_PutSampleExt (stream, mixer_chansize, fullsamp); - if (chans == 2) - left = !left; - } - - /* keep this order or die */ - UnlockRecursiveMutex (act_mutex); - UnlockRecursiveMutex (buf_mutex); - UnlockRecursiveMutex (src_mutex); - - (void) userdata; // satisfying compiler - unused arg -} - -/* fake mixer -- only process buffer and source states */ -static void -mixSDL_mix_fake (void *userdata, uint8 *stream, sint32 len) -{ - uint8 *end_stream = stream + len; - bool left = true; - uint32 chans = MIX_FORMAT_CHANS (mixer_format); - - /* keep this order or die */ - LockRecursiveMutex (src_mutex); - LockRecursiveMutex (buf_mutex); - LockRecursiveMutex (act_mutex); - - for (; stream < end_stream; stream += mixer_chansize) - { - uint32 i; - - for (i = 0; i < MAX_SOURCES; i++) - { - mixSDL_Source *src; - sint32 samp; - - /* find next source */ - for (; i < MAX_SOURCES && ( - (src = active_sources[i]) == 0 - || src->state != MIX_PLAYING - || !mixSDL_SourceGetFakeSample (src, &samp, left)); - i++) - ; - } - if (chans == 2) - left = !left; - } - - /* keep this order or die */ - UnlockRecursiveMutex (act_mutex); - UnlockRecursiveMutex (buf_mutex); - UnlockRecursiveMutex (src_mutex); - - (void) userdata; // satisfying compiler - unused arg -} diff --git a/sc2/src/sc2code/libs/sound/mixsdl/mixer.h b/sc2/src/sc2code/libs/sound/mixsdl/mixer.h deleted file mode 100644 index 2ae5081e5..000000000 --- a/sc2/src/sc2code/libs/sound/mixsdl/mixer.h +++ /dev/null @@ -1,280 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Simple mixer for use with SDL_audio - */ - -#ifndef MIXER_H -#define MIXER_H - -#include "types.h" -#include "SDL_byteorder.h" - -/** - * The interface heavily influenced by OpenAL - * to the point where you should use OpenAL's - * documentation when programming the mixer. - * (some source properties are not supported) - * - * EXCEPTION: You may not queue the same buffer - * on more than one source - */ - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN -# define MIX_IS_BIG_ENDIAN true -# define MIX_WANT_BIG_ENDIAN true -#else -# define MIX_IS_BIG_ENDIAN false -# define MIX_WANT_BIG_ENDIAN false -#endif - -/** - * Mixer errors (see OpenAL errors) - */ -enum -{ - MIX_NO_ERROR = 0, - MIX_INVALID_NAME = 0xA001U, - MIX_INVALID_ENUM = 0xA002U, - MIX_INVALID_VALUE = 0xA003U, - MIX_INVALID_OPERATION = 0xA004U, - MIX_OUT_OF_MEMORY = 0xA005U, - - MIX_SDL_FAILURE = 0xA101U -}; - -/** - * Source properties (see OpenAL) - */ -typedef enum -{ - MIX_POSITION = 0x1004, - MIX_LOOPING = 0x1007, - MIX_BUFFER = 0x1009, - MIX_GAIN = 0x100A, - MIX_SOURCE_STATE = 0x1010, - - MIX_BUFFERS_QUEUED = 0x1015, - MIX_BUFFERS_PROCESSED = 0x1016 - -} mixSDL_SourceProp; - -/** - * Source state information - */ -typedef enum -{ - MIX_INITIAL = 0, - MIX_STOPPED, - MIX_PLAYING, - MIX_PAUSED, - -} mixSDL_SourceState; - -/** - * Sound buffer properties - */ -typedef enum -{ - MIX_FREQUENCY = 0x2001, - MIX_BITS = 0x2002, - MIX_CHANNELS = 0x2003, - MIX_SIZE = 0x2004, - MIX_DATA = 0x2005 - -} mixSDL_BufferProp; - -/** - * Buffer states: semi-private - */ -typedef enum -{ - MIX_BUF_INITIAL = 0, - MIX_BUF_FILLED, - MIX_BUF_QUEUED, - MIX_BUF_PLAYING, - MIX_BUF_PROCESSED - -} mixSDL_BufferState; - -/** Sound buffers: format specifier. - * bits 00..07: bytes per sample - * bits 08..15: channels - * bits 15..31: meaningless - */ -#define MIX_FORMAT_DUMMYID 0x00170000 -#define MIX_FORMAT_BPC(f) ((f) & 0xff) -#define MIX_FORMAT_CHANS(f) (((f) >> 8) & 0xff) -#define MIX_FORMAT_BPC_MAX 2 -#define MIX_FORMAT_CHANS_MAX 2 -#define MIX_FORMAT_MAKE(b, c) \ - ( MIX_FORMAT_DUMMYID | ((b) & 0xff) | (((c) & 0xff) << 8) ) - -#define MIX_FORMAT_SAMPSIZE(f) \ - ( MIX_FORMAT_BPC(f) * MIX_FORMAT_CHANS(f) ) - -typedef enum -{ - MIX_FORMAT_MONO8 = MIX_FORMAT_MAKE (1, 1), - MIX_FORMAT_STEREO8 = MIX_FORMAT_MAKE (1, 2), - MIX_FORMAT_MONO16 = MIX_FORMAT_MAKE (2, 1), - MIX_FORMAT_STEREO16 = MIX_FORMAT_MAKE (2, 2) - -} mixSDL_Format; - -typedef enum -{ - MIX_QUALITY_LOW = 0, - MIX_QUALITY_MEDIUM, - MIX_QUALITY_HIGH, - MIX_QUALITY_DEFAULT = MIX_QUALITY_MEDIUM, - MIX_QUALITY_COUNT - -} mixSDL_Quality; - -typedef enum -{ - MIX_DRIVER_NOFLAGS = 0, - MIX_DRIVER_FAKE_DATA = 1, - MIX_DRIVER_FAKE_PLAY = 2, - MIX_DRIVER_FAKE_ALL = MIX_DRIVER_FAKE_DATA | MIX_DRIVER_FAKE_PLAY - -} mixSDL_DriverFlags; - -/************************************************* - * Interface Types - */ - -typedef intptr_t mixSDL_Object; -typedef intptr_t mixSDL_IntVal; - -typedef struct _mixSDL_Buffer -{ - uint32 magic; - bool locked; - mixSDL_BufferState state; - uint8 *data; - uint32 size; - /* original buffer values for OpenAL compat */ - void* orgdata; - uint32 orgfreq; - uint32 orgsize; - uint32 orgchannels; - uint32 orgchansize; - /* next buffer in chain */ - struct _mixSDL_Buffer *next; - -} mixSDL_Buffer; - -#define mixSDL_bufMagic 0x4258494DU /* MIXB in LSB */ - -typedef struct -{ - uint32 magic; - bool locked; - mixSDL_SourceState state; - bool looping; - float gain; - uint32 cqueued; - uint32 cprocessed; - mixSDL_Buffer *firstqueued; /* first buf in the queue */ - mixSDL_Buffer *nextqueued; /* next to play, or 0 */ - mixSDL_Buffer *prevqueued; /* previously played */ - mixSDL_Buffer *lastqueued; /* last in queue */ - uint32 curbufofs; - double curbufdelta; - -} mixSDL_Source; - -#define mixSDL_srcMagic 0x5358494DU /* MIXS in LSB */ - -typedef struct -{ - const char* (* GetDriverName) (void); - const char* (* GetError) (void); - /* see SDL for description of these functions */ - int (* OpenAudio) (void *desired, void *obtained); - void (* CloseAudio) (void); - void (* PauseAudio) (int pause_on); - -} mixSDL_DriverInfo; -typedef const mixSDL_DriverInfo *mixSDL_Driver; - -/************************************************* - * General interface - */ -uint32 mixSDL_GetError (void); -void mixSDL_UseDriver (mixSDL_Driver driver, mixSDL_DriverFlags flags); - -bool mixSDL_OpenAudio (uint32 freq, uint32 format, uint32 samples_buf, - mixSDL_Quality quality); -void mixSDL_CloseAudio (void); -bool mixSDL_QuerySpec (uint32 *freq, uint32 *format, uint32 *channels); - -/************************************************* - * Sources - */ -void mixSDL_GenSources (uint32 n, mixSDL_Object *psrcobj); -void mixSDL_DeleteSources (uint32 n, mixSDL_Object *psrcobj); -bool mixSDL_IsSource (mixSDL_Object srcobj); -void mixSDL_Sourcei (mixSDL_Object srcobj, mixSDL_SourceProp pname, - mixSDL_IntVal value); -void mixSDL_Sourcef (mixSDL_Object srcobj, mixSDL_SourceProp pname, - float value); -void mixSDL_Sourcefv (mixSDL_Object srcobj, mixSDL_SourceProp pname, - float *value); -void mixSDL_GetSourcei (mixSDL_Object srcobj, mixSDL_SourceProp pname, - mixSDL_IntVal *value); -void mixSDL_GetSourcef (mixSDL_Object srcobj, mixSDL_SourceProp pname, - float *value); -void mixSDL_SourceRewind (mixSDL_Object srcobj); -void mixSDL_SourcePlay (mixSDL_Object srcobj); -void mixSDL_SourcePause (mixSDL_Object srcobj); -void mixSDL_SourceStop (mixSDL_Object srcobj); -void mixSDL_SourceQueueBuffers (mixSDL_Object srcobj, uint32 n, - mixSDL_Object* pbufobj); -void mixSDL_SourceUnqueueBuffers (mixSDL_Object srcobj, uint32 n, - mixSDL_Object* pbufobj); - -/************************************************* - * Buffers - */ -void mixSDL_GenBuffers (uint32 n, mixSDL_Object *pbufobj); -void mixSDL_DeleteBuffers (uint32 n, mixSDL_Object *pbufobj); -bool mixSDL_IsBuffer (mixSDL_Object bufobj); -void mixSDL_GetBufferi (mixSDL_Object bufobj, mixSDL_BufferProp pname, - mixSDL_IntVal *value); -void mixSDL_BufferData (mixSDL_Object bufobj, uint32 format, void* data, - uint32 size, uint32 freq); - - -/* Make sure the prop-value type is of suitable size - * it must be able to store both int and void* - * Adapted from SDL - * This will generate "negative subscript or subscript is too large" - * error during compile, if the actual size of a type is wrong - */ -#define MIX_COMPILE_TIME_ASSERT(name, x) \ - typedef int mixSDL_dummy_##name [(x) * 2 - 1] - -MIX_COMPILE_TIME_ASSERT (mixSDL_Object, - sizeof(mixSDL_Object) >= sizeof(void*)); -MIX_COMPILE_TIME_ASSERT (mixSDL_IntVal, - sizeof(mixSDL_IntVal) >= sizeof(mixSDL_Object)); - -#undef MIX_COMPILE_TIME_ASSERT - -#endif /* MIXER_H */ diff --git a/sc2/src/sc2code/libs/sound/mixsdl/mixerint.h b/sc2/src/sc2code/libs/sound/mixsdl/mixerint.h deleted file mode 100644 index e242c9e8f..000000000 --- a/sc2/src/sc2code/libs/sound/mixsdl/mixerint.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Simple mixer for use with SDL_audio - * Internals - */ - -#ifndef MIXERINT_H -#define MIXERINT_H - -#include "types.h" - -/************************************************* - * Internals - */ - -/* Conversion info types and funcs */ -typedef enum -{ - mixConvNone = 0, - mixConvStereoUp = 1, - mixConvStereoDown = 2, - mixConvSizeUp = 4, - mixConvSizeDown = 8 - -} mixSDL_ConvFlags; - -typedef struct -{ - uint32 srcfmt; - void *srcdata; - uint32 srcsize; - uint32 srcbpc; /* bytes/sample for 1 chan */ - uint32 srcchans; - uint32 srcsamples; - - uint32 dstfmt; - void *dstdata; - uint32 dstsize; - uint32 dstbpc; /* bytes/sample for 1 chan */ - uint32 dstchans; - uint32 dstsamples; - - mixSDL_ConvFlags flags; - -} mixSDL_Convertion; - -static void mixSDL_ConvertBuffer_internal (mixSDL_Convertion *conv); -static void mixSDL_ResampleFlat (mixSDL_Convertion *conv); - -static __inline__ sint32 mixSDL_GetSampleExt (void *src, uint32 bpc); -static __inline__ sint32 mixSDL_GetSampleInt (void *src, uint32 bpc); -static __inline__ void mixSDL_PutSampleInt (void *dst, uint32 bpc, - sint32 samp); -static __inline__ void mixSDL_PutSampleExt (void *dst, uint32 bpc, - sint32 samp); - -static __inline__ sint32 mixSDL_GetResampledInt_nearest (mixSDL_Source *src, bool left); -static __inline__ sint32 mixSDL_GetResampledInt_linear (mixSDL_Source *src, bool left); -static __inline__ sint32 mixSDL_GetResampledInt_cubic (mixSDL_Source *src, bool left); - -/* Source manipulation */ -static void mixSDL_SourceUnqueueAll (mixSDL_Source *src); -static void mixSDL_SourceStop_internal (mixSDL_Source *src); -static void mixSDL_SourceRewind_internal (mixSDL_Source *src); -static void mixSDL_SourceActivate (mixSDL_Source* src); -static void mixSDL_SourceDeactivate (mixSDL_Source* src); - -static __inline__ bool mixSDL_CheckBufferState (mixSDL_Buffer *buf, - const char* FuncName); - -/* Clipping boundaries */ -#define MIX_S16_MAX ((double) SINT16_MAX) -#define MIX_S16_MIN ((double) SINT16_MIN) -#define MIX_S8_MAX ((double) SINT8_MAX) -#define MIX_S8_MIN ((double) SINT8_MIN) - -/* Channel gain adjustment for clipping reduction */ -#define MIX_GAIN_ADJ (0.8f) - -/* Clipping filter boundaries */ -#define MIX_UNCLIP_AREA 30 /* percent */ -#define MIX_UNCLIP_S16_AREA ((sint32) SINT16_MAX * MIX_UNCLIP_AREA / 100) -#define MIX_UNCLIP_S16_MAX ((sint32) SINT16_MAX - MIX_UNCLIP_S16_AREA) -#define MIX_UNCLIP_S16_MIN ((sint32) SINT16_MIN + MIX_UNCLIP_S16_AREA) -#define MIX_UNCLIP_S8_AREA ((sint32) SINT8_MAX * MIX_UNCLIP_AREA / 100) -#define MIX_UNCLIP_S8_MAX ((sint32) SINT8_MAX - MIX_UNCLIP_S8_AREA) -#define MIX_UNCLIP_S8_MIN ((sint32) SINT8_MIN + MIX_UNCLIP_S8_AREA) - -/* The Mixer */ -static void mixSDL_mix_channels (void *userdata, uint8 *stream, - sint32 len); -static void mixSDL_mix_lowq (void *userdata, uint8 *stream, sint32 len); -static void mixSDL_mix_fake (void *userdata, uint8 *stream, sint32 len); -static void mixSDL_UnclipWorkBuffer (sint32 *data, sint32 *end_data, - uint32 step); -static __inline__ bool mixSDL_SourceGetNextSample (mixSDL_Source *src, - sint32* samp, bool left); -static __inline__ bool mixSDL_SourceGetFakeSample (mixSDL_Source *src, - sint32* psamp, bool left); - -/* SDL driver */ -static const char* mixSDL_DriverGetName (void); -static const char* mixSDL_DriverGetError (void); -static int mixSDL_DriverOpenAudio (void *desired, void *obtained); - -#endif /* MIXERINT_H */ diff --git a/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c b/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c deleted file mode 100644 index 3f0f505ac..000000000 --- a/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.c +++ /dev/null @@ -1,349 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -//#include "libs/graphics/sdl/sdl_common.h" -#include "SDL.h" -#include "libs/sound/sound.h" -#include "libs/tasklib.h" - -static Task StreamDecoderTask; - -/******************************************************************* - * NoSound driver for MixSDL - declarations - */ - -static const char* NoSound_GetDriverName (void); -static const char* NoSound_GetError (void); -static int NoSound_OpenAudio (void *desired, void *obtained); -static void NoSound_CloseAudio (void); -static void NoSound_PauseAudio (int pause_on); - -/* The nosound driver */ -static const -mixSDL_DriverInfo NoSound_driver = -{ - NoSound_GetDriverName, - NoSound_GetError, - NoSound_OpenAudio, - NoSound_CloseAudio, - NoSound_PauseAudio -}; -static SDL_AudioSpec NoSound_spec; -static Task NoSound_PlaybackTask; -static bool NoSound_Paused = true; -static const char* NoSound_ErrorStr = ""; - -/******************************************************************* - * Other stuff - */ -static int current_driver = 0; - -int TFB_NoSound_InitSound (int driver, int flags); - -/******************************************************************* - * Normal MixSDL sound - */ - -int -TFB_mixSDL_InitSound (int driver, int flags) -{ - int i; - char SoundcardName[256]; - uint32 audio_rate, audio_channels, audio_bufsize, audio_format; - mixSDL_Quality audio_quality; - TFB_DecoderFormats formats = - { - MIX_IS_BIG_ENDIAN, MIX_WANT_BIG_ENDIAN, - MIX_FORMAT_MONO8, MIX_FORMAT_STEREO8, - MIX_FORMAT_MONO16, MIX_FORMAT_STEREO16 - }; - - fprintf (stderr, "Initializing SDL audio subsystem.\n"); - if ((SDL_InitSubSystem(SDL_INIT_AUDIO)) == -1) - { - fprintf (stderr, "Couldn't initialize audio subsystem: %s\n", SDL_GetError()); - return -1; - } - fprintf (stderr, "SDL audio subsystem initialized.\n"); - - if (flags & TFB_SOUNDFLAGS_HQAUDIO) - { - audio_quality = MIX_QUALITY_HIGH; - audio_rate = 44100; - audio_bufsize = 4096; - } - else if (flags & TFB_SOUNDFLAGS_LQAUDIO) - { - audio_quality = MIX_QUALITY_LOW; - audio_rate = 22050; - audio_bufsize = 2048; - } - else - { - audio_quality = MIX_QUALITY_DEFAULT; - audio_rate = 44100; - audio_bufsize = 4096; - } - - fprintf (stderr, "Initializing MixSDL mixer.\n"); - if (!mixSDL_OpenAudio(audio_rate, MIX_FORMAT_STEREO16, - audio_bufsize, audio_quality)) - { - fprintf (stderr, "Unable to open audio: %x, %s\n", - mixSDL_GetError (), SDL_GetError ()); - SDL_QuitSubSystem (SDL_INIT_AUDIO); - return -1; - } - fprintf (stderr, "MixSDL Mixer initialized.\n"); - - atexit (TFB_UninitSound); - - SDL_AudioDriverName (SoundcardName, sizeof (SoundcardName)); - mixSDL_QuerySpec (&audio_rate, &audio_format, &audio_channels); - fprintf (stderr, " opened %s at %d Hz %d bit %s, %d samples audio buffer\n", - SoundcardName, audio_rate, audio_format & 0xFF, - audio_channels > 1 ? "stereo" : "mono", audio_bufsize); - - fprintf (stderr, "Initializing sound decoders.\n"); - SoundDecoder_Init (flags, &formats); - fprintf (stderr, "Sound decoders initialized.\n"); - - for (i = 0; i < NUM_SOUNDSOURCES; ++i) - { - mixSDL_GenSources (1, &soundSource[i].handle); - - soundSource[i].sample = NULL; - soundSource[i].stream_should_be_playing = FALSE; - soundSource[i].stream_mutex = CreateMutex ("MixSDL stream mutex", SYNC_CLASS_AUDIO); - soundSource[i].sbuffer = NULL; - soundSource[i].sbuf_start = 0; - soundSource[i].sbuf_size = 0; - soundSource[i].sbuf_offset = 0; - } - - SetSFXVolume (sfxVolumeScale); - SetSpeechVolume (speechVolumeScale); - SetMusicVolume ((COUNT)musicVolume); - - StreamDecoderTask = AssignTask (StreamDecoderTaskFunc, 1024, - "audio stream decoder"); - - current_driver = driver; - - return 0; -} - -void -TFB_mixSDL_UninitSound (void) -{ - int i; - - if (StreamDecoderTask) - { - ConcludeTask (StreamDecoderTask); - StreamDecoderTask = NULL; - } - - for (i = 0; i < NUM_SOUNDSOURCES; ++i) - { - if (soundSource[i].sample && soundSource[i].sample->decoder) - { - StopStream (i); - } - if (soundSource[i].sbuffer) - { - void *sbuffer = soundSource[i].sbuffer; - soundSource[i].sbuffer = NULL; - HFree (sbuffer); - } - DestroyMutex (soundSource[i].stream_mutex); - - mixSDL_DeleteSources (1, &soundSource[i].handle); - } - - SoundDecoder_Uninit (); - mixSDL_CloseAudio (); -} - -/******************************************************************* - * NoSound driver for MixSDL - */ - -int -TFB_NoSound_InitSound (int driver, int flags) -{ - int i; - uint32 audio_rate, audio_channels, audio_bufsize, audio_format; - TFB_DecoderFormats formats = - { - 0, 0, /* do not care about endianness */ - MIX_FORMAT_MONO8, MIX_FORMAT_STEREO8, - MIX_FORMAT_MONO16, MIX_FORMAT_STEREO16 - }; - - if (flags & TFB_SOUNDFLAGS_HQAUDIO) - { - audio_rate = 44100; - audio_bufsize = 4096; - } - else if (flags & TFB_SOUNDFLAGS_LQAUDIO) - { - audio_rate = 22050; - audio_bufsize = 2048; - } - else - { - audio_rate = 44100; - audio_bufsize = 4096; - } - - fprintf (stderr, "Initializing MixSDL mixer.\n"); - mixSDL_UseDriver (&NoSound_driver, MIX_DRIVER_FAKE_ALL); - if (!mixSDL_OpenAudio (audio_rate, MIX_FORMAT_STEREO16, - audio_bufsize, MIX_QUALITY_DEFAULT)) - { - fprintf (stderr, "Unable to open audio: %x, %s\n", - mixSDL_GetError (), SDL_GetError ()); - return -1; - } - fprintf (stderr, "MixSDL mixer initialized.\n"); - - atexit (TFB_UninitSound); - - mixSDL_QuerySpec (&audio_rate, &audio_format, &audio_channels); - fprintf (stderr, " opened 'fake' " - "at %d Hz %d bit %s, %d samples audio buffer\n", - audio_rate, audio_format & 0xFF, - audio_channels > 1 ? "stereo" : "mono", audio_bufsize); - - fprintf (stderr, "Initializing sound decoders.\n"); - SoundDecoder_Init (flags, &formats); - fprintf (stderr, "Sound decoders initialized.\n"); - - for (i = 0; i < NUM_SOUNDSOURCES; ++i) - { - mixSDL_GenSources (1, &soundSource[i].handle); - - soundSource[i].sample = NULL; - soundSource[i].stream_should_be_playing = FALSE; - soundSource[i].stream_mutex = CreateMutex ("MixSDL stream mutex", SYNC_CLASS_AUDIO); - soundSource[i].sbuffer = NULL; - soundSource[i].sbuf_start = 0; - soundSource[i].sbuf_size = 0; - soundSource[i].sbuf_offset = 0; - } - - SetSFXVolume (sfxVolumeScale); - SetSpeechVolume (speechVolumeScale); - SetMusicVolume ((COUNT)musicVolume); - - StreamDecoderTask = AssignTask (StreamDecoderTaskFunc, 1024, - "audio stream decoder"); - - current_driver = driver; - - return 0; -} - -void -TFB_NoSound_UninitSound (void) -{ - TFB_mixSDL_UninitSound (); -} - -int -NoSound_PlaybackTaskFunc (void *data) -{ - Task task = (Task)data; - uint8 *stream; - uint32 entryTime; - sint32 period, delay; - - stream = (uint8 *) HMalloc (NoSound_spec.size); - period = 1000 * NoSound_spec.samples / NoSound_spec.freq; - - while (!Task_ReadState (task, TASK_EXIT)) - { - entryTime = SDL_GetTicks (); - - if (!NoSound_Paused) - { - NoSound_spec.callback (NoSound_spec.userdata, - stream, NoSound_spec.size); - } - - delay = period - (SDL_GetTicks () - entryTime); - if (delay > 0) - SDL_Delay (delay); - } - - HFree (stream); - FinishTask (task); - return 0; -} - -static const char* -NoSound_GetDriverName () -{ - return "NoSound"; -} - -static const char* -NoSound_GetError () -{ - return NoSound_ErrorStr; -} - -static int -NoSound_OpenAudio (void *desired, void *obtained) -{ - /* we accept anything - copy the format verbatim */ - memcpy (&NoSound_spec, desired, sizeof (SDL_AudioSpec)); - /* calculate the requested PCM-buffer size and silence val */ - NoSound_spec.size = (NoSound_spec.format & 0x003f) / 8 - * NoSound_spec.channels * NoSound_spec.samples; - NoSound_spec.silence = ((NoSound_spec.format >> 8) & 0x80) ^ 0x80; - - memcpy (obtained, &NoSound_spec, sizeof (SDL_AudioSpec)); - - NoSound_PlaybackTask = AssignTask (NoSound_PlaybackTaskFunc, 1024, - "nosound audio playback"); - if (!NoSound_PlaybackTask) - { - NoSound_ErrorStr = "Could not start Playback Task"; - return -1; - } - - return 0; -} - -static void -NoSound_CloseAudio (void) -{ - if (NoSound_PlaybackTask) - { - ConcludeTask (NoSound_PlaybackTask); - NoSound_PlaybackTask = 0; - } -} - -static void -NoSound_PauseAudio (int pause_on) -{ - NoSound_Paused = pause_on; -} diff --git a/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.h b/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.h deleted file mode 100644 index 863649e22..000000000 --- a/sc2/src/sc2code/libs/sound/mixsdl/sound_mixsdl.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Mixer abstraction layer for MixSDL - */ -#include "mixer.h" - -/************************************************* - * Interface Types - */ -#define TFBSound_Object mixSDL_Object -#define TFBSound_IntVal mixSDL_IntVal - -/************************************************* - * General interface - */ -#define TFBSound_GetError mixSDL_GetError - -/************************************************* - * Sources - */ -#define TFBSound_GenSources mixSDL_GenSources -#define TFBSound_DeleteSources mixSDL_DeleteSources -#define TFBSound_IsSource mixSDL_IsSource -#define TFBSound_Sourcei mixSDL_Sourcei -#define TFBSound_Sourcef mixSDL_Sourcef -#define TFBSound_Sourcefv mixSDL_Sourcefv -#define TFBSound_GetSourcei mixSDL_GetSourcei -#define TFBSound_GetSourcef mixSDL_GetSourcef -#define TFBSound_SourceRewind mixSDL_SourceRewind -#define TFBSound_SourcePlay mixSDL_SourcePlay -#define TFBSound_SourcePause mixSDL_SourcePause -#define TFBSound_SourceStop mixSDL_SourceStop -#define TFBSound_SourceQueueBuffers mixSDL_SourceQueueBuffers -#define TFBSound_SourceUnqueueBuffers mixSDL_SourceUnqueueBuffers - -/************************************************* - * Buffers - */ -#define TFBSound_GenBuffers mixSDL_GenBuffers -#define TFBSound_DeleteBuffers mixSDL_DeleteBuffers -#define TFBSound_IsBuffer mixSDL_IsBuffer -#define TFBSound_GetBufferi mixSDL_GetBufferi -#define TFBSound_BufferData mixSDL_BufferData - -#define TFBSOUND_GAIN MIX_GAIN -#define TFBSOUND_BUFFER MIX_BUFFER -#define TFBSOUND_SOURCE_STATE MIX_SOURCE_STATE -#define TFBSOUND_PLAYING MIX_PLAYING -#define TFBSOUND_PAUSED MIX_PAUSED -#define TFBSOUND_STOPPED MIX_STOPPED -#define TFBSOUND_FORMAT_MONO16 MIX_FORMAT_MONO16 -#define TFBSOUND_FORMAT_STEREO16 MIX_FORMAT_STEREO16 -#define TFBSOUND_FORMAT_STEREO8 MIX_FORMAT_STEREO8 -#define TFBSOUND_LOOPING MIX_LOOPING -#define TFBSOUND_BUFFERS_PROCESSED MIX_BUFFERS_PROCESSED -#define TFBSOUND_BUFFERS_QUEUED MIX_BUFFERS_QUEUED -#define TFBSOUND_NO_ERROR MIX_NO_ERROR -#define TFBSOUND_SIZE MIX_SIZE -#define TFBSOUND_POSITION MIX_POSITION diff --git a/sc2/src/sc2code/libs/sound/openal/mixer.h b/sc2/src/sc2code/libs/sound/openal/mixer.h deleted file mode 100644 index 1ac25ec44..000000000 --- a/sc2/src/sc2code/libs/sound/openal/mixer.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Adaptation layer - */ - -#ifndef MIXER_H -#define MIXER_H - -#include "types.h" -#include "SDL_byteorder.h" - -/** - * This is just a simple endianness setup for the mixer - */ - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN -# define MIX_IS_BIG_ENDIAN true -# define MIX_WANT_BIG_ENDIAN false -#else -# define MIX_IS_BIG_ENDIAN false -# define MIX_WANT_BIG_ENDIAN false -#endif - -#endif /* MIXER_H */ diff --git a/sc2/src/sc2code/libs/sound/openal/sound_openal.c b/sc2/src/sc2code/libs/sound/openal/sound_openal.c deleted file mode 100644 index 2f6d7d74d..000000000 --- a/sc2/src/sc2code/libs/sound/openal/sound_openal.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_OPENAL - -#include "libs/sound/sound.h" -#include "options.h" - -ALCcontext *alcContext = NULL; -ALCdevice *alcDevice = NULL; -ALfloat listenerPos[] = {0.0f, 0.0f, 0.0f}; -ALfloat listenerVel[] = {0.0f, 0.0f, 0.0f}; -ALfloat listenerOri[] = {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}; -static Task StreamDecoderTask; - - -int -TFB_alInitSound (int driver, int flags) -{ - int i; - TFB_DecoderFormats formats = - { - MIX_IS_BIG_ENDIAN, MIX_WANT_BIG_ENDIAN, - AL_FORMAT_MONO8, AL_FORMAT_STEREO8, - AL_FORMAT_MONO16, AL_FORMAT_STEREO16 - }; - - fprintf (stderr, "Initializing OpenAL.\n"); -#ifdef WIN32 - alcDevice = alcOpenDevice ((ALubyte*)"DirectSound3D"); -#else - alcDevice = alcOpenDevice (NULL); -#endif - - if (!alcDevice) - { - fprintf (stderr,"Couldn't initialize OpenAL: %d\n", alcGetError (NULL)); - return -1; - } - - atexit (TFB_UninitSound); - - alcContext = alcCreateContext (alcDevice, NULL); - if (!alcContext) - { - fprintf (stderr, "Couldn't create OpenAL context: %d\n", alcGetError (alcDevice)); - } - - alcMakeContextCurrent (alcContext); - - fprintf (stderr, "OpenAL initialized.\n"); - fprintf (stderr, " version: %s\n", alGetString (AL_VERSION)); - fprintf (stderr, " vendor: %s\n", alGetString (AL_VENDOR)); - fprintf (stderr, " renderer: %s\n", alGetString (AL_RENDERER)); - fprintf (stderr, " device: %s\n", - alcGetString (alcDevice, ALC_DEFAULT_DEVICE_SPECIFIER)); - //fprintf (stderr, " extensions: %s\n", alGetString (AL_EXTENSIONS)); - - fprintf (stderr, "Initializing sound decoders.\n"); - SoundDecoder_Init (flags, &formats); - fprintf (stderr, "Sound decoders initialized.\n"); - - alListenerfv (AL_POSITION, listenerPos); - alListenerfv (AL_VELOCITY, listenerVel); - alListenerfv (AL_ORIENTATION, listenerOri); - - for (i = 0; i < NUM_SOUNDSOURCES; ++i) - { - float zero[3] = {0.0f, 0.0f, 0.0f}; - - alGenSources (1, &soundSource[i].handle); - alSourcei (soundSource[i].handle, AL_LOOPING, AL_FALSE); - alSourcefv (soundSource[i].handle, AL_POSITION, zero); - alSourcefv (soundSource[i].handle, AL_VELOCITY, zero); - alSourcefv (soundSource[i].handle, AL_DIRECTION, zero); - - soundSource[i].sample = NULL; - soundSource[i].stream_should_be_playing = FALSE; - soundSource[i].stream_mutex = CreateMutex ("OpenAL stream mutex", SYNC_CLASS_AUDIO); - soundSource[i].sbuffer = NULL; - soundSource[i].sbuf_start = 0; - soundSource[i].sbuf_size = 0; - soundSource[i].sbuf_offset = 0; - } - - SetSFXVolume (sfxVolumeScale); - SetSpeechVolume (speechVolumeScale); - SetMusicVolume ((COUNT) musicVolume); - - if (optStereoSFX) - alDistanceModel (AL_INVERSE_DISTANCE); - else - alDistanceModel (AL_NONE); - - StreamDecoderTask = AssignTask (StreamDecoderTaskFunc, 1024, - "audio stream decoder"); - - (void) driver; // eat compiler warning - - return 0; -} - -void -TFB_alUninitSound (void) -{ - int i; - - if (StreamDecoderTask) - { - ConcludeTask (StreamDecoderTask); - StreamDecoderTask = NULL; - } - - for (i = 0; i < NUM_SOUNDSOURCES; ++i) - { - if (soundSource[i].sample && soundSource[i].sample->decoder) - { - StopStream (i); - } - if (soundSource[i].sbuffer) - { - void *sbuffer = soundSource[i].sbuffer; - soundSource[i].sbuffer = NULL; - HFree (sbuffer); - } - DestroyMutex (soundSource[i].stream_mutex); - } - - alcMakeContextCurrent (NULL); - alcDestroyContext (alcContext); - alcContext = NULL; - alcCloseDevice (alcDevice); - alcDevice = NULL; - - SoundDecoder_Uninit (); -} - -#endif diff --git a/sc2/src/sc2code/libs/sound/play.h b/sc2/src/sc2code/libs/sound/play.h deleted file mode 100644 index 0308f524f..000000000 --- a/sc2/src/sc2code/libs/sound/play.h +++ /dev/null @@ -1,92 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _PLAY_H -#define _PLAY_H - -enum -{ - MOD_TRACK, - RED_BOOK_TRACK, - - NUM_TRACK_TYPES -}; - -typedef struct -{ - MUSIC_REF TrackRef; - PBYTE TrackPtr; -} TRACK_DESC; -extern TRACK_DESC volatile _TrackList[NUM_TRACK_TYPES]; - -#define MAX_CHANNELS 4 -#define MAX_TRACKS 16 -#define MAX_INSTRUMENTS 63 -#define MAX_BLOCKS 256 -#define MAX_TRACK_VOLUME 64 - -typedef unsigned short SAMPLE_RATE; - -typedef struct -{ - COUNT LoopBegin, LoopLength; - COUNT SampleLength; - BYTE volume, transposition; -} INSTRUMENT_DESC; - -typedef struct -{ - BYTE LineCommands[MAX_CHANNELS][3]; -} LINE_DESC; -typedef LINE_DESC *PLINE_DESC; -#define LINE_DESCPTR PLINE_DESC - -typedef struct -{ - BYTE NumTracks, LastLine; - LINE_DESC LineList[1]; -} BLOCK_DESC; -typedef BLOCK_DESC *PBLOCK_DESC; -#define BLOCK_DESCPTR PBLOCK_DESC - -#define PLAY_CONTINUOUS (1 << 0) - -typedef struct -{ - INSTRUMENT_DESC PresetList[MAX_INSTRUMENTS]; - BYTE NumPhysicalBlocks, NumLogicalBlocks; - BYTE LogToPhysBlockList[MAX_BLOCKS]; - BYTE Tempo, NumSteps; - BYTE Priority, Flags; - BYTE TrackVolumeList[MAX_TRACKS]; - BYTE MasterVolume; - BYTE NumInstruments; - - DWORD InstrumentList[MAX_INSTRUMENTS]; - DWORD BlockList[1]; -} SONG_DESC; -typedef SONG_DESC *PSONG_DESC; -#define SONG_DESCPTR PSONG_DESC - -extern void _download_effects (SOUND_REF SoundRef); -extern BOOLEAN _download_instruments (MUSIC_REF MusicRef); - -#include "redbook.h" - -#endif /* _PLAY_H */ - diff --git a/sc2/src/sc2code/libs/sound/redbook.h b/sc2/src/sc2code/libs/sound/redbook.h deleted file mode 100644 index 760e86e99..000000000 --- a/sc2/src/sc2code/libs/sound/redbook.h +++ /dev/null @@ -1,29 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _REDBOOK_H -#define _REDBOOK_H - -extern BOOLEAN _is_red_book (PBYTE TrackInfo); -extern BOOLEAN _play_red_book (PBYTE TrackInfo, BOOLEAN Loop); -extern void _stop_red_book (void); -extern BOOLEAN _red_book_playing (void); -extern void _pause_red_book (void); -extern void _resume_red_book (void); - -#endif /* _REDBOOK_H */ diff --git a/sc2/src/sc2code/libs/sound/sound_chooser.c b/sc2/src/sc2code/libs/sound/sound_chooser.c deleted file mode 100644 index 2d15094c5..000000000 --- a/sc2/src/sc2code/libs/sound/sound_chooser.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Mixer abstraction layer - */ - -#ifdef HAVE_OPENAL - -#include "libs/sound/sound_common.h" -#include "libs/sound/sound_chooser.h" -#include - -static unsigned int tfb_enum_lookup[TFBSOUND_ENUMSIZE]; -unsigned int TFBSOUND_NO_ERROR; -int TFBSOUND_PAUSED; -int TFBSOUND_PLAYING; -int TFBSOUND_STOPPED; -unsigned int TFBSOUND_FORMAT_MONO16; -unsigned int TFBSOUND_FORMAT_STEREO16; -unsigned int TFBSOUND_FORMAT_STEREO8; -unsigned int TFBSOUND_FORMAT_MONO8; - -int TFB_mixSDL_InitSound (int driver, int flags); -int TFB_NoSound_InitSound (int driver, int flags); -#ifdef HAVE_OPENAL -int TFB_alInitSound (int driver, int flags); -#endif - - -/************************************************* - * General interface - */ -uint32 -TFBSound_GetError (void) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - return (alGetError ()); - else - return (mixSDL_GetError ()); -} - -/************************************************* - * Sources - */ - -void -TFBSound_GenSources (uint32 n, TFBSound_Object *psrcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alGenSources (n, (ALuint *)psrcobj); - else - mixSDL_GenSources (n, (mixSDL_Object *)psrcobj); -} - -void TFBSound_DeleteSources (uint32 n, TFBSound_Object *psrcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alDeleteSources (n, (ALuint *)psrcobj); - else - mixSDL_DeleteSources (n, (mixSDL_Object *)psrcobj); -} - -bool -TFBSound_IsSource (TFBSound_Object srcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - return (alIsSource ((ALuint)srcobj)); - else - return (mixSDL_IsSource ((mixSDL_Object)srcobj)); -} - -void -TFBSound_Sourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, - TFBSound_IntVal value) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourcei ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], (ALint) value); - else - mixSDL_Sourcei ((mixSDL_Object) srcobj, - (mixSDL_SourceProp) tfb_enum_lookup[pname], (mixSDL_IntVal) value); -} - -void -TFBSound_Sourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, float value) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourcef ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], value); - else - mixSDL_Sourcef ((mixSDL_Object) srcobj, - (mixSDL_SourceProp) tfb_enum_lookup[pname], value); -} - -void -TFBSound_Sourcefv (TFBSound_Object srcobj, TFBSound_SourceProp pname, float *value) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourcefv ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], value); - else - mixSDL_Sourcefv ((mixSDL_Object) srcobj, - (mixSDL_SourceProp) tfb_enum_lookup[pname], value); -} - -void -TFBSound_GetSourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, - TFBSound_IntVal *value) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alGetSourcei ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], (ALint *)value); - else - mixSDL_GetSourcei ((mixSDL_Object) srcobj, - (mixSDL_SourceProp) tfb_enum_lookup[pname], (mixSDL_IntVal *)value); -} - -void -TFBSound_GetSourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, - float *value) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alGetSourcef ((ALuint) srcobj, (ALenum) tfb_enum_lookup[pname], value); - else - mixSDL_GetSourcef ((mixSDL_Object) srcobj, - (mixSDL_SourceProp) tfb_enum_lookup[pname], value); -} - -void -TFBSound_SourceRewind (TFBSound_Object srcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourceRewind ((ALuint) srcobj); - else - mixSDL_SourceRewind ((mixSDL_Object) srcobj); -} - -void -TFBSound_SourcePlay (TFBSound_Object srcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourcePlay ((ALuint) srcobj); - else - mixSDL_SourcePlay ((mixSDL_Object) srcobj); -} - -void -TFBSound_SourcePause (TFBSound_Object srcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourcePause ((ALuint) srcobj); - else - mixSDL_SourcePause ((mixSDL_Object) srcobj); -} - -void -TFBSound_SourceStop (TFBSound_Object srcobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourceStop ((ALuint) srcobj); - else - mixSDL_SourceStop ((mixSDL_Object) srcobj); -} - -void -TFBSound_SourceQueueBuffers (TFBSound_Object srcobj, uint32 n, - TFBSound_Object* pbufobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourceQueueBuffers ((ALuint) srcobj, n,(ALuint *) pbufobj); - else - mixSDL_SourceQueueBuffers ((mixSDL_Object) srcobj, n, - (mixSDL_Object*) pbufobj); -} - -void -TFBSound_SourceUnqueueBuffers (TFBSound_Object srcobj, uint32 n, - TFBSound_Object* pbufobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alSourceUnqueueBuffers ((ALuint) srcobj, n, (ALuint *) pbufobj); - else - mixSDL_SourceUnqueueBuffers ((mixSDL_Object) srcobj, n, - (mixSDL_Object*) pbufobj); -} - -/************************************************* - * Buffers - */ -void -TFBSound_GenBuffers (uint32 n, TFBSound_Object *pbufobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alGenBuffers (n, (ALuint *)pbufobj); - else - mixSDL_GenBuffers (n, (mixSDL_Object *)pbufobj); -} - -void -TFBSound_DeleteBuffers (uint32 n, TFBSound_Object *pbufobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alDeleteBuffers (n, (ALuint *)pbufobj); - else - mixSDL_DeleteBuffers (n, (mixSDL_Object *)pbufobj); -} - -bool -TFBSound_IsBuffer (TFBSound_Object bufobj) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - return (alIsBuffer ((ALuint) bufobj)); - else - return (mixSDL_IsBuffer ((mixSDL_Object) bufobj)); -} - -void -TFBSound_GetBufferi (TFBSound_Object bufobj, TFBSound_BufferProp pname, - TFBSound_IntVal *value) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alGetBufferi ((ALuint) bufobj, (ALenum) tfb_enum_lookup[pname], (ALint *)value); - else - mixSDL_GetBufferi ((mixSDL_Object) bufobj, - (mixSDL_BufferProp) tfb_enum_lookup[pname], (mixSDL_IntVal *)value); -} - -void -TFBSound_BufferData (TFBSound_Object bufobj, uint32 format, void* data, - uint32 size, uint32 freq) -{ - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - alBufferData ((ALuint) bufobj, (ALenum) format, data, size, freq); - else - mixSDL_BufferData ((mixSDL_Object) bufobj, format, data, size, freq); -} - -int -TFB_choose_InitSound (int driver, int flags) -{ - SoundDriver = driver; - - if (driver == TFB_SOUNDDRIVER_OPENAL) - { - tfb_enum_lookup[TFBSOUND_GAIN] = AL_GAIN; - tfb_enum_lookup[TFBSOUND_BUFFER] = AL_BUFFER; - tfb_enum_lookup[TFBSOUND_SOURCE_STATE] = AL_SOURCE_STATE; - tfb_enum_lookup[TFBSOUND_LOOPING] = AL_LOOPING; - tfb_enum_lookup[TFBSOUND_BUFFERS_PROCESSED] = AL_BUFFERS_PROCESSED; - tfb_enum_lookup[TFBSOUND_BUFFERS_QUEUED] = AL_BUFFERS_QUEUED; - tfb_enum_lookup[TFBSOUND_SIZE] = AL_SIZE; - tfb_enum_lookup[TFBSOUND_POSITION] = AL_POSITION; - TFBSOUND_NO_ERROR = AL_NO_ERROR; - TFBSOUND_PAUSED = AL_PAUSED; - TFBSOUND_PLAYING = AL_PLAYING; - TFBSOUND_STOPPED = AL_STOPPED; - TFBSOUND_FORMAT_MONO16 = AL_FORMAT_MONO16; - TFBSOUND_FORMAT_STEREO16 = AL_FORMAT_STEREO16; - TFBSOUND_FORMAT_MONO8 = AL_FORMAT_MONO8; - TFBSOUND_FORMAT_STEREO8 = AL_FORMAT_STEREO8; - return (TFB_alInitSound (driver, flags)); - } - else - { - /* NoSound uses MixSDL, common values */ - tfb_enum_lookup[TFBSOUND_GAIN] = MIX_GAIN; - tfb_enum_lookup[TFBSOUND_BUFFER] = MIX_BUFFER; - tfb_enum_lookup[TFBSOUND_SOURCE_STATE] = MIX_SOURCE_STATE; - tfb_enum_lookup[TFBSOUND_LOOPING] = MIX_LOOPING; - tfb_enum_lookup[TFBSOUND_BUFFERS_PROCESSED] = MIX_BUFFERS_PROCESSED; - tfb_enum_lookup[TFBSOUND_BUFFERS_QUEUED] = MIX_BUFFERS_QUEUED; - tfb_enum_lookup[TFBSOUND_SIZE] = MIX_SIZE; - tfb_enum_lookup[TFBSOUND_POSITION] = MIX_POSITION; - TFBSOUND_NO_ERROR = MIX_NO_ERROR; - TFBSOUND_PAUSED = MIX_PAUSED; - TFBSOUND_PLAYING = MIX_PLAYING; - TFBSOUND_STOPPED = MIX_STOPPED; - TFBSOUND_FORMAT_MONO16 = MIX_FORMAT_MONO16; - TFBSOUND_FORMAT_STEREO16 = MIX_FORMAT_STEREO16; - TFBSOUND_FORMAT_MONO8 = MIX_FORMAT_MONO8; - TFBSOUND_FORMAT_STEREO8 = MIX_FORMAT_STEREO8; - - if (driver == TFB_SOUNDDRIVER_MIXSDL) - return (TFB_mixSDL_InitSound (driver, flags)); - else - return (TFB_NoSound_InitSound (driver, flags)); - } -} - -#endif diff --git a/sc2/src/sc2code/libs/sound/sound_chooser.h b/sc2/src/sc2code/libs/sound/sound_chooser.h deleted file mode 100644 index 8376cd145..000000000 --- a/sc2/src/sc2code/libs/sound/sound_chooser.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Mixer abstraction layer - */ - -#ifndef SOUNDCHOOSER_H -# define SOUNDCHOOSER_H -# ifdef WIN32 -# include -# include -# ifdef _MSC_VER -# pragma comment (lib, "OpenAL32.lib") -# endif -#else -# include -# include -#endif - -#include "mixsdl/mixer.h" -#include "openal/mixer.h" -#include "types.h" - - - /************************************************* - * Interface Types - */ - -typedef intptr_t TFBSound_Object; -typedef intptr_t TFBSound_IntVal; -typedef const int TFBSound_SourceProp; -typedef const int TFBSound_BufferProp; - -/************************************************* - * General interface - */ -uint32 TFBSound_GetError (void); - -/************************************************* - * Sources - */ -void TFBSound_GenSources (uint32 n, TFBSound_Object *psrcobj); -void TFBSound_DeleteSources (uint32 n, TFBSound_Object *psrcobj); -bool TFBSound_IsSource (TFBSound_Object srcobj); -void TFBSound_Sourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, - TFBSound_IntVal value); -void TFBSound_Sourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, - float value); -void TFBSound_Sourcefv (TFBSound_Object srcobj, TFBSound_SourceProp pname, - float *value); -void TFBSound_GetSourcei (TFBSound_Object srcobj, TFBSound_SourceProp pname, - TFBSound_IntVal *value); -void TFBSound_GetSourcef (TFBSound_Object srcobj, TFBSound_SourceProp pname, - float *value); -void TFBSound_SourceRewind (TFBSound_Object srcobj); -void TFBSound_SourcePlay (TFBSound_Object srcobj); -void TFBSound_SourcePause (TFBSound_Object srcobj); -void TFBSound_SourceStop (TFBSound_Object srcobj); -void TFBSound_SourceQueueBuffers (TFBSound_Object srcobj, uint32 n, - TFBSound_Object* pbufobj); -void TFBSound_SourceUnqueueBuffers (TFBSound_Object srcobj, uint32 n, - TFBSound_Object* pbufobj); - -/************************************************* - * Buffers - */ -void TFBSound_GenBuffers (uint32 n, TFBSound_Object *pbufobj); -void TFBSound_DeleteBuffers (uint32 n, TFBSound_Object *pbufobj); -bool TFBSound_IsBuffer (TFBSound_Object bufobj); -void TFBSound_GetBufferi (TFBSound_Object bufobj, TFBSound_BufferProp pname, - TFBSound_IntVal *value); -void TFBSound_BufferData (TFBSound_Object bufobj, uint32 format, void* data, - uint32 size, uint32 freq); - -#define TFBSound_BufferData_Linux alBufferWriteData_LOKI -enum -{ - - TFBSOUND_GAIN = 0, - TFBSOUND_BUFFER, - TFBSOUND_SOURCE_STATE, - TFBSOUND_LOOPING, - TFBSOUND_BUFFERS_PROCESSED, - TFBSOUND_BUFFERS_QUEUED, - TFBSOUND_SIZE, - TFBSOUND_POSITION, - TFBSOUND_ENUMSIZE -}; - -extern int TFBSOUND_PAUSED; -extern int TFBSOUND_PLAYING; -extern int TFBSOUND_STOPPED; -extern unsigned int TFBSOUND_NO_ERROR; -extern unsigned int TFBSOUND_FORMAT_MONO16; -extern unsigned int TFBSOUND_FORMAT_STEREO16; -extern unsigned int TFBSOUND_FORMAT_MONO8; -extern unsigned int TFBSOUND_FORMAT_STEREO8; - -#endif /* SOUNDCHOOSER_H */ diff --git a/sc2/src/sc2code/libs/sound/sound_common.c b/sc2/src/sc2code/libs/sound/sound_common.c deleted file mode 100644 index 0bb54962e..000000000 --- a/sc2/src/sc2code/libs/sound/sound_common.c +++ /dev/null @@ -1,161 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "libs/graphics/gfx_common.h" -#include "libs/sound/sound_common.h" -#include "libs/sound/sound.h" -#include "libs/tasklib.h" - -int SoundDriver = TFB_SOUNDDRIVER_MIXSDL; - -int musicVolume = (MAX_VOLUME >> 1); -float musicVolumeScale = 1.0f; -float sfxVolumeScale = 1.0f; -float speechVolumeScale = 1.0f; - -static Task FadeTask; -static SIZE TTotal; -static SIZE volume_end; - - -int TFB_mixSDL_InitSound (int driver, int flags); -int TFB_NoSound_InitSound (int driver, int flags); -#ifdef HAVE_OPENAL -int TFB_choose_InitSound (int driver, int flags); -int TFB_alInitSound (int driver, int flags); -#endif - -void TFB_mixSDL_UninitSound (void); -void TFB_NoSound_UninitSound (void); -#ifdef HAVE_OPENAL -void TFB_alUninitSound (void); -#endif - - -static int -fade_task (void *data) -{ - SIZE TDelta, volume_beg; - DWORD StartTime, CurTime; - Task task = (Task) data; - - volume_beg = musicVolume; - StartTime = CurTime = GetTimeCounter (); - do - { - SleepThreadUntil (CurTime + ONE_SECOND / 120); - CurTime = GetTimeCounter (); - if ((TDelta = (SIZE) (CurTime - StartTime)) > TTotal) - TDelta = TTotal; - - SetMusicVolume ((COUNT) (volume_beg + (SIZE) - ((long) (volume_end - volume_beg) * TDelta / TTotal))); - } while (TDelta < TTotal); - - FadeTask = 0; - FinishTask (task); - return (1); -} - -DWORD -FadeMusic (BYTE end_vol, SIZE TimeInterval) -{ - DWORD TimeOut; - - if (FadeTask) - { - volume_end = musicVolume; - TTotal = 1; - do - TaskSwitch (); - while (FadeTask); - TaskSwitch (); - } - - if ((TTotal = TimeInterval) <= 0) - TTotal = 1; /* prevent divide by zero and negative fade */ - volume_end = end_vol; - - if (TTotal > 1 && (FadeTask = AssignTask (fade_task, 0, - "fade music"))) - { - TimeOut = GetTimeCounter () + TTotal + 1; - } - else - { - SetMusicVolume (end_vol); - TimeOut = GetTimeCounter (); - } - - return (TimeOut); -} - -int -TFB_InitSound (int driver, int flags) -{ - int ret; - -#ifdef HAVE_OPENAL - ret = TFB_choose_InitSound (driver, flags); -#else - SoundDriver = driver; - if (SoundDriver == TFB_SOUNDDRIVER_OPENAL) - { - fprintf (stderr, "OpenAL driver not compiled in, so using MixSDL\n"); - SoundDriver = TFB_SOUNDDRIVER_MIXSDL; - } - if (SoundDriver == TFB_SOUNDDRIVER_MIXSDL) - ret = TFB_mixSDL_InitSound (SoundDriver, flags); - else - ret = TFB_NoSound_InitSound (SoundDriver, flags); -#endif - if (ret != 0) - { - fprintf (stderr, "Sound driver initialization failed.\n" - "This may happen when a soundcard is " - "not present or not available.\n" - "NOTICE: Try running UQM with '--sound=none' option\n"); - exit (EXIT_FAILURE); - } - - return ret; -} - -void -TFB_UninitSound (void) -{ - switch (SoundDriver) - { - case TFB_SOUNDDRIVER_OPENAL: -#ifdef HAVE_OPENAL - TFB_alUninitSound (); -#else - fprintf (stderr, "TFB_UninitSound(): driver is set to OpenAL" - "while OpenAL driver is not compiled in\n"); -#endif - break; - - case TFB_SOUNDDRIVER_MIXSDL: - TFB_mixSDL_UninitSound (); - break; - - case TFB_SOUNDDRIVER_NOSOUND: - TFB_NoSound_UninitSound (); - break; - } -} diff --git a/sc2/src/sc2code/libs/sound/sound_common.h b/sc2/src/sc2code/libs/sound/sound_common.h deleted file mode 100644 index 91f264dbc..000000000 --- a/sc2/src/sc2code/libs/sound/sound_common.h +++ /dev/null @@ -1,44 +0,0 @@ -//Copyright Paul Reiche, Fred Ford. 1992-2002 - -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef SOUND_COMMON_H -#define SOUND_COMMON_H - -// driver for TFB_InitSound -enum -{ - TFB_SOUNDDRIVER_MIXSDL, - TFB_SOUNDDRIVER_NOSOUND, - TFB_SOUNDDRIVER_OPENAL -}; -extern int SoundDriver; - -// flags for TFB_InitSound -#define TFB_SOUNDFLAGS_HQAUDIO (1<<0) // high quality audio -#define TFB_SOUNDFLAGS_MQAUDIO (1<<1) // medium quality audio -#define TFB_SOUNDFLAGS_LQAUDIO (1<<2) // low quality audio - -int TFB_InitSound (int driver, int flags); -void TFB_UninitSound (void); - -extern int musicVolume; -extern float musicVolumeScale; -extern float sfxVolumeScale; -extern float speechVolumeScale; - -#endif