Audio: Make volume gain ramp update rate variable

This patch adds to volume component capability to use one of
four ramp update rate presets 125 to 1000 us depending on topology
defined ramp length that is typically between 20 to 250 ms. The
rate needs to be higher for faster ramps to avoid zipper noise.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2020-06-25 14:30:30 +03:00 committed by Liam Girdwood
parent 3dc0ae97ac
commit 6bae1569a2
2 changed files with 30 additions and 4 deletions

View File

@ -789,9 +789,11 @@ static int volume_prepare(struct comp_dev *dev)
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *sinkb;
struct sof_ipc_comp_config *config = dev_comp_config(dev);
struct sof_ipc_comp_volume *pga;
uint32_t sink_period_bytes;
int i;
int ramp_update_us;
int ret;
int i;
comp_dbg(dev, "volume_prepare()");
@ -840,7 +842,6 @@ static int volume_prepare(struct comp_dev *dev)
* for entire topology specified time.
*/
cd->ramp_finished = true;
cd->vol_ramp_frames = dev->frames / (dev->period / VOL_RAMP_UPDATE_US);
cd->channels = sinkb->stream.channels;
cd->sample_rate = sinkb->stream.rate;
for (i = 0; i < cd->channels; i++) {
@ -850,6 +851,21 @@ static int volume_prepare(struct comp_dev *dev)
cd->ramp_finished = false;
}
/* Determine ramp update rate depending on requested ramp length. To
* ensure evenly updated gain envelope with limited fraction resolution
* four presets are used.
*/
pga = COMP_GET_IPC(dev, sof_ipc_comp_volume);
if (pga->initial_ramp < VOL_RAMP_UPDATE_THRESHOLD_FASTEST_MS)
ramp_update_us = VOL_RAMP_UPDATE_FASTEST_US;
else if (pga->initial_ramp < VOL_RAMP_UPDATE_THRESHOLD_FAST_MS)
ramp_update_us = VOL_RAMP_UPDATE_FAST_US;
else if (pga->initial_ramp < VOL_RAMP_UPDATE_THRESHOLD_SLOW_MS)
ramp_update_us = VOL_RAMP_UPDATE_SLOW_US;
else
ramp_update_us = VOL_RAMP_UPDATE_SLOWEST_US;
cd->vol_ramp_frames = dev->frames / (dev->period / ramp_update_us);
return 0;
err:

View File

@ -47,9 +47,19 @@ struct sof_ipc_ctrl_value_chan;
/**
* \brief Volume ramp update rate in microseconds.
* Update volume gain value every 1 ms.
* Update volume gain value every 125 to 1000 us. The faster gain ramps need
* higher update rate to avoid annoying zipper noise sound. The below
* values were tested subjectively for constraint of 125 microseconds
* multiple gain update rate.
*/
#define VOL_RAMP_UPDATE_US 1000
#define VOL_RAMP_UPDATE_SLOWEST_US 1000
#define VOL_RAMP_UPDATE_SLOW_US 500
#define VOL_RAMP_UPDATE_FAST_US 250
#define VOL_RAMP_UPDATE_FASTEST_US 125
#define VOL_RAMP_UPDATE_THRESHOLD_SLOW_MS 128
#define VOL_RAMP_UPDATE_THRESHOLD_FAST_MS 64
#define VOL_RAMP_UPDATE_THRESHOLD_FASTEST_MS 32
/**
* \brief Volume maximum value.