diff options
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r-- | apps/pcmbuf.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index f1fee37452..6cbd4556b6 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <string.h> | 36 | #include <string.h> |
37 | #include "settings.h" | 37 | #include "settings.h" |
38 | #include "audio.h" | 38 | #include "audio.h" |
39 | #include "voice_thread.h" | ||
39 | #include "dsp.h" | 40 | #include "dsp.h" |
40 | 41 | ||
41 | #define PCMBUF_TARGET_CHUNK 32768 /* This is the target fill size of chunks | 42 | #define PCMBUF_TARGET_CHUNK 32768 /* This is the target fill size of chunks |
@@ -116,7 +117,7 @@ static struct chunkdesc *mix_chunk IDATA_ATTR; | |||
116 | static size_t pcmbuf_mix_sample IDATA_ATTR; | 117 | static size_t pcmbuf_mix_sample IDATA_ATTR; |
117 | 118 | ||
118 | static bool low_latency_mode = false; | 119 | static bool low_latency_mode = false; |
119 | static bool pcmbuf_flush; | 120 | static bool flush_pcmbuf; |
120 | 121 | ||
121 | #ifdef HAVE_PRIORITY_SCHEDULING | 122 | #ifdef HAVE_PRIORITY_SCHEDULING |
122 | static int codec_thread_priority = PRIORITY_PLAYBACK; | 123 | static int codec_thread_priority = PRIORITY_PLAYBACK; |
@@ -183,7 +184,7 @@ static bool show_desc(char *caller) | |||
183 | 184 | ||
184 | /* Commit PCM data */ | 185 | /* Commit PCM data */ |
185 | 186 | ||
186 | /* This is really just part of pcmbuf_flush_fillpos, but is easier to keep | 187 | /* This is really just part of commit_chunk, but is easier to keep |
187 | * in a separate function for the moment */ | 188 | * in a separate function for the moment */ |
188 | static inline void pcmbuf_add_chunk(void) | 189 | static inline void pcmbuf_add_chunk(void) |
189 | { | 190 | { |
@@ -198,7 +199,7 @@ static inline void pcmbuf_add_chunk(void) | |||
198 | pcmbuf_current->link = NULL; | 199 | pcmbuf_current->link = NULL; |
199 | end_of_track = false; /* This is single use only */ | 200 | end_of_track = false; /* This is single use only */ |
200 | if (read_chunk != NULL) { | 201 | if (read_chunk != NULL) { |
201 | if (pcmbuf_flush) | 202 | if (flush_pcmbuf) |
202 | { | 203 | { |
203 | write_end_chunk->link = read_chunk->link; | 204 | write_end_chunk->link = read_chunk->link; |
204 | read_chunk->link = pcmbuf_current; | 205 | read_chunk->link = pcmbuf_current; |
@@ -207,7 +208,7 @@ static inline void pcmbuf_add_chunk(void) | |||
207 | write_end_chunk = write_end_chunk->link; | 208 | write_end_chunk = write_end_chunk->link; |
208 | pcmbuf_unplayed_bytes -= write_end_chunk->size; | 209 | pcmbuf_unplayed_bytes -= write_end_chunk->size; |
209 | } | 210 | } |
210 | pcmbuf_flush = false; | 211 | flush_pcmbuf = false; |
211 | } | 212 | } |
212 | /* If there is already a read buffer setup, add to it */ | 213 | /* If there is already a read buffer setup, add to it */ |
213 | else | 214 | else |
@@ -233,14 +234,14 @@ static inline void pcmbuf_add_chunk(void) | |||
233 | /** | 234 | /** |
234 | * Commit samples waiting to the pcm buffer. | 235 | * Commit samples waiting to the pcm buffer. |
235 | */ | 236 | */ |
236 | static bool pcmbuf_flush_fillpos(void) | 237 | static bool commit_chunk(void) |
237 | { | 238 | { |
238 | if (pcmbuffer_fillpos) { | 239 | if (pcmbuffer_fillpos) { |
239 | /* Never use the last buffer descriptor */ | 240 | /* Never use the last buffer descriptor */ |
240 | while (write_chunk == write_end_chunk) { | 241 | while (write_chunk == write_end_chunk) { |
241 | /* If this happens, something is being stupid */ | 242 | /* If this happens, something is being stupid */ |
242 | if (!pcm_is_playing()) { | 243 | if (!pcm_is_playing()) { |
243 | logf("pcmbuf_flush_fillpos error"); | 244 | logf("commit_chunk error"); |
244 | pcmbuf_play_start(); | 245 | pcmbuf_play_start(); |
245 | } | 246 | } |
246 | /* Let approximately one chunk of data playback */ | 247 | /* Let approximately one chunk of data playback */ |
@@ -366,16 +367,13 @@ void *pcmbuf_request_buffer(int *count) | |||
366 | else | 367 | else |
367 | { | 368 | { |
368 | /* Flush and wrap the buffer */ | 369 | /* Flush and wrap the buffer */ |
369 | pcmbuf_flush_fillpos(); | 370 | commit_chunk(); |
370 | pcmbuffer_pos = 0; | 371 | pcmbuffer_pos = 0; |
371 | return &pcmbuffer[0]; | 372 | return &pcmbuffer[0]; |
372 | } | 373 | } |
373 | } | 374 | } |
374 | else | ||
375 | { | ||
376 | return NULL; | ||
377 | } | ||
378 | } | 375 | } |
376 | return NULL; | ||
379 | } | 377 | } |
380 | 378 | ||
381 | void pcmbuf_write_complete(int count) | 379 | void pcmbuf_write_complete(int count) |
@@ -394,7 +392,7 @@ void pcmbuf_write_complete(int count) | |||
394 | pcmbuffer_fillpos += length; | 392 | pcmbuffer_fillpos += length; |
395 | 393 | ||
396 | if (NEED_FLUSH(pcmbuffer_pos + pcmbuffer_fillpos)) | 394 | if (NEED_FLUSH(pcmbuffer_pos + pcmbuffer_fillpos)) |
397 | pcmbuf_flush_fillpos(); | 395 | commit_chunk(); |
398 | } | 396 | } |
399 | } | 397 | } |
400 | 398 | ||
@@ -507,7 +505,7 @@ static void pcmbuf_pcm_callback(unsigned char** start, size_t* size) | |||
507 | if (pcmbuffer_fillpos && !read_chunk) | 505 | if (pcmbuffer_fillpos && !read_chunk) |
508 | { | 506 | { |
509 | logf("pcmbuf_pcm_callback: commit last samples"); | 507 | logf("pcmbuf_pcm_callback: commit last samples"); |
510 | pcmbuf_flush_fillpos(); | 508 | commit_chunk(); |
511 | } | 509 | } |
512 | } | 510 | } |
513 | 511 | ||
@@ -565,7 +563,7 @@ void pcmbuf_play_stop(void) | |||
565 | pcmbuffer_fillpos = 0; | 563 | pcmbuffer_fillpos = 0; |
566 | crossfade_init = false; | 564 | crossfade_init = false; |
567 | crossfade_active = false; | 565 | crossfade_active = false; |
568 | pcmbuf_flush = false; | 566 | flush_pcmbuf = false; |
569 | DISPLAY_DESC("play_stop"); | 567 | DISPLAY_DESC("play_stop"); |
570 | 568 | ||
571 | /* Can unboost the codec thread here no matter who's calling */ | 569 | /* Can unboost the codec thread here no matter who's calling */ |
@@ -741,7 +739,7 @@ static void crossfade_start(void) | |||
741 | } | 739 | } |
742 | 740 | ||
743 | logf("crossfade_start"); | 741 | logf("crossfade_start"); |
744 | pcmbuf_flush_fillpos(); | 742 | commit_chunk(); |
745 | crossfade_active = true; | 743 | crossfade_active = true; |
746 | 744 | ||
747 | /* Initialize the crossfade buffer size to all of the buffered data that | 745 | /* Initialize the crossfade buffer size to all of the buffered data that |
@@ -887,7 +885,7 @@ static void flush_crossfade(char *buf, size_t length) | |||
887 | size_t pcmbuffer_index = pcmbuffer_pos + pcmbuffer_fillpos; | 885 | size_t pcmbuffer_index = pcmbuffer_pos + pcmbuffer_fillpos; |
888 | if (NEED_FLUSH(pcmbuffer_index)) | 886 | if (NEED_FLUSH(pcmbuffer_index)) |
889 | { | 887 | { |
890 | pcmbuf_flush_fillpos(); | 888 | commit_chunk(); |
891 | pcmbuffer_index = pcmbuffer_pos + pcmbuffer_fillpos; | 889 | pcmbuffer_index = pcmbuffer_pos + pcmbuffer_fillpos; |
892 | } | 890 | } |
893 | size_t copy_n = MIN(length, pcmbuf_size - pcmbuffer_index); | 891 | size_t copy_n = MIN(length, pcmbuf_size - pcmbuffer_index); |
@@ -914,8 +912,8 @@ static bool pcmbuf_crossfade_init(bool manual_skip) | |||
914 | /* Not enough data, or crossfade disabled, flush the old data instead */ | 912 | /* Not enough data, or crossfade disabled, flush the old data instead */ |
915 | if (LOW_DATA(2) || !pcmbuf_is_crossfade_enabled() || low_latency_mode) | 913 | if (LOW_DATA(2) || !pcmbuf_is_crossfade_enabled() || low_latency_mode) |
916 | { | 914 | { |
917 | pcmbuf_flush_fillpos(); | 915 | commit_chunk(); |
918 | pcmbuf_flush = true; | 916 | flush_pcmbuf = true; |
919 | return false; | 917 | return false; |
920 | } | 918 | } |
921 | 919 | ||