A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 113 lines 3.8 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2005 Ray Lambert 11 * 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. 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#include <stdbool.h> 24 25#ifndef AB_REPEAT_ENABLE /* Dummy functions */ 26static inline bool ab_repeat_mode_enabled(void) 27{ 28 return false; 29} 30static inline bool ab_bool_dummy_marker(unsigned int song_position) 31{ 32 (void) song_position; 33 return false; 34} 35static inline void ab_void_dummy_marker(unsigned int song_position) 36{ 37 (void) song_position; 38} 39static inline void ab_dummy_voidfn(void){} 40 41#define ab_before_A_marker ab_bool_dummy_marker 42#define ab_after_A_marker ab_bool_dummy_marker 43#define ab_jump_to_A_marker ab_dummy_voidfn 44#define ab_reset_markers ab_dummy_voidfn 45#define ab_set_A_marker ab_void_dummy_marker 46#define ab_set_B_marker ab_void_dummy_marker 47#define ab_get_A_marker ab_bool_dummy_marker 48#define ab_get_B_marker ab_bool_dummy_marker 49#define ab_end_of_track_report ab_dummy_voidfn 50#define ab_reached_B_marker ab_bool_dummy_marker 51#define ab_position_report ab_void_dummy_marker 52 53#else /*def AB_REPEAT_ENABLE*/ 54#include "audio.h" 55#include "kernel.h" /* needed for HZ */ 56 57#define AB_MARKER_NONE 0 58 59#include "settings.h" 60 61bool ab_before_A_marker(unsigned int song_position); 62bool ab_after_A_marker(unsigned int song_position); 63void ab_jump_to_A_marker(void); 64void ab_reset_markers(void); 65void ab_set_A_marker(unsigned int song_position); 66void ab_set_B_marker(unsigned int song_position); 67/* These return whether the marker are actually set. 68 * The actual positions are returned via output parameter */ 69bool ab_get_A_marker(unsigned int *song_position); 70bool ab_get_B_marker(unsigned int *song_position); 71void ab_end_of_track_report(void); 72 73/* These functions really need to be inlined for speed */ 74extern unsigned int ab_A_marker; 75extern unsigned int ab_B_marker; 76 77static inline bool ab_repeat_mode_enabled(void) 78{ 79 return global_settings.repeat_mode == REPEAT_AB; 80} 81 82static inline bool ab_reached_B_marker(unsigned int song_position) 83{ 84/* following is the size of the window in which we'll detect that the B marker 85was hit; it must be larger than the frequency (in milliseconds) at which this 86function is called otherwise detection of the B marker will be unreliable */ 87/* On swcodec, the worst case seems to be 9600kHz with 1024 samples between 88 * calls, meaning ~9 calls per second, look within 1/5 of a second */ 89#define B_MARKER_DETECT_WINDOW 200 90 if (ab_B_marker != AB_MARKER_NONE) 91 { 92 if ( (song_position >= ab_B_marker) 93 && (song_position <= (ab_B_marker+B_MARKER_DETECT_WINDOW)) ) 94 return true; 95 } 96 return false; 97} 98 99static inline void ab_position_report(unsigned long position) 100{ 101 if (ab_repeat_mode_enabled()) 102 { 103 if ( !(audio_status() & AUDIO_STATUS_PAUSE) && 104 ab_reached_B_marker(position) ) 105 { 106 ab_jump_to_A_marker(); 107 } 108 } 109} 110 111#endif 112 113#endif /* _ABREPEAT_H_ */