By default all the real targets have dummy audio/video and disk audio.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 This file hacked^H^H^H^H^H^Hwritten by Ryan C. Gordon
25 #include "SDL_config.h"
27 /* Output audio to nowhere... */
29 #include "SDL_rwops.h"
30 #include "SDL_timer.h"
31 #include "SDL_audio.h"
32 #include "../SDL_audiomem.h"
33 #include "../SDL_audio_c.h"
34 #include "../SDL_audiodev_c.h"
35 #include "SDL_dummyaudio.h"
37 /* The tag name used by DUMMY audio */
38 #define DUMMYAUD_DRIVER_NAME "dummy"
40 /* environment variables and defaults. */
41 #define DUMMYENVR_WRITEDELAY "SDL_DUMMYAUDIODELAY"
42 #define DUMMYDEFAULT_WRITEDELAY 150
44 /* Audio driver functions */
45 static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
46 static void DUMMYAUD_WaitAudio(_THIS);
47 static void DUMMYAUD_PlayAudio(_THIS);
48 static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
49 static void DUMMYAUD_CloseAudio(_THIS);
51 /* Audio driver bootstrap functions */
52 static int DUMMYAUD_Available(void)
54 const char *envr = SDL_getenv("SDL_AUDIODRIVER");
55 if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
61 static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device)
63 SDL_free(device->hidden);
67 static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex)
69 SDL_AudioDevice *this;
72 /* Initialize all variables that we clean on shutdown */
73 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
75 SDL_memset(this, 0, (sizeof *this));
76 this->hidden = (struct SDL_PrivateAudioData *)
77 SDL_malloc((sizeof *this->hidden));
79 if ( (this == NULL) || (this->hidden == NULL) ) {
86 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
88 envr = SDL_getenv(DUMMYENVR_WRITEDELAY);
89 this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DUMMYDEFAULT_WRITEDELAY;
91 /* Set the function pointers */
92 this->OpenAudio = DUMMYAUD_OpenAudio;
93 this->WaitAudio = DUMMYAUD_WaitAudio;
94 this->PlayAudio = DUMMYAUD_PlayAudio;
95 this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
96 this->CloseAudio = DUMMYAUD_CloseAudio;
98 this->free = DUMMYAUD_DeleteDevice;
103 AudioBootStrap DUMMYAUD_bootstrap = {
104 DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
105 DUMMYAUD_Available, DUMMYAUD_CreateDevice
108 /* This function waits until it is possible to write a full sound buffer */
109 static void DUMMYAUD_WaitAudio(_THIS)
111 SDL_Delay(this->hidden->write_delay);
114 static void DUMMYAUD_PlayAudio(_THIS)
116 /* no-op...this is a null driver. */
119 static Uint8 *DUMMYAUD_GetAudioBuf(_THIS)
121 return(this->hidden->mixbuf);
124 static void DUMMYAUD_CloseAudio(_THIS)
126 if ( this->hidden->mixbuf != NULL ) {
127 SDL_FreeAudioMem(this->hidden->mixbuf);
128 this->hidden->mixbuf = NULL;
132 static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
134 /* Allocate mixing buffer */
135 this->hidden->mixlen = spec->size;
136 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
137 if ( this->hidden->mixbuf == NULL ) {
140 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
142 /* We're ready to rock and roll. :-) */