2005-08-21 23:01:12 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2008-05-08 18:33:41 +00:00
|
|
|
* $Id$
|
2005-08-21 23:01:12 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Ray Lambert
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-08-21 23:01:12 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _ABREPEAT_H_
|
|
|
|
#define _ABREPEAT_H_
|
|
|
|
|
|
|
|
#ifdef AB_REPEAT_ENABLE
|
2006-01-21 23:43:57 +00:00
|
|
|
#include <stdbool.h>
|
2009-03-08 16:10:40 +00:00
|
|
|
#include "audio.h"
|
|
|
|
#include "kernel.h" /* needed for HZ */
|
2005-08-21 23:01:12 +00:00
|
|
|
|
|
|
|
#define AB_MARKER_NONE 0
|
|
|
|
|
2006-01-21 23:43:57 +00:00
|
|
|
#include "settings.h"
|
|
|
|
|
2011-01-18 16:11:33 +00:00
|
|
|
void ab_repeat_init(void);
|
2005-08-21 23:01:12 +00:00
|
|
|
bool ab_before_A_marker(unsigned int song_position);
|
|
|
|
bool ab_after_A_marker(unsigned int song_position);
|
|
|
|
void ab_jump_to_A_marker(void);
|
|
|
|
void ab_reset_markers(void);
|
|
|
|
void ab_set_A_marker(unsigned int song_position);
|
|
|
|
void ab_set_B_marker(unsigned int song_position);
|
2013-12-13 09:24:15 +00:00
|
|
|
/* These return whether the marker are actually set.
|
|
|
|
* The actual positions are returned via output parameter */
|
|
|
|
bool ab_get_A_marker(unsigned int *song_position);
|
|
|
|
bool ab_get_B_marker(unsigned int *song_position);
|
2006-01-21 23:43:57 +00:00
|
|
|
void ab_end_of_track_report(void);
|
|
|
|
|
|
|
|
/* These functions really need to be inlined for speed */
|
|
|
|
extern unsigned int ab_A_marker;
|
|
|
|
extern unsigned int ab_B_marker;
|
|
|
|
|
|
|
|
static inline bool ab_repeat_mode_enabled(void)
|
|
|
|
{
|
|
|
|
return global_settings.repeat_mode == REPEAT_AB;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ab_reached_B_marker(unsigned int song_position)
|
|
|
|
{
|
|
|
|
/* following is the size of the window in which we'll detect that the B marker
|
|
|
|
was hit; it must be larger than the frequency (in milliseconds) at which this
|
|
|
|
function is called otherwise detection of the B marker will be unreliable */
|
|
|
|
/* On swcodec, the worst case seems to be 9600kHz with 1024 samples between
|
|
|
|
* calls, meaning ~9 calls per second, look within 1/5 of a second */
|
|
|
|
#define B_MARKER_DETECT_WINDOW 200
|
|
|
|
if (ab_B_marker != AB_MARKER_NONE)
|
|
|
|
{
|
|
|
|
if ( (song_position >= ab_B_marker)
|
|
|
|
&& (song_position <= (ab_B_marker+B_MARKER_DETECT_WINDOW)) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ab_position_report(unsigned long position)
|
|
|
|
{
|
|
|
|
if (ab_repeat_mode_enabled())
|
|
|
|
{
|
|
|
|
if ( !(audio_status() & AUDIO_STATUS_PAUSE) &&
|
|
|
|
ab_reached_B_marker(position) )
|
|
|
|
{
|
|
|
|
ab_jump_to_A_marker();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-21 23:01:12 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _ABREPEAT_H_ */
|