comparison src/audio/mint/SDL_mintaudio.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
54 long SDL_MintAudio_thread_pid; 54 long SDL_MintAudio_thread_pid;
55 55
56 /* The callback function, called by each driver whenever needed */ 56 /* The callback function, called by each driver whenever needed */
57 57
58 void 58 void
59 SDL_MintAudio_Callback (void) 59 SDL_MintAudio_Callback(void)
60 { 60 {
61 Uint8 *buffer; 61 Uint8 *buffer;
62 SDL_AudioDevice *audio = SDL_MintAudio_device; 62 SDL_AudioDevice *audio = SDL_MintAudio_device;
63 63
64 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; 64 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
65 SDL_memset (buffer, audio->spec.silence, audio->spec.size); 65 SDL_memset(buffer, audio->spec.silence, audio->spec.size);
66 66
67 if (audio->paused) 67 if (audio->paused)
68 return; 68 return;
69 69
70 if (audio->convert.needed) { 70 if (audio->convert.needed) {
73 if (audio->convert.src_format == AUDIO_U8) { 73 if (audio->convert.src_format == AUDIO_U8) {
74 silence = 0x80; 74 silence = 0x80;
75 } else { 75 } else {
76 silence = 0; 76 silence = 0;
77 } 77 }
78 SDL_memset (audio->convert.buf, silence, audio->convert.len); 78 SDL_memset(audio->convert.buf, silence, audio->convert.len);
79 audio->spec.callback (audio->spec.userdata, 79 audio->spec.callback(audio->spec.userdata,
80 (Uint8 *) audio->convert.buf, 80 (Uint8 *) audio->convert.buf,
81 audio->convert.len); 81 audio->convert.len);
82 SDL_ConvertAudio (&audio->convert); 82 SDL_ConvertAudio(&audio->convert);
83 SDL_memcpy (buffer, audio->convert.buf, audio->convert.len_cvt); 83 SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
84 } else { 84 } else {
85 audio->spec.callback (audio->spec.userdata, buffer, audio->spec.size); 85 audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size);
86 } 86 }
87 } 87 }
88 88
89 /* Add a new frequency/clock/predivisor to the current list */ 89 /* Add a new frequency/clock/predivisor to the current list */
90 void 90 void
91 SDL_MintAudio_AddFrequency (_THIS, Uint32 frequency, Uint32 clock, 91 SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
92 Uint32 prediv, int gpio_bits) 92 Uint32 prediv, int gpio_bits)
93 { 93 {
94 int i, p; 94 int i, p;
95 95
96 if (MINTAUDIO_freqcount == MINTAUDIO_maxfreqs) { 96 if (MINTAUDIO_freqcount == MINTAUDIO_maxfreqs) {
97 return; 97 return;
105 } 105 }
106 106
107 /* Put all following ones farer */ 107 /* Put all following ones farer */
108 if (MINTAUDIO_freqcount > 0) { 108 if (MINTAUDIO_freqcount > 0) {
109 for (i = MINTAUDIO_freqcount; i > p; i--) { 109 for (i = MINTAUDIO_freqcount; i > p; i--) {
110 SDL_memcpy (&MINTAUDIO_frequencies[i], 110 SDL_memcpy(&MINTAUDIO_frequencies[i],
111 &MINTAUDIO_frequencies[i - 1], 111 &MINTAUDIO_frequencies[i - 1],
112 sizeof (mint_frequency_t)); 112 sizeof(mint_frequency_t));
113 } 113 }
114 } 114 }
115 115
116 /* And insert new one */ 116 /* And insert new one */
117 MINTAUDIO_frequencies[p].frequency = frequency; 117 MINTAUDIO_frequencies[p].frequency = frequency;
122 MINTAUDIO_freqcount++; 122 MINTAUDIO_freqcount++;
123 } 123 }
124 124
125 /* Search for the nearest frequency */ 125 /* Search for the nearest frequency */
126 int 126 int
127 SDL_MintAudio_SearchFrequency (_THIS, int desired_freq) 127 SDL_MintAudio_SearchFrequency(_THIS, int desired_freq)
128 { 128 {
129 int i; 129 int i;
130 130
131 /* Only 1 freq ? */ 131 /* Only 1 freq ? */
132 if (MINTAUDIO_freqcount == 1) { 132 if (MINTAUDIO_freqcount == 1) {
145 return MINTAUDIO_freqcount - 1; 145 return MINTAUDIO_freqcount - 1;
146 } 146 }
147 147
148 /* The thread function, used under MiNT with xbios */ 148 /* The thread function, used under MiNT with xbios */
149 int 149 int
150 SDL_MintAudio_Thread (long param) 150 SDL_MintAudio_Thread(long param)
151 { 151 {
152 SndBufPtr pointers; 152 SndBufPtr pointers;
153 SDL_bool buffers_filled[2] = { SDL_FALSE, SDL_FALSE }; 153 SDL_bool buffers_filled[2] = { SDL_FALSE, SDL_FALSE };
154 154
155 SDL_MintAudio_thread_finished = SDL_FALSE; 155 SDL_MintAudio_thread_finished = SDL_FALSE;
156 while (!SDL_MintAudio_quit_thread) { 156 while (!SDL_MintAudio_quit_thread) {
157 if (Buffptr (&pointers) != 0) 157 if (Buffptr(&pointers) != 0)
158 continue; 158 continue;
159 159
160 if (((unsigned long) pointers.play >= 160 if (((unsigned long) pointers.play >=
161 (unsigned long) SDL_MintAudio_audiobuf[0]) 161 (unsigned long) SDL_MintAudio_audiobuf[0])
162 && ((unsigned long) pointers.play <= 162 && ((unsigned long) pointers.play <=
163 (unsigned long) SDL_MintAudio_audiobuf[1])) { 163 (unsigned long) SDL_MintAudio_audiobuf[1])) {
164 /* DMA is reading buffer #0, setup buffer #1 if not already done */ 164 /* DMA is reading buffer #0, setup buffer #1 if not already done */
165 if (!buffers_filled[1]) { 165 if (!buffers_filled[1]) {
166 SDL_MintAudio_numbuf = 1; 166 SDL_MintAudio_numbuf = 1;
167 SDL_MintAudio_Callback (); 167 SDL_MintAudio_Callback();
168 Setbuffer (0, SDL_MintAudio_audiobuf[1], 168 Setbuffer(0, SDL_MintAudio_audiobuf[1],
169 SDL_MintAudio_audiobuf[1] + 169 SDL_MintAudio_audiobuf[1] +
170 SDL_MintAudio_audiosize); 170 SDL_MintAudio_audiosize);
171 buffers_filled[1] = SDL_TRUE; 171 buffers_filled[1] = SDL_TRUE;
172 buffers_filled[0] = SDL_FALSE; 172 buffers_filled[0] = SDL_FALSE;
173 } 173 }
174 } else { 174 } else {
175 /* DMA is reading buffer #1, setup buffer #0 if not already done */ 175 /* DMA is reading buffer #1, setup buffer #0 if not already done */
176 if (!buffers_filled[0]) { 176 if (!buffers_filled[0]) {
177 SDL_MintAudio_numbuf = 0; 177 SDL_MintAudio_numbuf = 0;
178 SDL_MintAudio_Callback (); 178 SDL_MintAudio_Callback();
179 Setbuffer (0, SDL_MintAudio_audiobuf[0], 179 Setbuffer(0, SDL_MintAudio_audiobuf[0],
180 SDL_MintAudio_audiobuf[0] + 180 SDL_MintAudio_audiobuf[0] +
181 SDL_MintAudio_audiosize); 181 SDL_MintAudio_audiosize);
182 buffers_filled[0] = SDL_TRUE; 182 buffers_filled[0] = SDL_TRUE;
183 buffers_filled[1] = SDL_FALSE; 183 buffers_filled[1] = SDL_FALSE;
184 } 184 }
185 } 185 }
186 186
187 usleep (100); 187 usleep(100);
188 } 188 }
189 SDL_MintAudio_thread_finished = SDL_TRUE; 189 SDL_MintAudio_thread_finished = SDL_TRUE;
190 return 0; 190 return 0;
191 } 191 }
192 192
193 void 193 void
194 SDL_MintAudio_WaitThread (void) 194 SDL_MintAudio_WaitThread(void)
195 { 195 {
196 if (!SDL_MintAudio_mint_present) 196 if (!SDL_MintAudio_mint_present)
197 return; 197 return;
198 198
199 if (SDL_MintAudio_thread_finished) 199 if (SDL_MintAudio_thread_finished)
200 return; 200 return;
201 201
202 SDL_MintAudio_quit_thread = SDL_TRUE; 202 SDL_MintAudio_quit_thread = SDL_TRUE;
203 while (!SDL_MintAudio_thread_finished) { 203 while (!SDL_MintAudio_thread_finished) {
204 Syield (); 204 Syield();
205 } 205 }
206 } 206 }
207 207
208 /* vi: set ts=4 sw=4 expandtab: */ 208 /* vi: set ts=4 sw=4 expandtab: */