Refacturate arm version of libmad's synthesis filter. Only two asm macros left, renam...
[kugel-rb.git] / apps / abrepeat.h
blob3c9853f2c5c3029792bda3bd58c7c69e72cdb456
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 #ifdef AB_REPEAT_ENABLE
25 #include <stdbool.h>
26 #include "audio.h"
27 #include "kernel.h" /* needed for HZ */
29 #define AB_MARKER_NONE 0
31 #if (AB_REPEAT_ENABLE == 1)
32 #include "settings.h"
33 #endif
35 void ab_repeat_init(void);
36 #if 0 /* Currently unused */
37 unsigned int ab_get_A_marker(void);
38 unsigned int ab_get_B_marker(void);
39 #endif /* if 0 */
40 bool ab_before_A_marker(unsigned int song_position);
41 bool ab_after_A_marker(unsigned int song_position);
42 void ab_jump_to_A_marker(void);
43 void ab_reset_markers(void);
44 void ab_set_A_marker(unsigned int song_position);
45 void ab_set_B_marker(unsigned int song_position);
46 #if (CONFIG_CODEC == SWCODEC)
47 void ab_end_of_track_report(void);
48 #endif
49 #ifdef HAVE_LCD_BITMAP
50 #include "screen_access.h"
51 void ab_draw_markers(struct screen * screen, int capacity,
52 int x, int y, int w, int h);
53 #endif
55 /* These functions really need to be inlined for speed */
56 extern unsigned int ab_A_marker;
57 extern unsigned int ab_B_marker;
59 static inline bool ab_A_marker_set(void)
61 return ab_A_marker != AB_MARKER_NONE;
64 static inline bool ab_B_marker_set(void)
66 return ab_B_marker != AB_MARKER_NONE;
69 static inline bool ab_repeat_mode_enabled(void)
71 #if (AB_REPEAT_ENABLE == 2)
72 return ab_A_marker_set() || ab_B_marker_set();
73 #else
74 return global_settings.repeat_mode == REPEAT_AB;
75 #endif
78 static inline bool ab_reached_B_marker(unsigned int song_position)
80 /* following is the size of the window in which we'll detect that the B marker
81 was hit; it must be larger than the frequency (in milliseconds) at which this
82 function is called otherwise detection of the B marker will be unreliable */
83 #if (CONFIG_CODEC == SWCODEC)
84 /* On swcodec, the worst case seems to be 9600kHz with 1024 samples between
85 * calls, meaning ~9 calls per second, look within 1/5 of a second */
86 #define B_MARKER_DETECT_WINDOW 200
87 #else
88 /* we assume that this function will be called on each system tick and derive
89 the window size from this with a generous margin of error (note: the number
90 of ticks per second is given by HZ) */
91 #define B_MARKER_DETECT_WINDOW ((1000/HZ)*10)
92 #endif
93 if (ab_B_marker != AB_MARKER_NONE)
95 if ( (song_position >= ab_B_marker)
96 && (song_position <= (ab_B_marker+B_MARKER_DETECT_WINDOW)) )
97 return true;
99 return false;
102 #if (CONFIG_CODEC == SWCODEC)
103 static inline void ab_position_report(unsigned long position)
105 if (ab_repeat_mode_enabled())
107 if ( !(audio_status() & AUDIO_STATUS_PAUSE) &&
108 ab_reached_B_marker(position) )
110 ab_jump_to_A_marker();
114 #endif
116 #endif
118 #endif /* _ABREPEAT_H_ */