1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/audio/dummy/SDL_dummyaudio.c Tue Mar 14 08:53:33 2006 +0000
1.3 @@ -0,0 +1,154 @@
1.4 +/*
1.5 + SDL - Simple DirectMedia Layer
1.6 + Copyright (C) 1997-2006 Sam Lantinga
1.7 +
1.8 + This library is free software; you can redistribute it and/or
1.9 + modify it under the terms of the GNU Lesser General Public
1.10 + License as published by the Free Software Foundation; either
1.11 + version 2.1 of the License, or (at your option) any later version.
1.12 +
1.13 + This library is distributed in the hope that it will be useful,
1.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.16 + Lesser General Public License for more details.
1.17 +
1.18 + You should have received a copy of the GNU Lesser General Public
1.19 + License along with this library; if not, write to the Free Software
1.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1.21 +
1.22 + Sam Lantinga
1.23 + slouken@libsdl.org
1.24 +
1.25 + This file hacked^H^H^H^H^H^Hwritten by Ryan C. Gordon
1.26 + (icculus@icculus.org)
1.27 +*/
1.28 +#include "SDL_config.h"
1.29 +
1.30 +/* Output raw audio data to a file. */
1.31 +
1.32 +#if HAVE_STDIO_H
1.33 +#include <stdio.h>
1.34 +#endif
1.35 +
1.36 +#include "SDL_rwops.h"
1.37 +#include "SDL_timer.h"
1.38 +#include "SDL_audio.h"
1.39 +#include "../SDL_audiomem.h"
1.40 +#include "../SDL_audio_c.h"
1.41 +#include "../SDL_audiodev_c.h"
1.42 +#include "SDL_dummyaudio.h"
1.43 +
1.44 +/* The tag name used by DUMMY audio */
1.45 +#define DUMMYAUD_DRIVER_NAME "dummy"
1.46 +
1.47 +/* environment variables and defaults. */
1.48 +#define DUMMYENVR_WRITEDELAY "SDL_DUMMYAUDIODELAY"
1.49 +#define DUMMYDEFAULT_WRITEDELAY 150
1.50 +
1.51 +/* Audio driver functions */
1.52 +static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
1.53 +static void DUMMYAUD_WaitAudio(_THIS);
1.54 +static void DUMMYAUD_PlayAudio(_THIS);
1.55 +static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
1.56 +static void DUMMYAUD_CloseAudio(_THIS);
1.57 +
1.58 +/* Audio driver bootstrap functions */
1.59 +static int DUMMYAUD_Available(void)
1.60 +{
1.61 + const char *envr = SDL_getenv("SDL_AUDIODRIVER");
1.62 + if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
1.63 + return(1);
1.64 + }
1.65 + return(0);
1.66 +}
1.67 +
1.68 +static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device)
1.69 +{
1.70 + SDL_free(device->hidden);
1.71 + SDL_free(device);
1.72 +}
1.73 +
1.74 +static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex)
1.75 +{
1.76 + SDL_AudioDevice *this;
1.77 + const char *envr;
1.78 +
1.79 + /* Initialize all variables that we clean on shutdown */
1.80 + this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
1.81 + if ( this ) {
1.82 + SDL_memset(this, 0, (sizeof *this));
1.83 + this->hidden = (struct SDL_PrivateAudioData *)
1.84 + SDL_malloc((sizeof *this->hidden));
1.85 + }
1.86 + if ( (this == NULL) || (this->hidden == NULL) ) {
1.87 + SDL_OutOfMemory();
1.88 + if ( this ) {
1.89 + SDL_free(this);
1.90 + }
1.91 + return(0);
1.92 + }
1.93 + SDL_memset(this->hidden, 0, (sizeof *this->hidden));
1.94 +
1.95 + envr = SDL_getenv(DUMMYENVR_WRITEDELAY);
1.96 + this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DUMMYDEFAULT_WRITEDELAY;
1.97 +
1.98 + /* Set the function pointers */
1.99 + this->OpenAudio = DUMMYAUD_OpenAudio;
1.100 + this->WaitAudio = DUMMYAUD_WaitAudio;
1.101 + this->PlayAudio = DUMMYAUD_PlayAudio;
1.102 + this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
1.103 + this->CloseAudio = DUMMYAUD_CloseAudio;
1.104 +
1.105 + this->free = DUMMYAUD_DeleteDevice;
1.106 +
1.107 + return this;
1.108 +}
1.109 +
1.110 +AudioBootStrap DUMMYAUD_bootstrap = {
1.111 + DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
1.112 + DUMMYAUD_Available, DUMMYAUD_CreateDevice
1.113 +};
1.114 +
1.115 +/* This function waits until it is possible to write a full sound buffer */
1.116 +static void DUMMYAUD_WaitAudio(_THIS)
1.117 +{
1.118 + SDL_Delay(this->hidden->write_delay);
1.119 +}
1.120 +
1.121 +static void DUMMYAUD_PlayAudio(_THIS)
1.122 +{
1.123 + /* no-op...this is a null driver. */
1.124 +}
1.125 +
1.126 +static Uint8 *DUMMYAUD_GetAudioBuf(_THIS)
1.127 +{
1.128 + return(this->hidden->mixbuf);
1.129 +}
1.130 +
1.131 +static void DUMMYAUD_CloseAudio(_THIS)
1.132 +{
1.133 + if ( this->hidden->mixbuf != NULL ) {
1.134 + SDL_FreeAudioMem(this->hidden->mixbuf);
1.135 + this->hidden->mixbuf = NULL;
1.136 + }
1.137 +}
1.138 +
1.139 +static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
1.140 +{
1.141 +#if HAVE_STDIO_H
1.142 + fprintf(stderr, "\nWARNING: You are using the SDL dummy audio driver!"
1.143 + " No sound will be output!\n\n");
1.144 +#endif
1.145 +
1.146 + /* Allocate mixing buffer */
1.147 + this->hidden->mixlen = spec->size;
1.148 + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
1.149 + if ( this->hidden->mixbuf == NULL ) {
1.150 + return(-1);
1.151 + }
1.152 + SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
1.153 +
1.154 + /* We're ready to rock and roll. :-) */
1.155 + return(0);
1.156 +}
1.157 +