2012-03-27 23:52:15 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Miika Pekkarinen
|
|
|
|
* Copyright (C) 2005 Magnus Holmgren
|
|
|
|
* Copyright (C) 2007 Thom Johansen
|
|
|
|
* 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-03-27 23:52:15 +00:00
|
|
|
#include "sound.h"
|
|
|
|
#include "fixedpoint.h"
|
2012-04-29 21:31:30 +00:00
|
|
|
#include "replaygain.h"
|
2012-03-27 23:52:15 +00:00
|
|
|
#include "dsp_proc_entry.h"
|
2012-04-29 21:31:30 +00:00
|
|
|
#include "dsp_misc.h"
|
2012-04-30 20:27:01 +00:00
|
|
|
#include "pga.h"
|
|
|
|
#include "channel_mode.h"
|
|
|
|
#ifdef HAVE_SW_TONE_CONTROLS
|
|
|
|
#include "tone_controls.h"
|
|
|
|
#endif
|
2012-04-29 21:31:30 +00:00
|
|
|
#include <string.h>
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/** Replaygain settings **/
|
2012-04-30 20:27:01 +00:00
|
|
|
static struct replaygain_settings current_settings;
|
|
|
|
static struct dsp_replay_gains current_gains;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
2012-04-30 20:27:01 +00:00
|
|
|
static void dsp_replaygain_update(
|
|
|
|
const struct replaygain_settings *settings,
|
|
|
|
const struct dsp_replay_gains *gains)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-04-30 20:27:01 +00:00
|
|
|
if (settings != ¤t_settings)
|
|
|
|
current_settings = *settings; /* Stash settings */
|
|
|
|
|
|
|
|
if (gains != ¤t_gains)
|
|
|
|
current_gains = *gains; /* Stash gains */
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
int32_t gain = PGA_UNITY;
|
|
|
|
|
2012-04-30 20:27:01 +00:00
|
|
|
if (settings->type != REPLAYGAIN_OFF || settings->noclip)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-04-30 20:27:01 +00:00
|
|
|
bool track_mode = settings->type == REPLAYGAIN_TRACK &&
|
|
|
|
gains->track_gain != 0;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
int32_t peak = (track_mode || gains->album_peak == 0) ?
|
2012-04-30 20:27:01 +00:00
|
|
|
gains->track_peak : gains->album_peak;
|
2012-03-27 23:52:15 +00:00
|
|
|
|
2012-04-30 20:27:01 +00:00
|
|
|
if (settings->type != REPLAYGAIN_OFF)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
|
|
|
gain = (track_mode || gains->album_gain == 0) ?
|
|
|
|
gains->track_gain : gains->album_gain;
|
|
|
|
|
2012-04-30 20:27:01 +00:00
|
|
|
if (settings->preamp != 0)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-04-30 20:27:01 +00:00
|
|
|
int32_t preamp = get_replaygain_int(settings->preamp * 10);
|
2012-03-27 23:52:15 +00:00
|
|
|
gain = fp_mul(gain, preamp, 24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gain == 0)
|
|
|
|
{
|
|
|
|
/* So that noclip can work even with no gain information. */
|
|
|
|
gain = PGA_UNITY;
|
|
|
|
}
|
|
|
|
|
2012-04-30 20:27:01 +00:00
|
|
|
if (settings->noclip && peak != 0 &&
|
2012-03-27 23:52:15 +00:00
|
|
|
fp_mul(gain, peak, 24) >= PGA_UNITY)
|
|
|
|
{
|
|
|
|
gain = fp_div(PGA_UNITY, peak, 24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pga_set_gain(PGA_REPLAYGAIN, gain);
|
|
|
|
pga_enable_gain(PGA_REPLAYGAIN, gain != PGA_UNITY);
|
|
|
|
}
|
|
|
|
|
2012-04-30 21:51:05 +00:00
|
|
|
static void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains)
|
2012-04-30 20:27:01 +00:00
|
|
|
{
|
|
|
|
if (gains == NULL)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-04-30 20:27:01 +00:00
|
|
|
/* Set defaults */
|
|
|
|
gains = ¤t_gains;
|
|
|
|
memset((void *)gains, 0, sizeof (*gains));
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 20:27:01 +00:00
|
|
|
dsp_replaygain_update(¤t_settings, gains);
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 21:51:05 +00:00
|
|
|
void dsp_replaygain_set_settings(const struct replaygain_settings *settings)
|
|
|
|
{
|
|
|
|
dsp_replaygain_update(settings, ¤t_gains);
|
|
|
|
}
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
|
|
|
|
/** Pitch Settings **/
|
|
|
|
|
2012-05-08 14:34:26 +00:00
|
|
|
#ifdef HAVE_PITCHCONTROL
|
2012-03-27 23:52:15 +00:00
|
|
|
static int32_t pitch_ratio = PITCH_SPEED_100;
|
|
|
|
|
|
|
|
static void dsp_pitch_update(struct dsp_config *dsp)
|
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
dsp_configure(dsp, DSP_SET_PITCH,
|
|
|
|
fp_div(pitch_ratio, PITCH_SPEED_100, 16));
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-23 18:19:06 +00:00
|
|
|
void dsp_set_pitch(int32_t percent)
|
2012-03-27 23:52:15 +00:00
|
|
|
{
|
2012-12-19 22:34:57 +00:00
|
|
|
if (percent <= 0)
|
|
|
|
percent = PITCH_SPEED_100;
|
|
|
|
|
|
|
|
if (percent == pitch_ratio)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pitch_ratio = percent;
|
|
|
|
|
|
|
|
dsp_pitch_update(dsp_get_config(CODEC_IDX_AUDIO));
|
2012-03-27 23:52:15 +00:00
|
|
|
}
|
2013-04-13 03:35:47 +00:00
|
|
|
|
2013-05-23 18:19:06 +00:00
|
|
|
int32_t dsp_get_pitch(void)
|
2013-04-13 03:35:47 +00:00
|
|
|
{
|
2013-05-23 18:19:06 +00:00
|
|
|
return pitch_ratio;
|
2013-04-13 03:35:47 +00:00
|
|
|
}
|
2013-05-23 18:19:06 +00:00
|
|
|
#endif /* HAVE_PITCHCONTROL */
|
2013-04-13 03:35:47 +00:00
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
static void INIT_ATTR misc_dsp_init(struct dsp_config *dsp,
|
|
|
|
enum dsp_ids 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);
|
|
|
|
}
|
2013-04-13 03:35:47 +00:00
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
/* This is a null-processing stage that monitors as an enabled stage but never
|
|
|
|
* becomes active in processing samples. It only hooks messages. */
|
|
|
|
|
|
|
|
/* DSP message hook */
|
|
|
|
static intptr_t misc_handler_configure(struct dsp_proc_entry *this,
|
|
|
|
struct dsp_config *dsp,
|
|
|
|
unsigned setting,
|
|
|
|
intptr_t value)
|
|
|
|
{
|
|
|
|
switch (setting)
|
|
|
|
{
|
|
|
|
case DSP_INIT:
|
2012-12-19 22:34:57 +00:00
|
|
|
misc_dsp_init(dsp, (enum dsp_ids)value);
|
2012-03-27 23:52:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DSP_PROC_CLOSE:
|
|
|
|
/* This stage should be enabled at all times */
|
|
|
|
DEBUGF("DSP_PROC_MISC_HANDLER - Error: Closing!\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSP_RESET:
|
2012-05-08 14:34:26 +00:00
|
|
|
#ifdef HAVE_PITCHCONTROL
|
2012-03-27 23:52:15 +00:00
|
|
|
dsp_pitch_update(dsp);
|
|
|
|
#endif
|
|
|
|
value = (intptr_t)NULL; /* Default gains */
|
|
|
|
case REPLAYGAIN_SET_GAINS:
|
2012-04-30 20:27:01 +00:00
|
|
|
dsp_replaygain_set_gains((void *)value);
|
2012-03-27 23:52:15 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-08 14:34:26 +00:00
|
|
|
#ifdef HAVE_PITCHCONTROL
|
2012-03-27 23:52:15 +00:00
|
|
|
case DSP_SET_FREQUENCY:
|
|
|
|
dsp_pitch_update(dsp);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-12-19 22:34:57 +00:00
|
|
|
return 0;
|
2012-03-27 23:52:15 +00:00
|
|
|
(void)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Database entry */
|
|
|
|
DSP_PROC_DB_ENTRY(
|
|
|
|
MISC_HANDLER,
|
|
|
|
misc_handler_configure);
|