From 6e794c9a2d9e91a926f70d0fcc66e255b0bdc221 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 3 Dec 2022 15:33:15 +0000 Subject: rbcodec dsp: Refactor DSP init routines, restore INIT_ATTR Refactor DSP init routines so there is a dedicated init function for the stages that need it. Remove the DSP_INIT configure message. This allows the init code to be safely marked INIT_ATTR, saving a bit of code size, and allowing the linker to verify that there are no unsafe references to the init routines. Change-Id: I1702f0f579bbb300a6fe7d0e67b13aa2e9dd7f8a --- lib/rbcodec/dsp/dsp_core.c | 21 ++++++++++++++++----- lib/rbcodec/dsp/dsp_core.h | 1 - lib/rbcodec/dsp/dsp_misc.c | 11 ----------- lib/rbcodec/dsp/dsp_proc_entry.h | 2 ++ lib/rbcodec/dsp/dsp_sample_io.c | 13 +++++++------ lib/rbcodec/dsp/dsp_sample_io.h | 5 +++-- lib/rbcodec/dsp/resample.c | 7 ++----- lib/rbcodec/dsp/resample.h | 26 ++++++++++++++++++++++++++ lib/rbcodec/dsp/tdspeed.c | 10 +++++----- lib/rbcodec/dsp/tdspeed.h | 1 + 10 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 lib/rbcodec/dsp/resample.h (limited to 'lib/rbcodec') diff --git a/lib/rbcodec/dsp/dsp_core.c b/lib/rbcodec/dsp/dsp_core.c index 14bf228bd6..5108c9ef47 100644 --- a/lib/rbcodec/dsp/dsp_core.c +++ b/lib/rbcodec/dsp/dsp_core.c @@ -24,6 +24,9 @@ #include "dsp_core.h" #include "dsp_sample_io.h" +#include "tdspeed.h" +#include "resample.h" + /* Define LOGF_ENABLE to enable logf output in this file */ /*#define LOGF_ENABLE*/ #include "logf.h" @@ -70,6 +73,11 @@ dsp_proc_slot_arr[DSP_NUM_PROC_STAGES+DSP_VOICE_NUM_PROC_STAGES] IBSS_ATTR; /* General DSP config */ static struct dsp_config dsp_conf[DSP_COUNT] IBSS_ATTR; +static const dsp_proc_init_fn_type dsp_init_fn[] INITDATA_ATTR = { + &dsp_timestretch_init, + &dsp_resample_init, +}; + /** Processing stages support functions **/ static const struct dsp_proc_db_entry * proc_db_entry(const struct dsp_proc_slot *s) @@ -517,12 +525,15 @@ void dsp_init(void) count = slot_count[i]; dsp->slot_free_mask = MASK_N(uint32_t, count, shift); - intptr_t value = i; - dsp_sample_io_configure(&dsp->io_data, DSP_INIT, &value); + dsp_sample_io_init(&dsp->io_data, i); + + /* Enable misc handler by default for the audio DSP */ + if (i == CODEC_IDX_AUDIO) + dsp_proc_enable(dsp, DSP_PROC_MISC_HANDLER, true); - /* Notify each db entry of global init for each DSP */ - for (unsigned int j = 0; j < DSP_NUM_PROC_STAGES; j++) - dsp_proc_database[j]->configure(NULL, dsp, DSP_INIT, i); + /* Call global init for DSPs that need it */ + for (unsigned int j = 0; j < ARRAYLEN(dsp_init_fn); ++j) + dsp_init_fn[j](dsp, i); dsp_configure(dsp, DSP_RESET, 0); } diff --git a/lib/rbcodec/dsp/dsp_core.h b/lib/rbcodec/dsp/dsp_core.h index 3544084056..9b09d981cc 100644 --- a/lib/rbcodec/dsp/dsp_core.h +++ b/lib/rbcodec/dsp/dsp_core.h @@ -32,7 +32,6 @@ enum dsp_ids enum dsp_settings { - DSP_INIT, /* For dsp_init */ DSP_RESET, DSP_SET_FREQUENCY, DSP_SET_SAMPLE_DEPTH, diff --git a/lib/rbcodec/dsp/dsp_misc.c b/lib/rbcodec/dsp/dsp_misc.c index 8687abc06a..24ec857e3a 100644 --- a/lib/rbcodec/dsp/dsp_misc.c +++ b/lib/rbcodec/dsp/dsp_misc.c @@ -149,13 +149,6 @@ unsigned int dsp_get_output_frequency(struct dsp_config *dsp) return dsp_configure(dsp, DSP_GET_OUT_FREQUENCY, 0); } -static void misc_dsp_init(struct dsp_config *dsp, unsigned int dsp_id) -{ - /* Enable us for the audio DSP at startup */ - if (dsp_id == CODEC_IDX_AUDIO) - dsp_proc_enable(dsp, DSP_PROC_MISC_HANDLER, true); -} - /* This is a null-processing stage that monitors as an enabled stage but never * becomes active in processing samples. It only hooks messages. */ @@ -167,10 +160,6 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this, { switch (setting) { - case DSP_INIT: - misc_dsp_init(dsp, value); - break; - case DSP_PROC_CLOSE: /* This stage should be enabled at all times */ DEBUGF("DSP_PROC_MISC_HANDLER - Error: Closing!\n"); diff --git a/lib/rbcodec/dsp/dsp_proc_entry.h b/lib/rbcodec/dsp/dsp_proc_entry.h index 0a65792207..7a4b8de1c6 100644 --- a/lib/rbcodec/dsp/dsp_proc_entry.h +++ b/lib/rbcodec/dsp/dsp_proc_entry.h @@ -127,6 +127,8 @@ typedef intptr_t (*dsp_proc_config_fn_type)(struct dsp_proc_entry *this, struct dsp_config *dsp, unsigned int setting, intptr_t value); +typedef void (*dsp_proc_init_fn_type)(struct dsp_config *dsp, + unsigned int dsp_id); /* Enable/disable a processing stage - not to be called during processing * by processing code! */ diff --git a/lib/rbcodec/dsp/dsp_sample_io.c b/lib/rbcodec/dsp/dsp_sample_io.c index af3a424aa0..8a0d5da7cc 100644 --- a/lib/rbcodec/dsp/dsp_sample_io.c +++ b/lib/rbcodec/dsp/dsp_sample_io.c @@ -36,6 +36,13 @@ static void format_change_set(struct sample_io_data *this) this->format_dirty = 1; } +void dsp_sample_io_init(struct sample_io_data *this, unsigned int dsp_id) +{ + this->output_sampr = DSP_OUT_DEFAULT_HZ; + dsp_sample_input_init(this, dsp_id); + dsp_sample_output_init(this); +} + bool dsp_sample_io_configure(struct sample_io_data *this, unsigned int setting, intptr_t *value_p) @@ -44,12 +51,6 @@ bool dsp_sample_io_configure(struct sample_io_data *this, switch (setting) { - case DSP_INIT: - this->output_sampr = DSP_OUT_DEFAULT_HZ; - dsp_sample_input_init(this, value); - dsp_sample_output_init(this); - break; - case DSP_RESET: /* Reset all sample descriptions to default */ format_change_set(this); diff --git a/lib/rbcodec/dsp/dsp_sample_io.h b/lib/rbcodec/dsp/dsp_sample_io.h index 7e41337a5b..095aea3f3a 100644 --- a/lib/rbcodec/dsp/dsp_sample_io.h +++ b/lib/rbcodec/dsp/dsp_sample_io.h @@ -56,17 +56,18 @@ struct sample_io_data uint8_t output_version; /* Format version of src buffer at output */ }; -void dsp_sample_input_init(struct sample_io_data *this, unsigned int dsp_id); +void dsp_sample_input_init(struct sample_io_data *this, unsigned int dsp_id) INIT_ATTR; void dsp_sample_input_flush(struct sample_io_data *this); void dsp_sample_input_format_change(struct sample_io_data *this, struct sample_format *format); -void dsp_sample_output_init(struct sample_io_data *this); +void dsp_sample_output_init(struct sample_io_data *this) INIT_ATTR; void dsp_sample_output_flush(struct sample_io_data *this); void dsp_sample_output_format_change(struct sample_io_data *this, struct sample_format *format); /* Sample IO watches the format setting from the codec */ +void dsp_sample_io_init(struct sample_io_data *this, unsigned int dsp_id) INIT_ATTR; bool dsp_sample_io_configure(struct sample_io_data *this, unsigned int setting, intptr_t *value_p); diff --git a/lib/rbcodec/dsp/resample.c b/lib/rbcodec/dsp/resample.c index 77e1c5e0e5..bec0de99f0 100644 --- a/lib/rbcodec/dsp/resample.c +++ b/lib/rbcodec/dsp/resample.c @@ -26,6 +26,7 @@ #include "fixedpoint.h" #include "dsp_proc_entry.h" #include "dsp_misc.h" +#include "resample.h" #include /** @@ -262,7 +263,7 @@ static intptr_t resample_new_format(struct dsp_proc_entry *this, return PROC_NEW_FORMAT_DEACTIVATED; } -static void resample_dsp_init(struct dsp_config *dsp, unsigned int dsp_id) +void dsp_resample_init(struct dsp_config *dsp, unsigned int dsp_id) { int32_t *lbuf, *rbuf; @@ -310,10 +311,6 @@ static intptr_t resample_configure(struct dsp_proc_entry *this, switch (setting) { - case DSP_INIT: - resample_dsp_init(dsp, value); - break; - case DSP_FLUSH: resample_flush(this); break; diff --git a/lib/rbcodec/dsp/resample.h b/lib/rbcodec/dsp/resample.h new file mode 100644 index 0000000000..1f6edf00ca --- /dev/null +++ b/lib/rbcodec/dsp/resample.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2022 Aidan MacDonald + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _DSP_RESAMPLE_H +#define _DSP_RESAMPLE_H + +void dsp_resample_init(struct dsp_config *dsp, unsigned int dsp_id) INIT_ATTR; + +#endif /* _DSP_RESAMPLE_H */ diff --git a/lib/rbcodec/dsp/tdspeed.c b/lib/rbcodec/dsp/tdspeed.c index 88d057560c..022a8edb6d 100644 --- a/lib/rbcodec/dsp/tdspeed.c +++ b/lib/rbcodec/dsp/tdspeed.c @@ -521,8 +521,12 @@ static intptr_t tdspeed_new_format(struct dsp_proc_entry *this, (void)this; } -static void tdspeed_dsp_init(struct tdspeed_state_s *st, unsigned int dsp_id) +void dsp_timestretch_init(struct dsp_config *dsp, unsigned int dsp_id) { + (void)dsp; + + struct tdspeed_state_s *st = &tdspeed_state; + /* everything is at 100% until dsp_set_timestretch is called with some other value and timestretch is enabled at the time */ if (dsp_id == CODEC_IDX_AUDIO) @@ -541,10 +545,6 @@ static intptr_t tdspeed_configure(struct dsp_proc_entry *this, switch (setting) { - case DSP_INIT: - tdspeed_dsp_init(st, value); - break; - case DSP_FLUSH: tdspeed_flush(); break; diff --git a/lib/rbcodec/dsp/tdspeed.h b/lib/rbcodec/dsp/tdspeed.h index 84920ac7c2..5f35990375 100644 --- a/lib/rbcodec/dsp/tdspeed.h +++ b/lib/rbcodec/dsp/tdspeed.h @@ -40,6 +40,7 @@ void dsp_timestretch_enable(bool enable); void dsp_set_timestretch(int32_t percent); int32_t dsp_get_timestretch(void); bool dsp_timestretch_available(void); +void dsp_timestretch_init(struct dsp_config *dsp, unsigned int dsp_id) INIT_ATTR; void tdspeed_move(int i, void* current, void* new); #endif /* _TDSPEED_H */ -- cgit v1.2.3