2012-03-27 23:52:15 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2013-05-27 07:23:33 +00:00
|
|
|
#include "rbcodecconfig.h"
|
2012-05-03 13:54:48 +00:00
|
|
|
#include "platform.h"
|
2012-04-29 21:31:30 +00:00
|
|
|
#include "dsp_core.h"
|
2012-03-27 23:52:15 +00:00
|
|
|
#include "dsp_sample_io.h"
|
|
|
|
|
|
|
|
/* Define LOGF_ENABLE to enable logf output in this file */
|
|
|
|
/*#define LOGF_ENABLE*/
|
|
|
|
#include "logf.h"
|
|
|
|
|
|
|
|
/* Actually generate the database of stages */
|
|
|
|
#define DSP_PROC_DB_CREATE
|
|
|
|
#include "dsp_proc_entry.h"
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
#ifndef DSP_PROCESS_START
|
|
|
|
/* These do nothing if not previously defined */
|
|
|
|
#define DSP_PROCESS_START()
|
|
|
|
#define DSP_PROCESS_LOOP()
|
|
|
|
#define DSP_PROCESS_END()
|
|
|
|
#endif /* !DSP_PROCESS_START */
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
/* Linked lists give fewer loads in processing loop compared to some index
|
|
|
|
* list, which is more important than keeping occasionally executed code
|
|
|
|
* simple */
|
|
|
|
|
|
|
|
struct dsp_config
|
|
|
|
{
|
|
|
|
/** General DSP-local data **/
|
2012-12-19 22:34:57 +00:00
|
|
|
struct sample_io_data io_data; /* Sample input-output data (first) */
|
|
|
|
uint32_t slot_free_mask; /* Mask of free slots for this DSP */
|
|
|
|
uint32_t proc_mask_enabled; /* Mask of enabled stages */
|
|
|
|
uint32_t proc_mask_active; /* Mask of active stages */
|
2012-03-27 23:52:15 +00:00
|
|
|
struct dsp_proc_slot
|
|
|
|
{
|
|
|
|
struct dsp_proc_entry proc_entry; /* This enabled stage */
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *next; /* Next enabled slot */
|
|
|
|
uint32_t mask; /* In place operation mask/flag */
|
|
|
|
uint8_t version; /* Sample format version */
|
|
|
|
uint8_t db_index; /* Index in database array */
|
|
|
|
} *proc_slots; /* Pointer to first in list of enabled
|
|
|
|
stages */
|
2012-03-27 23:52:15 +00:00
|
|
|
};
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
#define NACT_BIT BIT_N(___DSP_PROC_ID_RESERVED)
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
/* Pool of slots for stages - supports 32 or fewer combined as-is atm. */
|
|
|
|
static struct dsp_proc_slot
|
|
|
|
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;
|
|
|
|
|
|
|
|
/** Processing stages support functions **/
|
2012-12-19 22:34:57 +00:00
|
|
|
static const struct dsp_proc_db_entry *
|
|
|
|
proc_db_entry(const struct dsp_proc_slot *s)
|
|
|
|
{
|
|
|
|
return dsp_proc_database[s->db_index];
|
|
|
|
}
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* Find the slot for a given enabled id */
|
|
|
|
static struct dsp_proc_slot * find_proc_slot(struct dsp_config *dsp,
|
|
|
|
unsigned int id)
|
|
|
|
{
|
|
|
|
const uint32_t mask = BIT_N(id);
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (!(dsp->proc_mask_enabled & mask))
|
2012-03-27 23:52:15 +00:00
|
|
|
return NULL; /* Not enabled */
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *s = dsp->proc_slots;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
while (1) /* In proc_mask_enabled == it must be there */
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
if (BIT_N(proc_db_entry(s)->id) == mask)
|
2012-03-27 23:52:15 +00:00
|
|
|
return s;
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
s = s->next;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Broadcast to all enabled stages or to the one with the specifically
|
|
|
|
* crafted setting */
|
|
|
|
static intptr_t proc_broadcast(struct dsp_config *dsp, unsigned int setting,
|
|
|
|
intptr_t value)
|
|
|
|
{
|
|
|
|
bool multi = setting < DSP_PROC_SETTING;
|
2013-05-23 17:58:51 +00:00
|
|
|
struct dsp_proc_slot *s;
|
|
|
|
|
|
|
|
if (multi)
|
|
|
|
{
|
|
|
|
/* Message to all enabled stages */
|
|
|
|
if (dsp_sample_io_configure(&dsp->io_data, setting, &value))
|
|
|
|
return value; /* To I/O only */
|
|
|
|
|
|
|
|
s = dsp->proc_slots;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Message to a particular stage */
|
|
|
|
s = find_proc_slot(dsp, setting - DSP_PROC_SETTING);
|
|
|
|
}
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
while (s != NULL)
|
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
intptr_t ret = proc_db_entry(s)->configure(
|
|
|
|
&s->proc_entry, dsp, setting, value);
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
if (!multi)
|
|
|
|
return ret;
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
s = s->next;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 17:58:51 +00:00
|
|
|
return 0;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add an item to the enabled list */
|
|
|
|
static struct dsp_proc_slot *
|
|
|
|
dsp_proc_enable_enlink(struct dsp_config *dsp, uint32_t mask)
|
|
|
|
{
|
|
|
|
/* Use the lowest-indexed available slot */
|
|
|
|
int slot = find_first_set_bit(dsp->slot_free_mask);
|
|
|
|
|
|
|
|
if (slot == 32)
|
|
|
|
{
|
|
|
|
/* Should NOT happen, ever, unless called before init */
|
|
|
|
DEBUGF("DSP %d: no slots!\n", (int)dsp_get_id(dsp));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
unsigned int db_index = 0, db_index_prev = DSP_NUM_PROC_STAGES;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* Order of enabled list is same as DB array */
|
2012-12-19 22:34:57 +00:00
|
|
|
while (1)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
uint32_t m = BIT_N(dsp_proc_database[db_index]->id);
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
if (m == mask)
|
|
|
|
break; /* This is the one */
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (dsp->proc_mask_enabled & m)
|
|
|
|
db_index_prev = db_index;
|
|
|
|
|
|
|
|
if (++db_index >= DSP_NUM_PROC_STAGES)
|
|
|
|
return NULL;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dsp_proc_slot *s = &dsp_proc_slot_arr[slot];
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (db_index_prev < DSP_NUM_PROC_STAGES)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *prev =
|
|
|
|
find_proc_slot(dsp, dsp_proc_database[db_index_prev]->id);
|
|
|
|
s->next = prev->next;
|
|
|
|
prev->next = s;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
s->next = dsp->proc_slots;
|
|
|
|
dsp->proc_slots = s;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
s->mask = mask | NACT_BIT;
|
|
|
|
s->version = 0;
|
|
|
|
s->db_index = db_index;
|
|
|
|
dsp->proc_mask_enabled |= mask;
|
2012-03-27 23:52:15 +00:00
|
|
|
dsp->slot_free_mask &= ~BIT_N(slot);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove an item from the enabled list */
|
|
|
|
static struct dsp_proc_slot *
|
|
|
|
dsp_proc_enable_delink(struct dsp_config *dsp, uint32_t mask)
|
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *s = dsp->proc_slots;
|
2012-03-27 23:52:15 +00:00
|
|
|
struct dsp_proc_slot *prev = NULL;
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
while (1) /* In proc_mask_enabled == it must be there */
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
if (BIT_N(proc_db_entry(s)->id) == mask)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
|
|
|
if (prev)
|
2012-12-19 22:34:57 +00:00
|
|
|
prev->next = s->next;
|
2012-03-27 23:52:15 +00:00
|
|
|
else
|
2012-12-19 22:34:57 +00:00
|
|
|
dsp->proc_slots = s->next;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
dsp->proc_mask_enabled &= ~mask;
|
2012-03-27 23:52:15 +00:00
|
|
|
dsp->slot_free_mask |= BIT_N(s - dsp_proc_slot_arr);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = s;
|
2012-12-19 22:34:57 +00:00
|
|
|
s = s->next;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dsp_proc_enable(struct dsp_config *dsp, enum dsp_proc_ids id,
|
|
|
|
bool enable)
|
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
const uint32_t mask = BIT_N(id);
|
|
|
|
bool enabled = dsp->proc_mask_enabled & mask;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
/* If enabled, just find it in list, if not, link a new one */
|
|
|
|
struct dsp_proc_slot *s = enabled ? find_proc_slot(dsp, id) :
|
|
|
|
dsp_proc_enable_enlink(dsp, mask);
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
DEBUGF("DSP- proc id not valid: %d\n", (int)id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
{
|
|
|
|
/* New entry - set defaults */
|
|
|
|
s->proc_entry.data = 0;
|
2012-12-19 22:34:57 +00:00
|
|
|
s->proc_entry.process = NULL;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
enabled = proc_db_entry(s)->configure(&s->proc_entry, dsp,
|
|
|
|
DSP_PROC_INIT, enabled) >= 0;
|
2012-03-27 23:52:15 +00:00
|
|
|
if (enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DEBUGF("DSP- proc init failed: %d\n", (int)id);
|
|
|
|
/* Cleanup below */
|
|
|
|
}
|
|
|
|
else if (!enabled)
|
|
|
|
{
|
|
|
|
return; /* No change */
|
|
|
|
}
|
|
|
|
|
|
|
|
dsp_proc_activate(dsp, id, false); /* Deactivate it first */
|
|
|
|
struct dsp_proc_slot *s = dsp_proc_enable_delink(dsp, mask);
|
2012-12-19 22:34:57 +00:00
|
|
|
proc_db_entry(s)->configure(&s->proc_entry, dsp, DSP_PROC_CLOSE, 0);
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 17:58:51 +00:00
|
|
|
/* Is the stage specified by the id currently enabled? */
|
|
|
|
bool dsp_proc_enabled(struct dsp_config *dsp, enum dsp_proc_ids id)
|
|
|
|
{
|
|
|
|
return (dsp->proc_mask_enabled & BIT_N(id)) != 0;
|
|
|
|
}
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
/* Activate or deactivate a stage */
|
|
|
|
void dsp_proc_activate(struct dsp_config *dsp, enum dsp_proc_ids id,
|
|
|
|
bool activate)
|
|
|
|
{
|
|
|
|
const uint32_t mask = BIT_N(id);
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (!(dsp->proc_mask_enabled & mask))
|
2012-03-27 23:52:15 +00:00
|
|
|
return; /* Not enabled */
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (activate != !(dsp->proc_mask_active & mask))
|
2012-03-27 23:52:15 +00:00
|
|
|
return; /* No change in state */
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *s = find_proc_slot(dsp, id);
|
|
|
|
|
|
|
|
if (activate)
|
|
|
|
{
|
|
|
|
dsp->proc_mask_active |= mask;
|
|
|
|
s->mask &= ~NACT_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dsp->proc_mask_active &= ~mask;
|
|
|
|
s->mask |= NACT_BIT;
|
|
|
|
}
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the stage specified by the id currently active? */
|
|
|
|
bool dsp_proc_active(struct dsp_config *dsp, enum dsp_proc_ids id)
|
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
return (dsp->proc_mask_active & BIT_N(id)) != 0;
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
/* Force the specified stage to receive a format update before the next
|
|
|
|
* buffer is sent to process() */
|
|
|
|
void dsp_proc_want_format_update(struct dsp_config *dsp,
|
|
|
|
enum dsp_proc_ids id)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *s = find_proc_slot(dsp, id);
|
2012-03-27 23:52:15 +00:00
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (s)
|
|
|
|
s->version = 0; /* Set invalid */
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
/* Set or unset in-place operation */
|
|
|
|
void dsp_proc_set_in_place(struct dsp_config *dsp, enum dsp_proc_ids id,
|
|
|
|
bool in_place)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
struct dsp_proc_slot *s = find_proc_slot(dsp, id);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const uint32_t mask = BIT_N(id);
|
|
|
|
|
|
|
|
if (in_place)
|
|
|
|
s->mask |= mask;
|
|
|
|
else
|
|
|
|
s->mask &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine by the rules if the processing function should be called */
|
|
|
|
static NO_INLINE bool dsp_proc_new_format(struct dsp_proc_slot *s,
|
|
|
|
struct dsp_config *dsp,
|
|
|
|
struct dsp_buffer *buf)
|
|
|
|
{
|
|
|
|
struct dsp_proc_entry *this = &s->proc_entry;
|
|
|
|
struct sample_format *format = &buf->format;
|
|
|
|
|
|
|
|
switch (proc_db_entry(s)->configure(
|
|
|
|
this, dsp, DSP_PROC_NEW_FORMAT, (intptr_t)format))
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
case PROC_NEW_FORMAT_OK:
|
|
|
|
s->version = format->version;
|
2012-03-27 23:52:15 +00:00
|
|
|
return true;
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
case PROC_NEW_FORMAT_TRANSITION:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case PROC_NEW_FORMAT_DEACTIVATED:
|
|
|
|
s->version = format->version;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
static FORCE_INLINE void dsp_proc_call(struct dsp_proc_slot *s,
|
|
|
|
struct dsp_config *dsp,
|
|
|
|
struct dsp_buffer **buf_p)
|
|
|
|
{
|
|
|
|
struct dsp_buffer *buf = *buf_p;
|
|
|
|
|
|
|
|
if (UNLIKELY(buf->format.version != s->version))
|
|
|
|
{
|
|
|
|
if (!dsp_proc_new_format(s, dsp, buf))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->mask)
|
|
|
|
{
|
|
|
|
if ((s->mask & (buf->proc_mask | NACT_BIT)) || buf->remcount <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buf->proc_mask |= s->mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->proc_entry.process(&s->proc_entry, buf_p);
|
|
|
|
}
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dsp_process:
|
|
|
|
*
|
|
|
|
* Process and convert src audio to dst based on the DSP configuration.
|
|
|
|
* dsp: the DSP instance in use
|
|
|
|
*
|
|
|
|
* src:
|
|
|
|
* remcount = number of input samples remaining; set to desired
|
|
|
|
* number of samples to be processed
|
|
|
|
* pin[0] = left channel if non-interleaved, audio data if
|
|
|
|
* interleaved or mono
|
|
|
|
* pin[1] = right channel if non-interleaved, ignored if
|
|
|
|
* interleaved or mono
|
|
|
|
* proc_mask = set to zero on first call, updated by this function
|
|
|
|
* to keep track of which in-place stages have been
|
|
|
|
* run on the buffers to avoid multiple applications of
|
|
|
|
* them
|
|
|
|
* format = for internal buffers, gives the relevant format
|
|
|
|
* details
|
|
|
|
*
|
|
|
|
* dst:
|
|
|
|
* remcount = number of samples placed in buffer so far; set to
|
|
|
|
* zero on first call
|
|
|
|
* p16out = current fill pointer in destination buffer; set to
|
|
|
|
* buffer start on first call
|
|
|
|
* bufcount = remaining buffer space in samples; set to maximum
|
|
|
|
* desired output count on first call
|
|
|
|
* format = ignored
|
|
|
|
*
|
|
|
|
* Processing stops when src is exhausted or dst is filled, whichever
|
|
|
|
* happens first. Samples can still be output when src buffer is empty
|
|
|
|
* if samples are held internally. Generally speaking, continue calling
|
|
|
|
* until no data is consumed and no data is produced to purge the DSP
|
|
|
|
* to the maximum extent feasible. Some internal processing stages may
|
|
|
|
* require more input before more output can be generated, thus there
|
|
|
|
* is no guarantee the DSP is free of data awaiting processing at that
|
|
|
|
* point.
|
|
|
|
*
|
|
|
|
* Additionally, samples consumed and samples produced do not necessarily
|
|
|
|
* have a direct correlation. Samples may be consumed without producing
|
|
|
|
* any output and samples may be produced without consuming any input.
|
|
|
|
* It depends on which stages are actively processing data at the time
|
|
|
|
* of the call and how they function internally.
|
|
|
|
*/
|
|
|
|
void dsp_process(struct dsp_config *dsp, struct dsp_buffer *src,
|
|
|
|
struct dsp_buffer *dst)
|
|
|
|
{
|
|
|
|
if (dst->bufcount <= 0)
|
|
|
|
{
|
|
|
|
/* No place to put anything thus nothing may be safely consumed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-03 13:54:48 +00:00
|
|
|
DSP_PROCESS_START();
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* Tag input with codec-specified sample format */
|
|
|
|
src->format = dsp->io_data.format;
|
|
|
|
|
2013-05-04 18:23:21 +00:00
|
|
|
if (src->format.version != dsp->io_data.sample_buf.format.version)
|
|
|
|
dsp_sample_input_format_change(&dsp->io_data, &src->format);
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* Out-of-place-processing stages take the current buf as input
|
|
|
|
* and switch the buffer to their own output buffer */
|
|
|
|
struct dsp_buffer *buf = src;
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
/* Convert input samples to internal format */
|
|
|
|
dsp->io_data.input_samples(&dsp->io_data, &buf);
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* Call all active/enabled stages depending if format is
|
|
|
|
same/changed on the last output buffer */
|
2012-12-19 22:34:57 +00:00
|
|
|
for (struct dsp_proc_slot *s = dsp->proc_slots; s; s = s->next)
|
|
|
|
dsp_proc_call(s, dsp, &buf);
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* Don't overread/write src/destination */
|
|
|
|
int outcount = MIN(dst->bufcount, buf->remcount);
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (outcount <= 0)
|
2012-03-27 23:52:15 +00:00
|
|
|
break; /* Output full or purged internal buffers */
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
if (UNLIKELY(buf->format.version != dsp->io_data.output_version))
|
|
|
|
dsp_sample_output_format_change(&dsp->io_data, &buf->format);
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
dsp->io_data.outcount = outcount;
|
2012-12-19 22:34:57 +00:00
|
|
|
dsp->io_data.output_samples(&dsp->io_data, buf, dst);
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* Advance buffers by what output consumed and produced */
|
|
|
|
dsp_advance_buffer32(buf, outcount);
|
|
|
|
dsp_advance_buffer_output(dst, outcount);
|
|
|
|
|
2012-05-03 13:54:48 +00:00
|
|
|
DSP_PROCESS_LOOP();
|
2012-03-27 23:52:15 +00:00
|
|
|
} /* while */
|
|
|
|
|
2012-05-03 13:54:48 +00:00
|
|
|
DSP_PROCESS_END();
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t dsp_configure(struct dsp_config *dsp, unsigned int setting,
|
|
|
|
intptr_t value)
|
|
|
|
{
|
|
|
|
return proc_broadcast(dsp, setting, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dsp_config * dsp_get_config(enum dsp_ids id)
|
|
|
|
{
|
|
|
|
if (id >= DSP_COUNT)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &dsp_conf[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the id given a dsp pointer (or even via something within
|
|
|
|
the struct itself) */
|
|
|
|
enum dsp_ids dsp_get_id(const struct dsp_config *dsp)
|
|
|
|
{
|
|
|
|
ptrdiff_t id = dsp - dsp_conf;
|
|
|
|
|
|
|
|
if (id < 0 || id >= DSP_COUNT)
|
|
|
|
return DSP_COUNT; /* obviously invalid */
|
|
|
|
|
|
|
|
return (enum dsp_ids)id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do what needs initializing before enable/disable calls can be made.
|
|
|
|
* Must be done before changing settings for the first time. */
|
|
|
|
void INIT_ATTR dsp_init(void)
|
|
|
|
{
|
2012-05-01 05:26:22 +00:00
|
|
|
static const uint8_t slot_count[DSP_COUNT] INITDATA_ATTR =
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
|
|
|
[CODEC_IDX_AUDIO] = DSP_NUM_PROC_STAGES,
|
|
|
|
[CODEC_IDX_VOICE] = DSP_VOICE_NUM_PROC_STAGES
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned int i = 0, count, shift = 0;
|
|
|
|
i < DSP_COUNT;
|
|
|
|
i++, shift += count)
|
|
|
|
{
|
|
|
|
struct dsp_config *dsp = &dsp_conf[i];
|
|
|
|
|
|
|
|
count = slot_count[i];
|
|
|
|
dsp->slot_free_mask = MASK_N(uint32_t, count, shift);
|
|
|
|
|
2013-05-23 17:58:51 +00:00
|
|
|
intptr_t value = i;
|
|
|
|
dsp_sample_io_configure(&dsp->io_data, DSP_INIT, &value);
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
dsp_configure(dsp, DSP_RESET, 0);
|
|
|
|
}
|
|
|
|
}
|