Colour targets: Revert an optimisation from almost 18 months ago that actually turned...
[Rockbox.git] / apps / abrepeat.h
blobde65f90915d8f28df58bff10b58cfbbd989926af
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Ray Lambert
12 * 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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _ABREPEAT_H_
22 #define _ABREPEAT_H_
24 #include "system.h"
26 #ifdef AB_REPEAT_ENABLE
27 #include "audio.h"
28 #include "kernel.h"
29 #include <stdbool.h>
31 #define AB_MARKER_NONE 0
33 #if (AB_REPEAT_ENABLE == 1)
34 #include "settings.h"
35 #endif
37 void ab_repeat_init(void);
38 #if 0 /* Currently unused */
39 unsigned int ab_get_A_marker(void);
40 unsigned int ab_get_B_marker(void);
41 #endif /* if 0 */
42 bool ab_before_A_marker(unsigned int song_position);
43 bool ab_after_A_marker(unsigned int song_position);
44 void ab_jump_to_A_marker(void);
45 void ab_reset_markers(void);
46 void ab_set_A_marker(unsigned int song_position);
47 void ab_set_B_marker(unsigned int song_position);
48 #if (CONFIG_CODEC == SWCODEC)
49 void ab_end_of_track_report(void);
50 #endif
51 #ifdef HAVE_LCD_BITMAP
52 #include "screen_access.h"
53 void ab_draw_markers(struct screen * screen, int capacity,
54 int x0, int x1, int y, int h);
55 #endif
57 /* These functions really need to be inlined for speed */
58 extern unsigned int ab_A_marker;
59 extern unsigned int ab_B_marker;
61 static inline bool ab_A_marker_set(void)
63 return ab_A_marker != AB_MARKER_NONE;
66 static inline bool ab_B_marker_set(void)
68 return ab_B_marker != AB_MARKER_NONE;
71 static inline bool ab_repeat_mode_enabled(void)
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
80 static inline bool ab_reached_B_marker(unsigned int song_position)
82 /* following is the size of the window in which we'll detect that the B marker
83 was hit; it must be larger than the frequency (in milliseconds) at which this
84 function 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
91 the window size from this with a generous margin of error (note: the number
92 of 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)
97 if ( (song_position >= ab_B_marker)
98 && (song_position <= (ab_B_marker+B_MARKER_DETECT_WINDOW)) )
99 return true;
101 return false;
104 #if (CONFIG_CODEC == SWCODEC)
105 static inline void ab_position_report(unsigned long position)
107 if (ab_repeat_mode_enabled())
109 if ( !(audio_status() & AUDIO_STATUS_PAUSE) &&
110 ab_reached_B_marker(position) )
112 ab_jump_to_A_marker();
116 #endif
118 #endif
120 #endif /* _ABREPEAT_H_ */