Mercurial > sdl-ios-xcode
comparison src/audio/mint/SDL_mintaudio.c @ 1111:12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Wed, 10 Aug 2005 13:29:49 +0000 |
parents | 856f76a099c7 |
children | 080ed9ef0609 |
comparison
equal
deleted
inserted
replaced
1110:b6fdf299a2f3 | 1111:12c49532be00 |
---|---|
25 | 25 |
26 Patrice Mandin | 26 Patrice Mandin |
27 */ | 27 */ |
28 | 28 |
29 #include <string.h> | 29 #include <string.h> |
30 #include <unistd.h> | |
31 | |
32 #include <mint/osbind.h> | |
33 #include <mint/falcon.h> | |
34 #include <mint/mintbind.h> | |
30 | 35 |
31 #include "SDL_types.h" | 36 #include "SDL_types.h" |
32 #include "SDL_audio.h" | 37 #include "SDL_audio.h" |
33 | 38 |
34 #include "SDL_mintaudio.h" | 39 #include "SDL_mintaudio.h" |
41 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ | 46 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ |
42 unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ | 47 unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ |
43 unsigned short SDL_MintAudio_mutex; | 48 unsigned short SDL_MintAudio_mutex; |
44 unsigned long SDL_MintAudio_clocktics; | 49 unsigned long SDL_MintAudio_clocktics; |
45 cookie_stfa_t *SDL_MintAudio_stfa; | 50 cookie_stfa_t *SDL_MintAudio_stfa; |
51 | |
52 /* MiNT thread variables */ | |
53 SDL_bool SDL_MintAudio_mint_present; | |
54 SDL_bool SDL_MintAudio_quit_thread; | |
55 SDL_bool SDL_MintAudio_thread_finished; | |
56 long SDL_MintAudio_thread_pid; | |
46 | 57 |
47 /* The callback function, called by each driver whenever needed */ | 58 /* The callback function, called by each driver whenever needed */ |
48 | 59 |
49 void SDL_MintAudio_Callback(void) | 60 void SDL_MintAudio_Callback(void) |
50 { | 61 { |
127 } | 138 } |
128 | 139 |
129 /* Not in the array, give the latest */ | 140 /* Not in the array, give the latest */ |
130 return MINTAUDIO_freqcount-1; | 141 return MINTAUDIO_freqcount-1; |
131 } | 142 } |
143 | |
144 /* The thread function, used under MiNT with xbios */ | |
145 int SDL_MintAudio_Thread(long param) | |
146 { | |
147 SndBufPtr pointers; | |
148 SDL_bool buffers_filled[2] = {SDL_FALSE, SDL_FALSE}; | |
149 | |
150 SDL_MintAudio_thread_finished = SDL_FALSE; | |
151 while (!SDL_MintAudio_quit_thread) { | |
152 if (Buffptr(&pointers)!=0) | |
153 continue; | |
154 | |
155 if (( (unsigned long)pointers.play>=(unsigned long)SDL_MintAudio_audiobuf[0]) | |
156 && ( (unsigned long)pointers.play<=(unsigned long)SDL_MintAudio_audiobuf[1])) | |
157 { | |
158 /* DMA is reading buffer #0, setup buffer #1 if not already done */ | |
159 if (!buffers_filled[1]) { | |
160 SDL_MintAudio_numbuf = 1; | |
161 SDL_MintAudio_Callback(); | |
162 Setbuffer(0, SDL_MintAudio_audiobuf[1], SDL_MintAudio_audiobuf[1] + SDL_MintAudio_audiosize); | |
163 buffers_filled[1]=SDL_TRUE; | |
164 buffers_filled[0]=SDL_FALSE; | |
165 } | |
166 } else { | |
167 /* DMA is reading buffer #1, setup buffer #0 if not already done */ | |
168 if (!buffers_filled[0]) { | |
169 SDL_MintAudio_numbuf = 0; | |
170 SDL_MintAudio_Callback(); | |
171 Setbuffer(0, SDL_MintAudio_audiobuf[0], SDL_MintAudio_audiobuf[0] + SDL_MintAudio_audiosize); | |
172 buffers_filled[0]=SDL_TRUE; | |
173 buffers_filled[1]=SDL_FALSE; | |
174 } | |
175 } | |
176 | |
177 usleep(1000); | |
178 } | |
179 SDL_MintAudio_thread_finished = SDL_TRUE; | |
180 return 0; | |
181 } | |
182 | |
183 void SDL_MintAudio_WaitThread(void) | |
184 { | |
185 if (!SDL_MintAudio_mint_present) | |
186 return; | |
187 | |
188 if (SDL_MintAudio_thread_finished) | |
189 return; | |
190 | |
191 SDL_MintAudio_quit_thread = SDL_TRUE; | |
192 while (!SDL_MintAudio_thread_finished) { | |
193 Syield(); | |
194 } | |
195 } |