diff options
-rw-r--r-- | apps/pcmbuf.c | 31 | ||||
-rw-r--r-- | apps/playback.c | 15 |
2 files changed, 21 insertions, 25 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 95a423af6a..bcf971d1f8 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c | |||
@@ -85,7 +85,7 @@ volatile int pcmbuf_write_index; | |||
85 | int pcmbuf_unplayed_bytes; | 85 | int pcmbuf_unplayed_bytes; |
86 | int pcmbuf_watermark; | 86 | int pcmbuf_watermark; |
87 | void (*pcmbuf_watermark_event)(int bytes_left); | 87 | void (*pcmbuf_watermark_event)(int bytes_left); |
88 | static int last_chunksize; | 88 | //static int last_chunksize; |
89 | 89 | ||
90 | static void pcmbuf_boost(bool state) | 90 | static void pcmbuf_boost(bool state) |
91 | { | 91 | { |
@@ -110,11 +110,6 @@ int pcmbuf_num_used_buffers(void) | |||
110 | static void pcmbuf_callback(unsigned char** start, long* size) | 110 | static void pcmbuf_callback(unsigned char** start, long* size) |
111 | { | 111 | { |
112 | struct pcmbufdesc *desc = &pcmbuffers[pcmbuf_read_index]; | 112 | struct pcmbufdesc *desc = &pcmbuffers[pcmbuf_read_index]; |
113 | int sz; | ||
114 | |||
115 | pcmbuf_unplayed_bytes -= last_chunksize; | ||
116 | audiobuffer_free += last_chunksize; | ||
117 | |||
118 | 113 | ||
119 | if(desc->size == 0) | 114 | if(desc->size == 0) |
120 | { | 115 | { |
@@ -129,17 +124,15 @@ static void pcmbuf_callback(unsigned char** start, long* size) | |||
129 | 124 | ||
130 | if(pcmbuf_num_used_buffers()) | 125 | if(pcmbuf_num_used_buffers()) |
131 | { | 126 | { |
132 | /* Play max 64K at a time */ | 127 | pcmbuf_unplayed_bytes -= desc->size; |
133 | //sz = MIN(desc->size, 32768); | 128 | audiobuffer_free += desc->size; |
134 | sz = desc->size; | 129 | |
135 | *start = desc->addr; | 130 | *start = desc->addr; |
136 | *size = sz; | 131 | *size = desc->size; |
137 | 132 | ||
138 | /* Update the buffer descriptor */ | 133 | /* Update the buffer descriptor */ |
139 | desc->size -= sz; | 134 | desc->addr += desc->size; |
140 | desc->addr += sz; | 135 | desc->size = 0; |
141 | |||
142 | last_chunksize = sz; | ||
143 | } | 136 | } |
144 | else | 137 | else |
145 | { | 138 | { |
@@ -243,7 +236,7 @@ bool pcmbuf_crossfade_init(void) | |||
243 | void pcmbuf_play_stop(void) | 236 | void pcmbuf_play_stop(void) |
244 | { | 237 | { |
245 | pcm_play_stop(); | 238 | pcm_play_stop(); |
246 | last_chunksize = 0; | 239 | //last_chunksize = 0; |
247 | pcmbuf_unplayed_bytes = 0; | 240 | pcmbuf_unplayed_bytes = 0; |
248 | pcmbuf_read_index = 0; | 241 | pcmbuf_read_index = 0; |
249 | pcmbuf_write_index = 0; | 242 | pcmbuf_write_index = 0; |
@@ -278,6 +271,7 @@ void pcmbuf_flush_audio(void) | |||
278 | return ; | 271 | return ; |
279 | } | 272 | } |
280 | 273 | ||
274 | pcmbuf_boost(true); | ||
281 | crossfade_mode = CFM_FLUSH; | 275 | crossfade_mode = CFM_FLUSH; |
282 | crossfade_init = true; | 276 | crossfade_init = true; |
283 | } | 277 | } |
@@ -296,7 +290,8 @@ void pcmbuf_flush_fillpos(void) | |||
296 | /* This is a fatal error situation that should never happen. */ | 290 | /* This is a fatal error situation that should never happen. */ |
297 | if (!pcm_is_playing()) { | 291 | if (!pcm_is_playing()) { |
298 | logf("pcm_flush_fillpos error"); | 292 | logf("pcm_flush_fillpos error"); |
299 | break ; | 293 | pcm_play_data(pcmbuf_callback); |
294 | return ; | ||
300 | } | 295 | } |
301 | } | 296 | } |
302 | pcmbuf_event_handler = NULL; | 297 | pcmbuf_event_handler = NULL; |
@@ -320,7 +315,7 @@ static void crossfade_start(void) | |||
320 | } | 315 | } |
321 | 316 | ||
322 | logf("crossfade_start"); | 317 | logf("crossfade_start"); |
323 | pcmbuf_flush_fillpos(); | 318 | audiobuffer_fillpos = 0; |
324 | pcmbuf_boost(true); | 319 | pcmbuf_boost(true); |
325 | crossfade_active = true; | 320 | crossfade_active = true; |
326 | crossfade_pos = audiobuffer_pos; | 321 | crossfade_pos = audiobuffer_pos; |
@@ -384,7 +379,7 @@ static bool prepare_insert(long length) | |||
384 | pcmbuf_boost(false); | 379 | pcmbuf_boost(false); |
385 | return false; | 380 | return false; |
386 | } | 381 | } |
387 | 382 | ||
388 | if (!pcm_is_playing()) { | 383 | if (!pcm_is_playing()) { |
389 | pcmbuf_boost(true); | 384 | pcmbuf_boost(true); |
390 | crossfade_active = false; | 385 | crossfade_active = false; |
diff --git a/apps/playback.c b/apps/playback.c index 0b67615700..63bf4dbc4f 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -392,7 +392,7 @@ void codec_advance_buffer_callback(long amount) | |||
392 | if (amount > cur_ti->available + cur_ti->filerem) | 392 | if (amount > cur_ti->available + cur_ti->filerem) |
393 | amount = cur_ti->available + cur_ti->filerem; | 393 | amount = cur_ti->available + cur_ti->filerem; |
394 | 394 | ||
395 | if (amount > cur_ti->available) { | 395 | if (amount > cur_ti->available && !filling) { |
396 | if (!rebuffer_and_seek(ci.curpos + amount)) | 396 | if (!rebuffer_and_seek(ci.curpos + amount)) |
397 | ci.stop_codec = true; | 397 | ci.stop_codec = true; |
398 | return ; | 398 | return ; |
@@ -1346,16 +1346,16 @@ static void initiate_track_change(int peek_index) | |||
1346 | if (!playlist_check(peek_index)) | 1346 | if (!playlist_check(peek_index)) |
1347 | return ; | 1347 | return ; |
1348 | 1348 | ||
1349 | new_track = peek_index; | ||
1350 | ci.reload_codec = true; | ||
1351 | |||
1352 | /* Detect if disk is spinning.. */ | 1349 | /* Detect if disk is spinning.. */ |
1353 | if (filling) { | 1350 | if (filling) { |
1354 | ci.stop_codec = true; | 1351 | ci.stop_codec = true; |
1355 | playlist_next(peek_index); | 1352 | playlist_next(peek_index); |
1356 | queue_post(&audio_queue, AUDIO_PLAY, 0); | 1353 | queue_post(&audio_queue, AUDIO_PLAY, 0); |
1357 | } else { | 1354 | } else { |
1358 | pcmbuf_crossfade_init(); | 1355 | new_track = peek_index; |
1356 | ci.reload_codec = true; | ||
1357 | if (!pcmbuf_is_crossfade_enabled()) | ||
1358 | pcmbuf_flush_audio(); | ||
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | codec_track_changed(); | 1361 | codec_track_changed(); |
@@ -1384,8 +1384,9 @@ void audio_thread(void) | |||
1384 | ci.stop_codec = true; | 1384 | ci.stop_codec = true; |
1385 | ci.reload_codec = false; | 1385 | ci.reload_codec = false; |
1386 | ci.seek_time = 0; | 1386 | ci.seek_time = 0; |
1387 | if (!pcmbuf_is_crossfade_active()) | 1387 | pcmbuf_crossfade_init(); |
1388 | pcmbuf_crossfade_init(); | 1388 | while (codec_loaded) |
1389 | yield(); | ||
1389 | audio_play_start((int)ev.data); | 1390 | audio_play_start((int)ev.data); |
1390 | playlist_update_resume_info(audio_current_track()); | 1391 | playlist_update_resume_info(audio_current_track()); |
1391 | break ; | 1392 | break ; |