1
0
Fork 0
forked from len0rd/rockbox

Fundamentally rewrite much of the audio DSP.

Creates a standard buffer passing, local data passing and messaging
system for processing stages. Stages can be moved to their own source
files to reduce clutter and ease assimilation of new ones. dsp.c
becomes dsp_core.c which supports an engine and framework for effects.

Formats and change notifications are passed along with the buffer so
that they arrive at the correct time at each stage in the chain
regardless of the internal delays of a particular one.

Removes restrictions on the number of samples that can be processed at
a time and it pays attention to destination buffer size restrictions
without having to limit input count, which also allows pcmbuf to
remain fuller and safely set its own buffer limits as it sees fit.
There is no longer a need to query input/output counts given a certain
number of input samples; just give it the sizes of the source and
destination buffers.

Works in harmony with stages that are not deterministic in terms of
sample input/output ratio (like both resamplers but most notably
the timestretch). As a result it fixes quirks with timestretch hanging
up with certain settings and it now operates properly throughout its
full settings range.
Change-Id: Ib206ec78f6f6c79259c5af9009fe021d68be9734
Reviewed-on: http://gerrit.rockbox.org/200
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested-by: Michael Sevakis <jethead71@rockbox.org>
This commit is contained in:
Michael Sevakis 2012-03-27 19:52:15 -04:00
parent c9c1349773
commit c9bcbe202d
56 changed files with 4823 additions and 2998 deletions

View file

@ -19,16 +19,18 @@
*
****************************************************************************/
#include "config.h"
#include "system.h"
#include "fixedpoint.h"
#include "fracmul.h"
#include "settings.h"
#include "dsp.h"
#include "compressor.h"
#include <string.h>
/* Define LOGF_ENABLE to enable logf output in this file */
/*#define LOGF_ENABLE*/
#include "logf.h"
#include "dsp_proc_entry.h"
static struct compressor_settings curr_set; /* Cached settings */
static int32_t comp_rel_slope IBSS_ATTR; /* S7.24 format */
@ -251,10 +253,10 @@ bool compressor_update(const struct compressor_settings *settings)
* Returns the required gain factor in S7.24 format in order to compress the
* sample in accordance with the compression curve. Always 1 or less.
*/
static inline int32_t get_compression_gain(struct dsp_data *data,
static inline int32_t get_compression_gain(struct sample_format *format,
int32_t sample)
{
const int frac_bits_offset = data->frac_bits - 15;
const int frac_bits_offset = format->frac_bits - 15;
/* sample must be positive */
if (sample < 0)
@ -292,24 +294,40 @@ static inline int32_t get_compression_gain(struct dsp_data *data,
return -1;
}
/** DSP interface **/
/** SET COMPRESSOR
* Enable or disable the compressor based upon the settings
*/
void dsp_set_compressor(const struct compressor_settings *settings)
{
/* enable/disable the compressor depending upon settings */
bool enable = compressor_update(settings);
struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
dsp_proc_enable(dsp, DSP_PROC_COMPRESSOR, enable);
dsp_proc_activate(dsp, DSP_PROC_COMPRESSOR, true);
}
/** COMPRESSOR PROCESS
* Changes the gain of the samples according to the compressor curve
*/
void compressor_process(int count, struct dsp_data *data, int32_t *buf[])
static void compressor_process(struct dsp_proc_entry *this,
struct dsp_buffer **buf_p)
{
const int num_chan = data->num_channels;
int32_t *in_buf[2] = {buf[0], buf[1]};
struct dsp_buffer *buf = *buf_p;
int count = buf->remcount;
int32_t *in_buf[2] = { buf->p32[0], buf->p32[1] };
const int num_chan = buf->format.num_channels;
while (count-- > 0)
{
int ch;
/* use lowest (most compressed) gain factor of the output buffer
sample pair for both samples (mono is also handled correctly here)
*/
int32_t sample_gain = UNITY;
for (ch = 0; ch < num_chan; ch++)
for (int ch = 0; ch < num_chan; ch++)
{
int32_t this_gain = get_compression_gain(data, *in_buf[ch]);
int32_t this_gain = get_compression_gain(&buf->format, *in_buf[ch]);
if (this_gain < sample_gain)
sample_gain = this_gain;
}
@ -345,7 +363,7 @@ void compressor_process(int count, struct dsp_data *data, int32_t *buf[])
output buffer sample pair/mono sample */
if (total_gain != UNITY)
{
for (ch = 0; ch < num_chan; ch++)
for (int ch = 0; ch < num_chan; ch++)
{
*in_buf[ch] = FRACMUL_SHL(total_gain, *in_buf[ch], 7);
}
@ -353,9 +371,33 @@ void compressor_process(int count, struct dsp_data *data, int32_t *buf[])
in_buf[0]++;
in_buf[1]++;
}
(void)this;
}
void compressor_reset(void)
/* DSP message hook */
static intptr_t compressor_configure(struct dsp_proc_entry *this,
struct dsp_config *dsp,
unsigned int setting,
intptr_t value)
{
release_gain = UNITY;
switch (setting)
{
case DSP_PROC_INIT:
if (value != 0)
break; /* Already enabled */
this->process[0] = compressor_process;
case DSP_RESET:
case DSP_FLUSH:
release_gain = UNITY;
break;
}
return 1;
(void)dsp;
}
/* Database entry */
DSP_PROC_DB_ENTRY(
COMPRESSOR,
compressor_configure);