diff --git a/src/audio/volume/volume.c b/src/audio/volume/volume.c index 4dfc282ea..2bf398964 100644 --- a/src/audio/volume/volume.c +++ b/src/audio/volume/volume.c @@ -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: diff --git a/src/include/sof/audio/volume.h b/src/include/sof/audio/volume.h index b92133fd0..8b1b65650 100644 --- a/src/include/sof/audio/volume.h +++ b/src/include/sof/audio/volume.h @@ -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.