mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Submit parts of FS#12189 regarding codec API. Replaces access to global settings with a dedicated function to determine if the current track shall be looped. Used by several synthesizer codecs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30391 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
e66ad3e8a8
commit
e88d24a840
13 changed files with 38 additions and 29 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include "buffering.h"
|
#include "buffering.h"
|
||||||
#include "dsp.h"
|
#include "dsp.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
/* Define LOGF_ENABLE to enable logf output in this file */
|
/* Define LOGF_ENABLE to enable logf output in this file */
|
||||||
/*#define LOGF_ENABLE*/
|
/*#define LOGF_ENABLE*/
|
||||||
|
@ -405,6 +406,11 @@ static enum codec_command_action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool codec_loop_track_callback(void)
|
||||||
|
{
|
||||||
|
return global_settings.repeat_mode == REPEAT_ONE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize codec API */
|
/* Initialize codec API */
|
||||||
void codec_init_codec_api(void)
|
void codec_init_codec_api(void)
|
||||||
{
|
{
|
||||||
|
@ -421,6 +427,7 @@ void codec_init_codec_api(void)
|
||||||
ci.set_offset = audio_codec_update_offset;
|
ci.set_offset = audio_codec_update_offset;
|
||||||
ci.configure = codec_configure_callback;
|
ci.configure = codec_configure_callback;
|
||||||
ci.get_command = codec_get_command_callback;
|
ci.get_command = codec_get_command_callback;
|
||||||
|
ci.loop_track = codec_loop_track_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "splash.h"
|
#include "splash.h"
|
||||||
#include "general.h"
|
#include "general.h"
|
||||||
|
#include "rbpaths.h"
|
||||||
|
|
||||||
#define LOGF_ENABLE
|
#define LOGF_ENABLE
|
||||||
#include "logf.h"
|
#include "logf.h"
|
||||||
|
@ -97,6 +98,7 @@ struct codec_api ci = {
|
||||||
NULL, /* set_offset */
|
NULL, /* set_offset */
|
||||||
NULL, /* configure */
|
NULL, /* configure */
|
||||||
NULL, /* get_command */
|
NULL, /* get_command */
|
||||||
|
NULL, /* loop_track */
|
||||||
|
|
||||||
/* kernel/ system */
|
/* kernel/ system */
|
||||||
#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
|
#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
|
||||||
|
@ -127,7 +129,6 @@ struct codec_api ci = {
|
||||||
memmove,
|
memmove,
|
||||||
memcmp,
|
memcmp,
|
||||||
memchr,
|
memchr,
|
||||||
strcasestr,
|
|
||||||
#if defined(DEBUG) || defined(SIMULATOR)
|
#if defined(DEBUG) || defined(SIMULATOR)
|
||||||
debugf,
|
debugf,
|
||||||
#endif
|
#endif
|
||||||
|
@ -136,7 +137,6 @@ struct codec_api ci = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(qsort_func)qsort,
|
(qsort_func)qsort,
|
||||||
&global_settings,
|
|
||||||
|
|
||||||
#ifdef RB_PROFILE
|
#ifdef RB_PROFILE
|
||||||
profile_thread,
|
profile_thread,
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include "dsp.h"
|
#include "dsp.h"
|
||||||
#endif
|
#endif
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
#include "gcc_extensions.h"
|
#include "gcc_extensions.h"
|
||||||
#include "load_code.h"
|
#include "load_code.h"
|
||||||
|
@ -75,12 +74,12 @@
|
||||||
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
|
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
|
||||||
|
|
||||||
/* increase this every time the api struct changes */
|
/* increase this every time the api struct changes */
|
||||||
#define CODEC_API_VERSION 42
|
#define CODEC_API_VERSION 43
|
||||||
|
|
||||||
/* update this to latest version if a change to the api struct breaks
|
/* update this to latest version if a change to the api struct breaks
|
||||||
backwards compatibility (and please take the opportunity to sort in any
|
backwards compatibility (and please take the opportunity to sort in any
|
||||||
new function which are "waiting" at the end of the function table) */
|
new function which are "waiting" at the end of the function table) */
|
||||||
#define CODEC_MIN_API_VERSION 42
|
#define CODEC_MIN_API_VERSION 43
|
||||||
|
|
||||||
/* reasons for calling codec main entrypoint */
|
/* reasons for calling codec main entrypoint */
|
||||||
enum codec_entry_call_reason {
|
enum codec_entry_call_reason {
|
||||||
|
@ -145,6 +144,8 @@ struct codec_api {
|
||||||
void (*configure)(int setting, intptr_t value);
|
void (*configure)(int setting, intptr_t value);
|
||||||
/* Obtain command action on what to do next */
|
/* Obtain command action on what to do next */
|
||||||
enum codec_command_action (*get_command)(intptr_t *param);
|
enum codec_command_action (*get_command)(intptr_t *param);
|
||||||
|
/* Determine whether the track should be looped, if applicable. */
|
||||||
|
bool (*loop_track)(void);
|
||||||
|
|
||||||
/* kernel/ system */
|
/* kernel/ system */
|
||||||
#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
|
#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
|
||||||
|
@ -180,7 +181,6 @@ struct codec_api {
|
||||||
void* (*memmove)(void *out, const void *in, size_t n);
|
void* (*memmove)(void *out, const void *in, size_t n);
|
||||||
int (*memcmp)(const void *s1, const void *s2, size_t n);
|
int (*memcmp)(const void *s1, const void *s2, size_t n);
|
||||||
void *(*memchr)(const void *s1, int c, size_t n);
|
void *(*memchr)(const void *s1, int c, size_t n);
|
||||||
char *(*strcasestr) (const char* phaystack, const char* pneedle);
|
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(SIMULATOR)
|
#if defined(DEBUG) || defined(SIMULATOR)
|
||||||
void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
|
void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
|
||||||
|
@ -193,9 +193,6 @@ struct codec_api {
|
||||||
void (*qsort)(void *base, size_t nmemb, size_t size,
|
void (*qsort)(void *base, size_t nmemb, size_t size,
|
||||||
int(*compar)(const void *, const void *));
|
int(*compar)(const void *, const void *));
|
||||||
|
|
||||||
/* The ADX codec accesses global_settings to test for REPEAT_ONE mode */
|
|
||||||
struct user_settings* global_settings;
|
|
||||||
|
|
||||||
#ifdef RB_PROFILE
|
#ifdef RB_PROFILE
|
||||||
void (*profile_thread)(void);
|
void (*profile_thread)(void);
|
||||||
void (*profstop)(void);
|
void (*profstop)(void);
|
||||||
|
|
|
@ -239,7 +239,7 @@ enum codec_status codec_run(void)
|
||||||
if (bufoff > end_adr-18*channels && looping) {
|
if (bufoff > end_adr-18*channels && looping) {
|
||||||
DEBUGF("ADX: loop!\n");
|
DEBUGF("ADX: loop!\n");
|
||||||
/* check for endless looping */
|
/* check for endless looping */
|
||||||
if (ci->global_settings->repeat_mode==REPEAT_ONE) {
|
if (ci->loop_track()) {
|
||||||
loop_count=0;
|
loop_count=0;
|
||||||
fade_count = -1; /* disable fade */
|
fade_count = -1; /* disable fade */
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,8 +17,8 @@ static struct Ay_Emu ay_emu;
|
||||||
static void set_codec_track(int t, int multitrack) {
|
static void set_codec_track(int t, int multitrack) {
|
||||||
Ay_start_track(&ay_emu, t);
|
Ay_start_track(&ay_emu, t);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for loop mode we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&ay_emu, Track_get_length( &ay_emu, t ) - 4000, 4000);
|
Track_set_fade(&ay_emu, Track_get_length( &ay_emu, t ) - 4000, 4000);
|
||||||
}
|
}
|
||||||
if (multitrack) ci->set_elapsed(t*1000); /* t is track no to display */
|
if (multitrack) ci->set_elapsed(t*1000); /* t is track no to display */
|
||||||
|
@ -111,7 +111,7 @@ next_track:
|
||||||
ci->seek_complete();
|
ci->seek_complete();
|
||||||
|
|
||||||
/* Set fade again */
|
/* Set fade again */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&ay_emu, Track_get_length( &ay_emu, track ) - 4000, 4000);
|
Track_set_fade(&ay_emu, Track_get_length( &ay_emu, track ) - 4000, 4000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ static struct Gbs_Emu gbs_emu;
|
||||||
static void set_codec_track(int t) {
|
static void set_codec_track(int t) {
|
||||||
Gbs_start_track(&gbs_emu, t);
|
Gbs_start_track(&gbs_emu, t);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for loop mode we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&gbs_emu, Track_get_length( &gbs_emu, t ), 4000);
|
Track_set_fade(&gbs_emu, Track_get_length( &gbs_emu, t ), 4000);
|
||||||
}
|
}
|
||||||
ci->set_elapsed(t*1000); /* t is track no to display */
|
ci->set_elapsed(t*1000); /* t is track no to display */
|
||||||
|
|
|
@ -17,8 +17,8 @@ static struct Hes_Emu hes_emu;
|
||||||
static void set_codec_track(int t) {
|
static void set_codec_track(int t) {
|
||||||
Hes_start_track(&hes_emu, t);
|
Hes_start_track(&hes_emu, t);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for loop mode we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&hes_emu, Track_get_length( &hes_emu, t ), 4000);
|
Track_set_fade(&hes_emu, Track_get_length( &hes_emu, t ), 4000);
|
||||||
}
|
}
|
||||||
ci->set_elapsed(t*1000); /* t is track no to display */
|
ci->set_elapsed(t*1000); /* t is track no to display */
|
||||||
|
|
|
@ -18,7 +18,7 @@ static void set_codec_track(int t) {
|
||||||
Kss_start_track(&kss_emu, t);
|
Kss_start_track(&kss_emu, t);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for REPEAT_ONE we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&kss_emu, Track_get_length( &kss_emu, t ), 4000);
|
Track_set_fade(&kss_emu, Track_get_length( &kss_emu, t ), 4000);
|
||||||
}
|
}
|
||||||
ci->set_elapsed(t*1000); /* t is track no to display */
|
ci->set_elapsed(t*1000); /* t is track no to display */
|
||||||
|
|
|
@ -20,7 +20,7 @@ static void set_codec_track(int t, int multitrack) {
|
||||||
Nsf_start_track(&nsf_emu, t);
|
Nsf_start_track(&nsf_emu, t);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for REPEAT_ONE we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&nsf_emu, Track_length( &nsf_emu, t ) - 4000, 4000);
|
Track_set_fade(&nsf_emu, Track_length( &nsf_emu, t ) - 4000, 4000);
|
||||||
}
|
}
|
||||||
if (multitrack) ci->set_elapsed(t*1000); /* t is track no to display */
|
if (multitrack) ci->set_elapsed(t*1000); /* t is track no to display */
|
||||||
|
@ -109,7 +109,7 @@ next_track:
|
||||||
ci->seek_complete();
|
ci->seek_complete();
|
||||||
|
|
||||||
/* Set fade again */
|
/* Set fade again */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&nsf_emu, Track_length( &nsf_emu, track ), 4000);
|
Track_set_fade(&nsf_emu, Track_length( &nsf_emu, track ), 4000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ static void set_codec_track(int t) {
|
||||||
Sgc_start_track(&sgc_emu, t);
|
Sgc_start_track(&sgc_emu, t);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for REPEAT_ONE we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&sgc_emu, Track_get_length( &sgc_emu, t ), 4000);
|
Track_set_fade(&sgc_emu, Track_get_length( &sgc_emu, t ), 4000);
|
||||||
}
|
}
|
||||||
ci->set_elapsed(t*1000); /* t is track no to display */
|
ci->set_elapsed(t*1000); /* t is track no to display */
|
||||||
|
|
|
@ -477,7 +477,7 @@ static int play_track( void )
|
||||||
sampleswritten += WAV_CHUNK_SIZE;
|
sampleswritten += WAV_CHUNK_SIZE;
|
||||||
|
|
||||||
/* is track timed? */
|
/* is track timed? */
|
||||||
if (ci->global_settings->repeat_mode!=REPEAT_ONE && ci->id3->length) {
|
if (!ci->loop_track() && ci->id3->length) {
|
||||||
unsigned long curtime = sampleswritten*1000LL/SAMPLE_RATE;
|
unsigned long curtime = sampleswritten*1000LL/SAMPLE_RATE;
|
||||||
unsigned long lasttimesample = (sampleswritten-WAV_CHUNK_SIZE);
|
unsigned long lasttimesample = (sampleswritten-WAV_CHUNK_SIZE);
|
||||||
|
|
||||||
|
@ -513,10 +513,10 @@ static int play_track( void )
|
||||||
|
|
||||||
spc_play_send_samples(samples);
|
spc_play_send_samples(samples);
|
||||||
|
|
||||||
if (ci->global_settings->repeat_mode!=REPEAT_ONE)
|
if (ci->loop_track())
|
||||||
ci->set_elapsed(sampleswritten*1000LL/SAMPLE_RATE);
|
|
||||||
else
|
|
||||||
ci->set_elapsed(0);
|
ci->set_elapsed(0);
|
||||||
|
else
|
||||||
|
ci->set_elapsed(sampleswritten*1000LL/SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXIT_TIMER(total);
|
EXIT_TIMER(total);
|
||||||
|
@ -571,7 +571,7 @@ enum codec_status codec_run(void)
|
||||||
|
|
||||||
LoadID666(buffer+0x2e);
|
LoadID666(buffer+0x2e);
|
||||||
|
|
||||||
if (ci->global_settings->repeat_mode!=REPEAT_ONE && ID666.length==0) {
|
if (!ci->loop_track() && ID666.length==0) {
|
||||||
ID666.length=3*60*1000; /* 3 minutes */
|
ID666.length=3*60*1000; /* 3 minutes */
|
||||||
ID666.fade=5*1000; /* 5 seconds */
|
ID666.fade=5*1000; /* 5 seconds */
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ enum codec_status codec_run(void)
|
||||||
Vgm_start_track(&vgm_emu);
|
Vgm_start_track(&vgm_emu);
|
||||||
|
|
||||||
/* for REPEAT_ONE we disable track limits */
|
/* for REPEAT_ONE we disable track limits */
|
||||||
if (ci->global_settings->repeat_mode != REPEAT_ONE) {
|
if (!ci->loop_track()) {
|
||||||
Track_set_fade(&vgm_emu, ci->id3->length - 4000, 4000);
|
Track_set_fade(&vgm_emu, ci->id3->length - 4000, 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -505,6 +505,12 @@ static enum codec_command_action get_command(intptr_t *param)
|
||||||
(void)param;
|
(void)param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Some codecs call this to determine whether they should loop. */
|
||||||
|
static bool loop_track(void)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void set_offset(size_t value)
|
static void set_offset(size_t value)
|
||||||
{
|
{
|
||||||
ci.id3->offset = value;
|
ci.id3->offset = value;
|
||||||
|
@ -561,6 +567,7 @@ static void init_ci(void)
|
||||||
ci.set_offset = set_offset;
|
ci.set_offset = set_offset;
|
||||||
ci.configure = configure;
|
ci.configure = configure;
|
||||||
ci.get_command = get_command;
|
ci.get_command = get_command;
|
||||||
|
ci.loop_track = loop_track;
|
||||||
|
|
||||||
/* --- "Core" functions --- */
|
/* --- "Core" functions --- */
|
||||||
|
|
||||||
|
@ -578,7 +585,6 @@ static void init_ci(void)
|
||||||
ci.memmove = rb->memmove;
|
ci.memmove = rb->memmove;
|
||||||
ci.memcmp = rb->memcmp;
|
ci.memcmp = rb->memcmp;
|
||||||
ci.memchr = rb->memchr;
|
ci.memchr = rb->memchr;
|
||||||
ci.strcasestr = rb->strcasestr;
|
|
||||||
#if defined(DEBUG) || defined(SIMULATOR)
|
#if defined(DEBUG) || defined(SIMULATOR)
|
||||||
ci.debugf = rb->debugf;
|
ci.debugf = rb->debugf;
|
||||||
#endif
|
#endif
|
||||||
|
@ -587,7 +593,6 @@ static void init_ci(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ci.qsort = rb->qsort;
|
ci.qsort = rb->qsort;
|
||||||
ci.global_settings = rb->global_settings;
|
|
||||||
|
|
||||||
#ifdef RB_PROFILE
|
#ifdef RB_PROFILE
|
||||||
ci.profile_thread = rb->profile_thread;
|
ci.profile_thread = rb->profile_thread;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue