From e82392e2461d260b777ecd78256bb828b11be858 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Thu, 22 Jul 2021 18:07:54 +0300 Subject: [PATCH] Audio: Volume: Add state clear to reset() operation This patch adds clear of all component data in reset() component operation except state variables those are set by control commands. Note: If a new stream starts after reset() without free() and new(), the clear of all component data would result to wrong gain and wrong mute state. The driver commands are not re-sent in such case. Signed-off-by: Seppo Ingalsuo --- src/audio/volume/volume.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/audio/volume/volume.c b/src/audio/volume/volume.c index 9da8e1ffc..3cb7aebed 100644 --- a/src/audio/volume/volume.c +++ b/src/audio/volume/volume.c @@ -292,6 +292,26 @@ static void volume_ramp(struct comp_dev *dev) vol_sync_host(dev, cd->channels); } +/** + * \brief Reset state except controls. + */ +static void reset_state(struct vol_data *cd) +{ + int i; + + for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) { + cd->rvolume[i] = 0; + cd->ramp_coef[i] = 0; + } + + cd->channels = 0; + cd->ramp_finished = false; + cd->vol_ramp_active = false; + cd->vol_ramp_frames = 0; + cd->vol_ramp_elapsed_frames = 0; + cd->sample_rate = 0; +} + /** * \brief Creates volume component. * @@ -365,9 +385,7 @@ static struct comp_dev *volume_new(const struct comp_driver *drv, cd->muted[i] = false; } - cd->vol_ramp_active = false; - cd->channels = 0; /* To be set in prepare() */ - + reset_state(cd); comp_info(dev, "vol->initial_ramp = %d, vol->ramp = %d, vol->min_value = %d, vol->max_value = %d", vol->initial_ramp, vol->ramp, vol->min_value, vol->max_value); @@ -890,8 +908,10 @@ err: */ static int volume_reset(struct comp_dev *dev) { - comp_dbg(dev, "volume_reset()"); + struct vol_data *cd = comp_get_drvdata(dev); + comp_dbg(dev, "volume_reset()"); + reset_state(cd); comp_set_state(dev, COMP_TRIGGER_RESET); return 0; }