From e8eefe98bfd3768a9f3962bc71f0ee0431bae8b1 Mon Sep 17 00:00:00 2001 From: Jeffrey Goode Date: Sun, 1 Nov 2009 19:39:23 +0000 Subject: Code cleanup in codec_thread, playback and pcmbuf; more elegant solution to leftover samples git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23471 a1c6a512-1295-4272-9138-f99709370657 --- apps/pcmbuf.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'apps/pcmbuf.c') diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 4a338aa900..3ec0c114da 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c @@ -135,12 +135,13 @@ static void pcmbuf_under_watermark(bool under); static bool pcmbuf_flush_fillpos(void); #define CALL_IF_EXISTS(function, args...) if (function) function(args) -/* This function has 2 major logical parts (separated by brackets both for +/* This function has 3 major logical parts (separated by brackets both for * readability and variable scoping). The first part performs the - * operastions related to finishing off the last buffer we fed to the DMA. - * The second part performs the operations involved in sending a new buffer - * to the DMA. Finally the function checks the status of the buffer and - * boosts if necessary */ + * operations related to finishing off the last buffer we fed to the DMA. + * The second part detects the end of playlist condition when the pcm + * buffer is empty except for uncommitted samples. Then they are committed. + * The third part performs the operations involved in sending a new buffer + * to the DMA. */ static void pcmbuf_callback(unsigned char** start, size_t* size) ICODE_ATTR; static void pcmbuf_callback(unsigned char** start, size_t* size) { @@ -164,6 +165,15 @@ static void pcmbuf_callback(unsigned char** start, size_t* size) if (pcmbuf_current == crossfade_chunk) crossfade_chunk = pcmbuf_read; } + + { + /* Commit last samples at end of playlist */ + if (audiobuffer_fillpos && !pcmbuf_read) + { + logf("pcmbuf callback: commit last samples"); + pcmbuf_flush_fillpos(); + } + } { /* Send the new buffer to the pcm */ @@ -1109,11 +1119,3 @@ bool pcmbuf_is_crossfade_enabled(void) return crossfade_enabled; } - -/** PLAY LAST REMAINING SAMPLES AT END OF PLAYBACK - * Commit any remaining samples in the PCM buffer for playback. */ -void pcmbuf_play_remainder(void) -{ - if (audiobuffer_fillpos) - pcmbuf_flush_fillpos(); -} -- cgit v1.2.3