comparison src/audio/dummy/SDL_dummyaudio.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents b1f8c14f0df5
children 5f6550e5184f 37c9c4590689
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
35 35
36 /* The tag name used by DUMMY audio */ 36 /* The tag name used by DUMMY audio */
37 #define DUMMYAUD_DRIVER_NAME "dummy" 37 #define DUMMYAUD_DRIVER_NAME "dummy"
38 38
39 /* Audio driver functions */ 39 /* Audio driver functions */
40 static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); 40 static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec);
41 static void DUMMYAUD_WaitAudio(_THIS); 41 static void DUMMYAUD_WaitAudio(_THIS);
42 static void DUMMYAUD_PlayAudio(_THIS); 42 static void DUMMYAUD_PlayAudio(_THIS);
43 static Uint8 *DUMMYAUD_GetAudioBuf(_THIS); 43 static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
44 static void DUMMYAUD_CloseAudio(_THIS); 44 static void DUMMYAUD_CloseAudio(_THIS);
45 45
46 /* Audio driver bootstrap functions */ 46 /* Audio driver bootstrap functions */
47 static int DUMMYAUD_Available(void) 47 static int
48 DUMMYAUD_Available(void)
48 { 49 {
49 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); 50 const char *envr = SDL_getenv("SDL_AUDIODRIVER");
50 if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) { 51 if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
51 return(1); 52 return (1);
52 } 53 }
53 return(0); 54 return (0);
54 } 55 }
55 56
56 static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device) 57 static void
58 DUMMYAUD_DeleteDevice(SDL_AudioDevice * device)
57 { 59 {
58 SDL_free(device->hidden); 60 SDL_free(device->hidden);
59 SDL_free(device); 61 SDL_free(device);
60 } 62 }
61 63
62 static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex) 64 static SDL_AudioDevice *
65 DUMMYAUD_CreateDevice(int devindex)
63 { 66 {
64 SDL_AudioDevice *this; 67 SDL_AudioDevice *this;
65 68
66 /* Initialize all variables that we clean on shutdown */ 69 /* Initialize all variables that we clean on shutdown */
67 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); 70 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
68 if ( this ) { 71 if (this) {
69 SDL_memset(this, 0, (sizeof *this)); 72 SDL_memset(this, 0, (sizeof *this));
70 this->hidden = (struct SDL_PrivateAudioData *) 73 this->hidden = (struct SDL_PrivateAudioData *)
71 SDL_malloc((sizeof *this->hidden)); 74 SDL_malloc((sizeof *this->hidden));
72 } 75 }
73 if ( (this == NULL) || (this->hidden == NULL) ) { 76 if ((this == NULL) || (this->hidden == NULL)) {
74 SDL_OutOfMemory(); 77 SDL_OutOfMemory();
75 if ( this ) { 78 if (this) {
76 SDL_free(this); 79 SDL_free(this);
77 } 80 }
78 return(0); 81 return (0);
79 } 82 }
80 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 83 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
81 84
82 /* Set the function pointers */ 85 /* Set the function pointers */
83 this->OpenAudio = DUMMYAUD_OpenAudio; 86 this->OpenAudio = DUMMYAUD_OpenAudio;
84 this->WaitAudio = DUMMYAUD_WaitAudio; 87 this->WaitAudio = DUMMYAUD_WaitAudio;
85 this->PlayAudio = DUMMYAUD_PlayAudio; 88 this->PlayAudio = DUMMYAUD_PlayAudio;
86 this->GetAudioBuf = DUMMYAUD_GetAudioBuf; 89 this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
87 this->CloseAudio = DUMMYAUD_CloseAudio; 90 this->CloseAudio = DUMMYAUD_CloseAudio;
88 91
89 this->free = DUMMYAUD_DeleteDevice; 92 this->free = DUMMYAUD_DeleteDevice;
90 93
91 return this; 94 return this;
92 } 95 }
93 96
94 AudioBootStrap DUMMYAUD_bootstrap = { 97 AudioBootStrap DUMMYAUD_bootstrap = {
95 DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", 98 DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
96 DUMMYAUD_Available, DUMMYAUD_CreateDevice 99 DUMMYAUD_Available, DUMMYAUD_CreateDevice
97 }; 100 };
98 101
99 /* This function waits until it is possible to write a full sound buffer */ 102 /* This function waits until it is possible to write a full sound buffer */
100 static void DUMMYAUD_WaitAudio(_THIS) 103 static void
104 DUMMYAUD_WaitAudio(_THIS)
101 { 105 {
102 /* Don't block on first calls to simulate initial fragment filling. */ 106 /* Don't block on first calls to simulate initial fragment filling. */
103 if (this->hidden->initial_calls) 107 if (this->hidden->initial_calls)
104 this->hidden->initial_calls--; 108 this->hidden->initial_calls--;
105 else 109 else
106 SDL_Delay(this->hidden->write_delay); 110 SDL_Delay(this->hidden->write_delay);
107 } 111 }
108 112
109 static void DUMMYAUD_PlayAudio(_THIS) 113 static void
114 DUMMYAUD_PlayAudio(_THIS)
110 { 115 {
111 /* no-op...this is a null driver. */ 116 /* no-op...this is a null driver. */
112 } 117 }
113 118
114 static Uint8 *DUMMYAUD_GetAudioBuf(_THIS) 119 static Uint8 *
120 DUMMYAUD_GetAudioBuf(_THIS)
115 { 121 {
116 return(this->hidden->mixbuf); 122 return (this->hidden->mixbuf);
117 } 123 }
118 124
119 static void DUMMYAUD_CloseAudio(_THIS) 125 static void
126 DUMMYAUD_CloseAudio(_THIS)
120 { 127 {
121 if ( this->hidden->mixbuf != NULL ) { 128 if (this->hidden->mixbuf != NULL) {
122 SDL_FreeAudioMem(this->hidden->mixbuf); 129 SDL_FreeAudioMem(this->hidden->mixbuf);
123 this->hidden->mixbuf = NULL; 130 this->hidden->mixbuf = NULL;
124 } 131 }
125 } 132 }
126 133
127 static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) 134 static int
135 DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
128 { 136 {
129 float bytes_per_sec = 0.0f; 137 float bytes_per_sec = 0.0f;
130 138
131 /* Allocate mixing buffer */ 139 /* Allocate mixing buffer */
132 this->hidden->mixlen = spec->size; 140 this->hidden->mixlen = spec->size;
133 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); 141 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
134 if ( this->hidden->mixbuf == NULL ) { 142 if (this->hidden->mixbuf == NULL) {
135 return(-1); 143 return (-1);
136 } 144 }
137 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); 145 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
138 146
139 bytes_per_sec = (float) (((spec->format & 0xFF) / 8) * 147 bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
140 spec->channels * spec->freq); 148 spec->channels * spec->freq);
141 149
142 /* 150 /*
143 * We try to make this request more audio at the correct rate for 151 * We try to make this request more audio at the correct rate for
144 * a given audio spec, so timing stays fairly faithful. 152 * a given audio spec, so timing stays fairly faithful.
145 * Also, we have it not block at all for the first two calls, so 153 * Also, we have it not block at all for the first two calls, so
146 * it seems like we're filling two audio fragments right out of the 154 * it seems like we're filling two audio fragments right out of the
147 * gate, like other SDL drivers tend to do. 155 * gate, like other SDL drivers tend to do.
148 */ 156 */
149 this->hidden->initial_calls = 2; 157 this->hidden->initial_calls = 2;
150 this->hidden->write_delay = 158 this->hidden->write_delay =
151 (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f); 159 (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
152 160
153 /* We're ready to rock and roll. :-) */ 161 /* We're ready to rock and roll. :-) */
154 return(0); 162 return (0);
155 } 163 }
156 164
165 /* vi: set ts=4 sw=4 expandtab: */