blob: de65f90915d8f28df58bff10b58cfbbd989926af [file] [log] [blame]
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Nils Wallméniuse15adcd2008-05-08 18:33:41 +00008 * $Id$
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +00009 *
10 * Copyright (C) 2005 Ray Lambert
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _ABREPEAT_H_
22#define _ABREPEAT_H_
23
24#include "system.h"
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +000025
26#ifdef AB_REPEAT_ENABLE
Brandon Low8d5a6602006-01-21 23:43:57 +000027#include "audio.h"
28#include "kernel.h"
29#include <stdbool.h>
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +000030
31#define AB_MARKER_NONE 0
32
Brandon Low8d5a6602006-01-21 23:43:57 +000033#if (AB_REPEAT_ENABLE == 1)
34#include "settings.h"
35#endif
36
Jens Arnold314f3b52006-12-12 22:22:21 +000037void ab_repeat_init(void);
38#if 0 /* Currently unused */
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +000039unsigned int ab_get_A_marker(void);
40unsigned int ab_get_B_marker(void);
Jens Arnold314f3b52006-12-12 22:22:21 +000041#endif /* if 0 */
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +000042bool ab_before_A_marker(unsigned int song_position);
43bool ab_after_A_marker(unsigned int song_position);
44void ab_jump_to_A_marker(void);
45void ab_reset_markers(void);
46void ab_set_A_marker(unsigned int song_position);
47void ab_set_B_marker(unsigned int song_position);
Brandon Low8d5a6602006-01-21 23:43:57 +000048#if (CONFIG_CODEC == SWCODEC)
49void ab_end_of_track_report(void);
50#endif
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +000051#ifdef HAVE_LCD_BITMAP
Brandon Low8d5a6602006-01-21 23:43:57 +000052#include "screen_access.h"
53void ab_draw_markers(struct screen * screen, int capacity,
Dominik Riebeling08c813d2006-12-29 19:17:03 +000054 int x0, int x1, int y, int h);
Brandon Low8d5a6602006-01-21 23:43:57 +000055#endif
56
57/* These functions really need to be inlined for speed */
58extern unsigned int ab_A_marker;
59extern unsigned int ab_B_marker;
60
61static inline bool ab_A_marker_set(void)
62{
63 return ab_A_marker != AB_MARKER_NONE;
64}
65
66static inline bool ab_B_marker_set(void)
67{
68 return ab_B_marker != AB_MARKER_NONE;
69}
70
71static inline bool ab_repeat_mode_enabled(void)
72{
73#if (AB_REPEAT_ENABLE == 2)
74 return ab_A_marker_set() || ab_B_marker_set();
75#else
76 return global_settings.repeat_mode == REPEAT_AB;
77#endif
78}
79
80static inline bool ab_reached_B_marker(unsigned int song_position)
81{
82/* following is the size of the window in which we'll detect that the B marker
83was hit; it must be larger than the frequency (in milliseconds) at which this
84function is called otherwise detection of the B marker will be unreliable */
85#if (CONFIG_CODEC == SWCODEC)
86/* On swcodec, the worst case seems to be 9600kHz with 1024 samples between
87 * calls, meaning ~9 calls per second, look within 1/5 of a second */
88#define B_MARKER_DETECT_WINDOW 200
89#else
90/* we assume that this function will be called on each system tick and derive
91the window size from this with a generous margin of error (note: the number
92of ticks per second is given by HZ) */
93#define B_MARKER_DETECT_WINDOW ((1000/HZ)*10)
94#endif
95 if (ab_B_marker != AB_MARKER_NONE)
96 {
97 if ( (song_position >= ab_B_marker)
98 && (song_position <= (ab_B_marker+B_MARKER_DETECT_WINDOW)) )
99 return true;
100 }
101 return false;
102}
103
104#if (CONFIG_CODEC == SWCODEC)
105static inline void ab_position_report(unsigned long position)
106{
107 if (ab_repeat_mode_enabled())
108 {
109 if ( !(audio_status() & AUDIO_STATUS_PAUSE) &&
110 ab_reached_B_marker(position) )
111 {
112 ab_jump_to_A_marker();
113 }
114 }
115}
Linus Nielsen Feltzing0ad617c2005-08-21 23:01:12 +0000116#endif
117
118#endif
119
120#endif /* _ABREPEAT_H_ */