1.1 --- a/src/audio/dummy/SDL_dummyaudio.c Sun Oct 01 16:10:41 2006 +0000
1.2 +++ b/src/audio/dummy/SDL_dummyaudio.c Tue Oct 17 09:15:21 2006 +0000
1.3 @@ -25,141 +25,27 @@
1.4
1.5 /* Output audio to nowhere... */
1.6
1.7 -#include "SDL_rwops.h"
1.8 -#include "SDL_timer.h"
1.9 #include "SDL_audio.h"
1.10 -#include "../SDL_audiomem.h"
1.11 #include "../SDL_audio_c.h"
1.12 -#include "../SDL_audiodev_c.h"
1.13 #include "SDL_dummyaudio.h"
1.14
1.15 -/* The tag name used by DUMMY audio */
1.16 -#define DUMMYAUD_DRIVER_NAME "dummy"
1.17 -
1.18 -/* Audio driver functions */
1.19 -static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec);
1.20 -static void DUMMYAUD_WaitAudio(_THIS);
1.21 -static void DUMMYAUD_PlayAudio(_THIS);
1.22 -static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
1.23 -static void DUMMYAUD_CloseAudio(_THIS);
1.24 -
1.25 -/* Audio driver bootstrap functions */
1.26 static int
1.27 -DUMMYAUD_Available(void)
1.28 +DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture)
1.29 {
1.30 - const char *envr = SDL_getenv("SDL_AUDIODRIVER");
1.31 - if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
1.32 - return (1);
1.33 - }
1.34 - return (0);
1.35 + return 1; /* always succeeds. */
1.36 }
1.37
1.38 -static void
1.39 -DUMMYAUD_DeleteDevice(SDL_AudioDevice * device)
1.40 -{
1.41 - SDL_free(device->hidden);
1.42 - SDL_free(device);
1.43 -}
1.44 -
1.45 -static SDL_AudioDevice *
1.46 -DUMMYAUD_CreateDevice(int devindex)
1.47 +static int
1.48 +DUMMYAUD_Init(SDL_AudioDriverImpl *impl)
1.49 {
1.50 - SDL_AudioDevice *this;
1.51 -
1.52 - /* Initialize all variables that we clean on shutdown */
1.53 - this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
1.54 - if (this) {
1.55 - SDL_memset(this, 0, (sizeof *this));
1.56 - this->hidden = (struct SDL_PrivateAudioData *)
1.57 - SDL_malloc((sizeof *this->hidden));
1.58 - }
1.59 - if ((this == NULL) || (this->hidden == NULL)) {
1.60 - SDL_OutOfMemory();
1.61 - if (this) {
1.62 - SDL_free(this);
1.63 - }
1.64 - return (0);
1.65 - }
1.66 - SDL_memset(this->hidden, 0, (sizeof *this->hidden));
1.67 -
1.68 /* Set the function pointers */
1.69 - this->OpenAudio = DUMMYAUD_OpenAudio;
1.70 - this->WaitAudio = DUMMYAUD_WaitAudio;
1.71 - this->PlayAudio = DUMMYAUD_PlayAudio;
1.72 - this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
1.73 - this->CloseAudio = DUMMYAUD_CloseAudio;
1.74 -
1.75 - this->free = DUMMYAUD_DeleteDevice;
1.76 -
1.77 - return this;
1.78 + impl->OpenDevice = DUMMYAUD_OpenDevice;
1.79 + impl->OnlyHasDefaultOutputDevice = 1;
1.80 + return 1;
1.81 }
1.82
1.83 AudioBootStrap DUMMYAUD_bootstrap = {
1.84 - DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
1.85 - DUMMYAUD_Available, DUMMYAUD_CreateDevice
1.86 + "dummy", "SDL dummy audio driver", DUMMYAUD_Init, 1
1.87 };
1.88
1.89 -/* This function waits until it is possible to write a full sound buffer */
1.90 -static void
1.91 -DUMMYAUD_WaitAudio(_THIS)
1.92 -{
1.93 - /* Don't block on first calls to simulate initial fragment filling. */
1.94 - if (this->hidden->initial_calls)
1.95 - this->hidden->initial_calls--;
1.96 - else
1.97 - SDL_Delay(this->hidden->write_delay);
1.98 -}
1.99 -
1.100 -static void
1.101 -DUMMYAUD_PlayAudio(_THIS)
1.102 -{
1.103 - /* no-op...this is a null driver. */
1.104 -}
1.105 -
1.106 -static Uint8 *
1.107 -DUMMYAUD_GetAudioBuf(_THIS)
1.108 -{
1.109 - return (this->hidden->mixbuf);
1.110 -}
1.111 -
1.112 -static void
1.113 -DUMMYAUD_CloseAudio(_THIS)
1.114 -{
1.115 - if (this->hidden->mixbuf != NULL) {
1.116 - SDL_FreeAudioMem(this->hidden->mixbuf);
1.117 - this->hidden->mixbuf = NULL;
1.118 - }
1.119 -}
1.120 -
1.121 -static int
1.122 -DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
1.123 -{
1.124 - float bytes_per_sec = 0.0f;
1.125 -
1.126 - /* Allocate mixing buffer */
1.127 - this->hidden->mixlen = spec->size;
1.128 - this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
1.129 - if (this->hidden->mixbuf == NULL) {
1.130 - return (-1);
1.131 - }
1.132 - SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
1.133 -
1.134 - bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
1.135 - spec->channels * spec->freq);
1.136 -
1.137 - /*
1.138 - * We try to make this request more audio at the correct rate for
1.139 - * a given audio spec, so timing stays fairly faithful.
1.140 - * Also, we have it not block at all for the first two calls, so
1.141 - * it seems like we're filling two audio fragments right out of the
1.142 - * gate, like other SDL drivers tend to do.
1.143 - */
1.144 - this->hidden->initial_calls = 2;
1.145 - this->hidden->write_delay =
1.146 - (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
1.147 -
1.148 - /* We're ready to rock and roll. :-) */
1.149 - return (0);
1.150 -}
1.151 -
1.152 /* vi: set ts=4 sw=4 expandtab: */