Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Nils Wallménius | e15adcd | 2008-05-08 18:33:41 +0000 | [diff] [blame] | 8 | * $Id$ |
Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 9 | * |
| 10 | * Copyright (C) 2005 Ray Lambert |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 16 | * |
| 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 Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 25 | |
| 26 | #ifdef AB_REPEAT_ENABLE |
Brandon Low | 8d5a660 | 2006-01-21 23:43:57 +0000 | [diff] [blame] | 27 | #include "audio.h" |
| 28 | #include "kernel.h" |
| 29 | #include <stdbool.h> |
Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 30 | |
| 31 | #define AB_MARKER_NONE 0 |
| 32 | |
Brandon Low | 8d5a660 | 2006-01-21 23:43:57 +0000 | [diff] [blame] | 33 | #if (AB_REPEAT_ENABLE == 1) |
| 34 | #include "settings.h" |
| 35 | #endif |
| 36 | |
Jens Arnold | 314f3b5 | 2006-12-12 22:22:21 +0000 | [diff] [blame] | 37 | void ab_repeat_init(void); |
| 38 | #if 0 /* Currently unused */ |
Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 39 | unsigned int ab_get_A_marker(void); |
| 40 | unsigned int ab_get_B_marker(void); |
Jens Arnold | 314f3b5 | 2006-12-12 22:22:21 +0000 | [diff] [blame] | 41 | #endif /* if 0 */ |
Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 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); |
Brandon Low | 8d5a660 | 2006-01-21 23:43:57 +0000 | [diff] [blame] | 48 | #if (CONFIG_CODEC == SWCODEC) |
| 49 | void ab_end_of_track_report(void); |
| 50 | #endif |
Linus Nielsen Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 51 | #ifdef HAVE_LCD_BITMAP |
Brandon Low | 8d5a660 | 2006-01-21 23:43:57 +0000 | [diff] [blame] | 52 | #include "screen_access.h" |
| 53 | void ab_draw_markers(struct screen * screen, int capacity, |
Dominik Riebeling | 08c813d | 2006-12-29 19:17:03 +0000 | [diff] [blame] | 54 | int x0, int x1, int y, int h); |
Brandon Low | 8d5a660 | 2006-01-21 23:43:57 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
| 57 | /* These functions really need to be inlined for speed */ |
| 58 | extern unsigned int ab_A_marker; |
| 59 | extern unsigned int ab_B_marker; |
| 60 | |
| 61 | static inline bool ab_A_marker_set(void) |
| 62 | { |
| 63 | return ab_A_marker != AB_MARKER_NONE; |
| 64 | } |
| 65 | |
| 66 | static inline bool ab_B_marker_set(void) |
| 67 | { |
| 68 | return ab_B_marker != AB_MARKER_NONE; |
| 69 | } |
| 70 | |
| 71 | static 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 | |
| 80 | static 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 |
| 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) |
| 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) |
| 105 | static 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 Feltzing | 0ad617c | 2005-08-21 23:01:12 +0000 | [diff] [blame] | 116 | #endif |
| 117 | |
| 118 | #endif |
| 119 | |
| 120 | #endif /* _ABREPEAT_H_ */ |