summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl')
-rw-r--r--firmware/target/hosted/sdl/pcm-sdl.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c
index 020928d572..2c535b2dc5 100644
--- a/firmware/target/hosted/sdl/pcm-sdl.c
+++ b/firmware/target/hosted/sdl/pcm-sdl.c
@@ -56,7 +56,7 @@ static int sim_volume = 0;
56#if CONFIG_CODEC == SWCODEC 56#if CONFIG_CODEC == SWCODEC
57static int cvt_status = -1; 57static int cvt_status = -1;
58 58
59static Uint8* pcm_data; 59static const Uint8* pcm_data;
60static size_t pcm_data_size; 60static size_t pcm_data_size;
61static size_t pcm_sample_bytes; 61static size_t pcm_sample_bytes;
62static size_t pcm_channel_bytes; 62static size_t pcm_channel_bytes;
@@ -109,7 +109,7 @@ void pcm_play_dma_start(const void *addr, size_t size)
109{ 109{
110 pcm_dma_apply_settings_nolock(); 110 pcm_dma_apply_settings_nolock();
111 111
112 pcm_data = (Uint8 *) addr; 112 pcm_data = addr;
113 pcm_data_size = size; 113 pcm_data_size = size;
114 114
115 SDL_PauseAudio(0); 115 SDL_PauseAudio(0);
@@ -245,48 +245,48 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
245 245
246 /* Audio card wants more? Get some more then. */ 246 /* Audio card wants more? Get some more then. */
247 while (len > 0) { 247 while (len > 0) {
248 new_buffer = true; 248 new_buffer = pcm_play_dma_complete_callback(PCM_DMAST_OK,
249 pcm_play_get_more_callback((void **)&pcm_data, &pcm_data_size); 249 (const void **)&pcm_data, &pcm_data_size);
250
251 if (!new_buffer) {
252 DEBUGF("sdl_audio_callback: No Data.\n");
253 break;
254 }
255
250 start: 256 start:
251 if (pcm_data_size != 0) { 257 udata->num_in = pcm_data_size / pcm_sample_bytes;
252 udata->num_in = pcm_data_size / pcm_sample_bytes; 258 udata->num_out = len / pcm_sample_bytes;
253 udata->num_out = len / pcm_sample_bytes;
254 259
255 write_to_soundcard(udata); 260 write_to_soundcard(udata);
256 261
257 udata->num_in *= pcm_sample_bytes; 262 udata->num_in *= pcm_sample_bytes;
258 udata->num_out *= pcm_sample_bytes; 263 udata->num_out *= pcm_sample_bytes;
259 264
265 if (new_buffer)
266 {
267 new_buffer = false;
268 pcm_play_dma_status_callback(PCM_DMAST_STARTED);
260 269
261 if (new_buffer) 270 if ((size_t)len > udata->num_out)
262 { 271 {
263 new_buffer = false; 272 int delay = pcm_data_size*250 / pcm_sampr - 1;
264 pcm_play_dma_started_callback();
265 273
266 if ((size_t)len > udata->num_out) 274 if (delay > 0)
267 { 275 {
268 int delay = pcm_data_size*250 / pcm_sampr - 1; 276 SDL_UnlockMutex(audio_lock);
269 277 SDL_Delay(delay);
270 if (delay > 0) 278 SDL_LockMutex(audio_lock);
271 { 279
272 SDL_UnlockMutex(audio_lock); 280 if (!pcm_is_playing())
273 SDL_Delay(delay); 281 break;
274 SDL_LockMutex(audio_lock);
275
276 if (!pcm_is_playing())
277 break;
278 }
279 } 282 }
280 } 283 }
281
282 pcm_data += udata->num_in;
283 pcm_data_size -= udata->num_in;
284 udata->stream += udata->num_out;
285 len -= udata->num_out;
286 } else {
287 DEBUGF("sdl_audio_callback: No Data.\n");
288 break;
289 } 284 }
285
286 pcm_data += udata->num_in;
287 pcm_data_size -= udata->num_in;
288 udata->stream += udata->num_out;
289 len -= udata->num_out;
290 } 290 }
291 291
292 SDL_UnlockMutex(audio_lock); 292 SDL_UnlockMutex(audio_lock);