1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Ray Lambert
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
24 #ifdef AB_REPEAT_ENABLE
29 #define AB_MARKER_NONE 0
31 #if (AB_REPEAT_ENABLE == 1)
35 void ab_repeat_init(void);
36 unsigned int ab_get_A_marker(void);
37 unsigned int ab_get_B_marker(void);
38 bool ab_before_A_marker(unsigned int song_position
);
39 bool ab_after_A_marker(unsigned int song_position
);
40 void ab_jump_to_A_marker(void);
41 void ab_reset_markers(void);
42 void ab_set_A_marker(unsigned int song_position
);
43 void ab_set_B_marker(unsigned int song_position
);
44 #if (CONFIG_CODEC == SWCODEC)
45 void ab_end_of_track_report(void);
47 #ifdef HAVE_LCD_BITMAP
48 #include "screen_access.h"
49 void ab_draw_markers(struct screen
* screen
, int capacity
,
53 /* These functions really need to be inlined for speed */
54 extern unsigned int ab_A_marker
;
55 extern unsigned int ab_B_marker
;
57 static inline bool ab_A_marker_set(void)
59 return ab_A_marker
!= AB_MARKER_NONE
;
62 static inline bool ab_B_marker_set(void)
64 return ab_B_marker
!= AB_MARKER_NONE
;
67 static inline bool ab_repeat_mode_enabled(void)
69 #if (AB_REPEAT_ENABLE == 2)
70 return ab_A_marker_set() || ab_B_marker_set();
72 return global_settings
.repeat_mode
== REPEAT_AB
;
76 static inline bool ab_reached_B_marker(unsigned int song_position
)
78 /* following is the size of the window in which we'll detect that the B marker
79 was hit; it must be larger than the frequency (in milliseconds) at which this
80 function is called otherwise detection of the B marker will be unreliable */
81 #if (CONFIG_CODEC == SWCODEC)
82 /* On swcodec, the worst case seems to be 9600kHz with 1024 samples between
83 * calls, meaning ~9 calls per second, look within 1/5 of a second */
84 #define B_MARKER_DETECT_WINDOW 200
86 /* we assume that this function will be called on each system tick and derive
87 the window size from this with a generous margin of error (note: the number
88 of ticks per second is given by HZ) */
89 #define B_MARKER_DETECT_WINDOW ((1000/HZ)*10)
91 if (ab_B_marker
!= AB_MARKER_NONE
)
93 if ( (song_position
>= ab_B_marker
)
94 && (song_position
<= (ab_B_marker
+B_MARKER_DETECT_WINDOW
)) )
100 #if (CONFIG_CODEC == SWCODEC)
101 static inline void ab_position_report(unsigned long position
)
103 if (ab_repeat_mode_enabled())
105 if ( !(audio_status() & AUDIO_STATUS_PAUSE
) &&
106 ab_reached_B_marker(position
) )
108 ab_jump_to_A_marker();
116 #endif /* _ABREPEAT_H_ */