comparison src/audio/mme/SDL_mmeaudio.c @ 2060:866052b01ee5

indent is evil
author Sam Lantinga <slouken@libsdl.org>
date Sat, 28 Oct 2006 16:48:03 +0000
parents 5f6550e5184f
children 99210400e8b9
comparison
equal deleted inserted replaced
2059:4685ccd33d0e 2060:866052b01ee5
61 Uint8 *mixbuf = NULL; 61 Uint8 *mixbuf = NULL;
62 int i; 62 int i;
63 63
64 /* Initialize all variables that we clean on shutdown */ 64 /* Initialize all variables that we clean on shutdown */
65 this->hidden = (struct SDL_PrivateAudioData *) 65 this->hidden = (struct SDL_PrivateAudioData *)
66 SDL_malloc((sizeof *this->hidden)); 66 SDL_malloc((sizeof *this->hidden));
67 if (this->hidden == NULL) { 67 if (this->hidden == NULL) {
68 SDL_OutOfMemory(); 68 SDL_OutOfMemory();
69 return 0; 69 return 0;
70 } 70 }
71 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 71 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
76 MME_CloseDevice(this); 76 MME_CloseDevice(this);
77 SDL_OutOfMemory(); 77 SDL_OutOfMemory();
78 return 0; 78 return 0;
79 } 79 }
80 80
81 SDL_memset(this->hidden->shm, '\0', sizeof (*this->hidden->shm)); 81 SDL_memset(this->hidden->shm, '\0', sizeof(*this->hidden->shm));
82 this->hidden->shm->sound = 0; 82 this->hidden->shm->sound = 0;
83 this->hidden->shm->wFmt.wf.wFormatTag = WAVE_FORMAT_PCM; 83 this->hidden->shm->wFmt.wf.wFormatTag = WAVE_FORMAT_PCM;
84 84
85 /* Determine the audio parameters from the AudioSpec */ 85 /* Determine the audio parameters from the AudioSpec */
86 /* Try for a closest match on audio format */ 86 /* Try for a closest match on audio format */
87 for (test_format = SDL_FirstAudioFormat(this->spec.format); 87 for (test_format = SDL_FirstAudioFormat(this->spec.format);
88 !valid_format && test_format;) { 88 !valid_format && test_format;) {
89 valid_format = 1; 89 valid_format = 1;
90 switch (test_format) { 90 switch (test_format) {
91 case AUDIO_U8: 91 case AUDIO_U8:
92 case AUDIO_S16: 92 case AUDIO_S16:
93 case AUDIO_S32: 93 case AUDIO_S32:
94 break; 94 break;
95 default: 95 default:
96 valid_format = 0; 96 valid_format = 0;
97 test_format = SDL_NextAudioFormat(); 97 test_format = SDL_NextAudioFormat();
98 } 98 }
99 } 99 }
100 100
101 if (!valid_format) { 101 if (!valid_format) {
102 MME_CloseDevice(this); 102 MME_CloseDevice(this);
109 109
110 /* !!! FIXME: Can this handle more than stereo? */ 110 /* !!! FIXME: Can this handle more than stereo? */
111 this->hidden->shm->wFmt.wf.nChannels = this->spec.channels; 111 this->hidden->shm->wFmt.wf.nChannels = this->spec.channels;
112 this->hidden->shm->wFmt.wf.nSamplesPerSec = this->spec.freq; 112 this->hidden->shm->wFmt.wf.nSamplesPerSec = this->spec.freq;
113 this->hidden->shm->wFmt.wf.nBlockAlign = 113 this->hidden->shm->wFmt.wf.nBlockAlign =
114 this->hidden->shm->wFmt.wf.nChannels * 114 this->hidden->shm->wFmt.wf.nChannels *
115 this->hidden->shm->wFmt.wBitsPerSample / 8; 115 this->hidden->shm->wFmt.wBitsPerSample / 8;
116 this->hidden->shm->wFmt.wf.nAvgBytesPerSec = 116 this->hidden->shm->wFmt.wf.nAvgBytesPerSec =
117 this->hidden->shm->wFmt.wf.nSamplesPerSec * 117 this->hidden->shm->wFmt.wf.nSamplesPerSec *
118 this->hidden->shm->wFmt.wf.nBlockAlign; 118 this->hidden->shm->wFmt.wf.nBlockAlign;
119 119
120 /* Check the buffer size -- minimum of 1/4 second (word aligned) */ 120 /* Check the buffer size -- minimum of 1/4 second (word aligned) */
121 if (this->spec.samples < (this->spec.freq / 4)) 121 if (this->spec.samples < (this->spec.freq / 4))
122 this->spec.samples = ((this->spec.freq / 4) + 3) & ~3; 122 this->spec.samples = ((this->spec.freq / 4) + 3) & ~3;
123 123
148 for (i = 0; i < NUM_BUFFERS; i++) { 148 for (i = 0; i < NUM_BUFFERS; i++) {
149 this->hidden->shm->wHdr[i].lpData = &mixbuf[i * (this->spec.size)]; 149 this->hidden->shm->wHdr[i].lpData = &mixbuf[i * (this->spec.size)];
150 this->hidden->shm->wHdr[i].dwBufferLength = this->spec.size; 150 this->hidden->shm->wHdr[i].dwBufferLength = this->spec.size;
151 this->hidden->shm->wHdr[i].dwFlags = 0; 151 this->hidden->shm->wHdr[i].dwFlags = 0;
152 this->hidden->shm->wHdr[i].dwUser = i; 152 this->hidden->shm->wHdr[i].dwUser = i;
153 this->hidden->shm->wHdr[i].dwLoops = 0; /* loop control counter */ 153 this->hidden->shm->wHdr[i].dwLoops = 0; /* loop control counter */
154 this->hidden->shm->wHdr[i].lpNext = NULL; /* reserved for driver */ 154 this->hidden->shm->wHdr[i].lpNext = NULL; /* reserved for driver */
155 this->hidden->shm->wHdr[i].reserved = 0; 155 this->hidden->shm->wHdr[i].reserved = 0;
156 inUse[i] = FALSE; 156 inUse[i] = FALSE;
157 } 157 }
158 this->hidden->next_buffer = 0; 158 this->hidden->next_buffer = 0;
159 159
181 MME_PlayDevice(_THIS) 181 MME_PlayDevice(_THIS)
182 { 182 {
183 /* Queue it up */ 183 /* Queue it up */
184 waveOutWrite(this->hidden->shm->sound, 184 waveOutWrite(this->hidden->shm->sound,
185 &(this->hidden->shm->wHdr[this->hidden->next_buffer]), 185 &(this->hidden->shm->wHdr[this->hidden->next_buffer]),
186 sizeof (WAVEHDR)); 186 sizeof(WAVEHDR));
187 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; 187 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
188 } 188 }
189 189
190 static void 190 static void
191 MME_WaitDone(_THIS) 191 MME_WaitDone(_THIS)
236 this->hidden = NULL; 236 this->hidden = NULL;
237 } 237 }
238 } 238 }
239 239
240 static int 240 static int
241 MME_Init(SDL_AudioDriverImpl *impl) 241 MME_Init(SDL_AudioDriverImpl * impl)
242 { 242 {
243 /* Set the function pointers */ 243 /* Set the function pointers */
244 impl->OpenDevice = MME_OpenDevice; 244 impl->OpenDevice = MME_OpenDevice;
245 impl->WaitDevice = MME_WaitDevice; 245 impl->WaitDevice = MME_WaitDevice;
246 impl->WaitDone = MME_WaitDone; 246 impl->WaitDone = MME_WaitDone;