summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-19 16:37:52 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-19 16:37:52 +0000
commitd3b8245ca87177af9454e823acb6f57b47e196ca (patch)
treeebc7b708cb1b7e69e99d2969a1ec24111c35f1e9
parent3947b0c6328e446fd70641885a7035614cfc90e5 (diff)
downloadrockbox-d3b8245ca87177af9454e823acb6f57b47e196ca.zip
rockbox-d3b8245ca87177af9454e823acb6f57b47e196ca.tar.gz
rockbox-d3b8245ca87177af9454e823acb6f57b47e196ca.tar.bz2
rockbox-d3b8245ca87177af9454e823acb6f57b47e196ca.tar.xz
Second part of FS#8104 by Bertrik Sikken: Simplification of audio_track_count, audio_have_tracks and audio_have_free_tracks. This hopefully won't affect anything, but the semantics of the functions have changed slightly.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15693 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c2
-rw-r--r--apps/playback.c28
2 files changed, 9 insertions, 21 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index f343ce6..e3f576d 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -344,7 +344,7 @@ static bool dbg_buffering_thread(void)
snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
lcd_puts(0, line++, buf);
- snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count()-1);
+ snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
lcd_puts(0, line++, buf);
snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
diff --git a/apps/playback.c b/apps/playback.c
index 1ad6ce6..e136579 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -1422,32 +1422,20 @@ static void codec_thread(void)
static bool audio_have_tracks(void)
{
- return track_ridx != track_widx || CUR_TI->filesize;
+ return (audio_track_count() != 0);
}
-static bool audio_have_free_tracks(void)
+static int audio_free_track_count(void)
{
- if (track_widx < track_ridx)
- return track_widx + 1 < track_ridx;
- else if (track_ridx == 0)
- return track_widx < MAX_TRACK - 1;
-
- return true;
+ /* Used tracks + free tracks adds up to MAX_TRACK - 1 */
+ return MAX_TRACK - 1 - audio_track_count();
}
int audio_track_count(void)
{
- if (audio_have_tracks())
- {
- int relative_track_widx = track_widx;
-
- if (track_ridx > track_widx)
- relative_track_widx += MAX_TRACK;
-
- return relative_track_widx - track_ridx + 1;
- }
-
- return 0;
+ /* Calculate difference from track_ridx to track_widx
+ * taking into account a possible wrap-around. */
+ return (MAX_TRACK + track_widx - track_ridx) & MAX_TRACK_MASK;
}
long audio_filebufused(void)
@@ -1659,7 +1647,7 @@ static bool audio_load_track(int offset, bool start_play)
/* Stop buffer filling if there is no free track entries.
Don't fill up the last track entry (we wan't to store next track
metadata there). */
- if (!audio_have_free_tracks())
+ if (!audio_free_track_count())
{
logf("No free tracks");
return false;