mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
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
This commit is contained in:
parent
646d5f92ef
commit
b96b7640de
5 changed files with 129 additions and 103 deletions
|
@ -11,6 +11,7 @@ dsp/afr.c
|
||||||
dsp/surround.c
|
dsp/surround.c
|
||||||
dsp/dsp_filter.c
|
dsp/dsp_filter.c
|
||||||
dsp/dsp_misc.c
|
dsp/dsp_misc.c
|
||||||
|
dsp/dsp_sample_io.c
|
||||||
dsp/dsp_sample_input.c
|
dsp/dsp_sample_input.c
|
||||||
dsp/dsp_sample_output.c
|
dsp/dsp_sample_output.c
|
||||||
dsp/eq.c
|
dsp/eq.c
|
||||||
|
|
|
@ -49,11 +49,6 @@
|
||||||
* behave.
|
* 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 */
|
#define SAMPLE_BUF_COUNT 128 /* Per channel, per DSP */
|
||||||
/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */
|
/* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */
|
||||||
static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR;
|
static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR;
|
||||||
|
@ -241,23 +236,13 @@ void dsp_sample_input_format_change(struct sample_io_data *this,
|
||||||
[this->sample_depth > NATIVE_DEPTH ? 1 : 0];
|
[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 */
|
/* 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;
|
this->sample_buf.remcount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dsp_sample_input_init(struct sample_io_data *this,
|
void dsp_sample_input_init(struct sample_io_data *this,
|
||||||
enum dsp_ids dsp_id)
|
enum dsp_ids dsp_id)
|
||||||
{
|
{
|
||||||
int32_t *lbuf, *rbuf;
|
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[0] = lbuf;
|
||||||
this->sample_buf_p[1] = rbuf;
|
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;
|
|
||||||
}
|
|
||||||
|
|
116
lib/rbcodec/dsp/dsp_sample_io.c
Normal file
116
lib/rbcodec/dsp/dsp_sample_io.c
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -56,9 +56,13 @@ struct sample_io_data
|
||||||
uint8_t output_version; /* Format version of src buffer at output */
|
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,
|
void dsp_sample_input_format_change(struct sample_io_data *this,
|
||||||
struct sample_format *format);
|
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,
|
void dsp_sample_output_format_change(struct sample_io_data *this,
|
||||||
struct sample_format *format);
|
struct sample_format *format);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,11 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
#ifndef INIT_ATTR
|
#ifndef INIT_ATTR
|
||||||
# define INIT_ATTR
|
# define INIT_ATTR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef INITDATA_ATTR
|
||||||
|
# define INITDATA_ATTR
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef CODEC
|
#ifdef CODEC
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue