diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-03 15:15:44 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-22 17:20:14 -0500 |
commit | b96b7640de381757c5ceac182e01bc84f668e64a (patch) | |
tree | 28480994531e0e6563c5dec34affd69e2adcdeac | |
parent | 646d5f92ef966bfaae288becd8774953d3703f5f (diff) | |
download | rockbox-b96b7640de.tar.gz rockbox-b96b7640de.zip |
rbcodec dsp: Move dsp_sample_io_configure() to its own file
Makes dsp_sample_input.c a bit less messy, and dependencies
are more explicit. There's possibly a minor loss of inlining
but it isn't a big deal.
Change-Id: I30f923a0ca758f2b113d32852d1f65586dff0cd1
-rw-r--r-- | lib/rbcodec/SOURCES | 1 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_sample_input.c | 106 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_sample_io.c | 116 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_sample_io.h | 4 | ||||
-rw-r--r-- | lib/rbcodec/platform.h | 5 |
5 files changed, 129 insertions, 103 deletions
diff --git a/lib/rbcodec/SOURCES b/lib/rbcodec/SOURCES index b0efebc989..28097e9f49 100644 --- a/lib/rbcodec/SOURCES +++ b/lib/rbcodec/SOURCES @@ -11,6 +11,7 @@ dsp/afr.c dsp/surround.c dsp/dsp_filter.c dsp/dsp_misc.c +dsp/dsp_sample_io.c dsp/dsp_sample_input.c dsp/dsp_sample_output.c dsp/eq.c diff --git a/lib/rbcodec/dsp/dsp_sample_input.c b/lib/rbcodec/dsp/dsp_sample_input.c index c57f81bb4f..8068ce5097 100644 --- a/lib/rbcodec/dsp/dsp_sample_input.c +++ b/lib/rbcodec/dsp/dsp_sample_input.c @@ -49,11 +49,6 @@ * behave. */ -extern void dsp_sample_output_init(struct sample_io_data *this); -extern void dsp_sample_output_flush(struct sample_io_data *this); -extern void dsp_sample_output_format_change(struct sample_io_data *this, - struct sample_format *format); - #define SAMPLE_BUF_COUNT 128 /* Per channel, per DSP */ /* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */ static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR; @@ -241,24 +236,14 @@ void dsp_sample_input_format_change(struct sample_io_data *this, [this->sample_depth > NATIVE_DEPTH ? 1 : 0]; } -/* increment the format version counter */ -static void format_change_set(struct sample_io_data *this) -{ - if (this->format_dirty) - return; - - this->format.version = (uint8_t)(this->format.version + 1) ?: 1; - this->format_dirty = 1; -} - /* discard the sample buffer */ -static void dsp_sample_input_flush(struct sample_io_data *this) +void dsp_sample_input_flush(struct sample_io_data *this) { this->sample_buf.remcount = 0; } -static void dsp_sample_input_init(struct sample_io_data *this, - enum dsp_ids dsp_id) +void dsp_sample_input_init(struct sample_io_data *this, + enum dsp_ids dsp_id) { int32_t *lbuf, *rbuf; @@ -282,88 +267,3 @@ static void dsp_sample_input_init(struct sample_io_data *this, this->sample_buf_p[0] = lbuf; this->sample_buf_p[1] = rbuf; } - -static void dsp_sample_io_init(struct sample_io_data *this, - enum dsp_ids 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) -{ - intptr_t value = *value_p; - - switch (setting) - { - case DSP_INIT: - dsp_sample_io_init(this, (enum dsp_ids)value); - break; - - case DSP_RESET: - /* Reset all sample descriptions to default */ - format_change_set(this); - this->format.num_channels = 2; - this->format.frac_bits = WORD_FRACBITS; - this->format.output_scale = WORD_FRACBITS + 1 - NATIVE_DEPTH; - this->format.frequency = this->output_sampr; - this->format.codec_frequency = this->output_sampr; - this->sample_depth = NATIVE_DEPTH; - this->stereo_mode = STEREO_NONINTERLEAVED; - break; - - case DSP_SET_FREQUENCY: - format_change_set(this); - value = value > 0 ? (unsigned int)value : this->output_sampr; - this->format.frequency = value; - this->format.codec_frequency = value; - break; - - case DSP_SET_SAMPLE_DEPTH: - format_change_set(this); - this->format.frac_bits = - value <= NATIVE_DEPTH ? WORD_FRACBITS : value; - this->format.output_scale = - this->format.frac_bits + 1 - NATIVE_DEPTH; - this->sample_depth = value; - break; - - case DSP_SET_STEREO_MODE: - format_change_set(this); - this->format.num_channels = value == STEREO_MONO ? 1 : 2; - this->stereo_mode = value; - break; - - case DSP_FLUSH: - dsp_sample_input_flush(this); - dsp_sample_output_flush(this); - break; - - case DSP_SET_PITCH: - format_change_set(this); - value = value > 0 ? value : (1 << 16); - this->format.frequency = - fp_mul(value, this->format.codec_frequency, 16); - break; - - case DSP_SET_OUT_FREQUENCY: - value = value > 0 ? value : DSP_OUT_DEFAULT_HZ; - value = MIN(DSP_OUT_MAX_HZ, MAX(DSP_OUT_MIN_HZ, value)); - *value_p = value; - - if ((unsigned int)value == this->output_sampr) - return true; /* No change; don't broadcast */ - - this->output_sampr = value; - break; - - case DSP_GET_OUT_FREQUENCY: - *value_p = this->output_sampr; - return true; /* Only I/O handles it */ - } - - return false; -} diff --git a/lib/rbcodec/dsp/dsp_sample_io.c b/lib/rbcodec/dsp/dsp_sample_io.c new file mode 100644 index 0000000000..637d41a918 --- /dev/null +++ b/lib/rbcodec/dsp/dsp_sample_io.c @@ -0,0 +1,116 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 Miika Pekkarinen + * Copyright (C) 2012 Michael Sevakis + * + * 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. + * + ****************************************************************************/ +#include "rbcodecconfig.h" +#include "platform.h" +#include "dsp_core.h" +#include "dsp_sample_io.h" +#include "dsp_proc_entry.h" +#include "fixedpoint.h" + +/* increment the format version counter */ +static void format_change_set(struct sample_io_data *this) +{ + if (this->format_dirty) + return; + + this->format.version = (uint8_t)(this->format.version + 1) ?: 1; + this->format_dirty = 1; +} + +bool dsp_sample_io_configure(struct sample_io_data *this, + unsigned int setting, + intptr_t *value_p) +{ + intptr_t value = *value_p; + + switch (setting) + { + case DSP_INIT: + this->output_sampr = DSP_OUT_DEFAULT_HZ; + dsp_sample_input_init(this, (enum dsp_ids)value); + dsp_sample_output_init(this); + break; + + case DSP_RESET: + /* Reset all sample descriptions to default */ + format_change_set(this); + this->format.num_channels = 2; + this->format.frac_bits = WORD_FRACBITS; + this->format.output_scale = WORD_FRACBITS + 1 - NATIVE_DEPTH; + this->format.frequency = this->output_sampr; + this->format.codec_frequency = this->output_sampr; + this->sample_depth = NATIVE_DEPTH; + this->stereo_mode = STEREO_NONINTERLEAVED; + break; + + case DSP_SET_FREQUENCY: + format_change_set(this); + value = value > 0 ? (unsigned int)value : this->output_sampr; + this->format.frequency = value; + this->format.codec_frequency = value; + break; + + case DSP_SET_SAMPLE_DEPTH: + format_change_set(this); + this->format.frac_bits = + value <= NATIVE_DEPTH ? WORD_FRACBITS : value; + this->format.output_scale = + this->format.frac_bits + 1 - NATIVE_DEPTH; + this->sample_depth = value; + break; + + case DSP_SET_STEREO_MODE: + format_change_set(this); + this->format.num_channels = value == STEREO_MONO ? 1 : 2; + this->stereo_mode = value; + break; + + case DSP_FLUSH: + dsp_sample_input_flush(this); + dsp_sample_output_flush(this); + break; + + case DSP_SET_PITCH: + format_change_set(this); + value = value > 0 ? value : (1 << 16); + this->format.frequency = + fp_mul(value, this->format.codec_frequency, 16); + break; + + case DSP_SET_OUT_FREQUENCY: + value = value > 0 ? value : DSP_OUT_DEFAULT_HZ; + value = MIN(DSP_OUT_MAX_HZ, MAX(DSP_OUT_MIN_HZ, value)); + *value_p = value; + + if ((unsigned int)value == this->output_sampr) + return true; /* No change; don't broadcast */ + + this->output_sampr = value; + break; + + case DSP_GET_OUT_FREQUENCY: + *value_p = this->output_sampr; + return true; /* Only I/O handles it */ + } + + return false; +} diff --git a/lib/rbcodec/dsp/dsp_sample_io.h b/lib/rbcodec/dsp/dsp_sample_io.h index 5117e04a3e..483f24112c 100644 --- a/lib/rbcodec/dsp/dsp_sample_io.h +++ b/lib/rbcodec/dsp/dsp_sample_io.h @@ -56,9 +56,13 @@ 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, enum dsp_ids dsp_id); +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_flush(struct sample_io_data *this); void dsp_sample_output_format_change(struct sample_io_data *this, struct sample_format *format); diff --git a/lib/rbcodec/platform.h b/lib/rbcodec/platform.h index d13380b795..d6b890599a 100644 --- a/lib/rbcodec/platform.h +++ b/lib/rbcodec/platform.h @@ -41,6 +41,11 @@ size_t strlcpy(char *dst, const char *src, size_t siz); #ifndef INIT_ATTR # define INIT_ATTR #endif + +#ifndef INITDATA_ATTR +# define INITDATA_ATTR +#endif + /* #ifdef CODEC |