Skip to content

Commit

Permalink
audio: volume: reduce ramp volume calculation
Browse files Browse the repository at this point in the history
Will first check whether have same target volume, if same,
then only calculate one channel and copy to other channels.

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 committed Sep 15, 2023
1 parent f9846d9 commit f5f57b2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/audio/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ static inline int32_t volume_windows_fade_ramp(struct vol_data *cd, int32_t ramp
}
#endif

void volume_set_ramp_channel(struct vol_data *cd, uint32_t channels_count)
{
int i;

cd->is_same_volume = true;
for (i = 1; i < channels_count; i++) {
if (cd->tvolume[0] != cd->tvolume[i]) {
cd->is_same_volume = false;
break;
}
}

if (cd->is_same_volume)
cd->ramp_channel_counter = 1;
else
cd->ramp_channel_counter = channels_count;
}

/**
* \brief Ramps volume changes over time.
* \param[in,out] vol_data Volume component data
Expand Down Expand Up @@ -272,7 +290,7 @@ static inline void volume_ramp(struct processing_module *mod)
#endif

/* Update each volume if it's not at target for active channels */
for (i = 0; i < cd->channels; i++) {
for (i = 0; i < cd->ramp_channel_counter; i++) {
/* skip if target reached */
volume = cd->volume[i];
tvolume = cd->tvolume[i];
Expand Down Expand Up @@ -311,6 +329,11 @@ static inline void volume_ramp(struct processing_module *mod)
cd->volume[i] = new_vol;
}

if (cd->is_same_volume) {
for (i = 1; i < cd->channels; i++)
cd->volume[i] = cd->volume[0];
}

cd->is_passthrough = cd->ramp_finished;
for (i = 0; i < cd->channels; i++) {
if (cd->volume[i] != VOL_ZERO_DB) {
Expand Down
4 changes: 4 additions & 0 deletions src/audio/volume/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ struct vol_data {
bool copy_gain; /**< control copy gain or not */
uint32_t attenuation; /**< peakmeter adjustment in range [0 - 31] */
bool is_passthrough; /**< is passthrough or do gain multiplication */
bool is_same_volume; /**< check ramp volume are same with each channel */
uint32_t ramp_channel_counter; /**< channels need new ramp volume */
};

/** \brief Volume processing functions map. */
Expand Down Expand Up @@ -308,4 +310,6 @@ void volume_set_chan_mute(struct processing_module *mod, int chan);

void volume_set_chan_unmute(struct processing_module *mod, int chan);

void volume_set_ramp_channel(struct vol_data *cd, uint32_t channels_count);

#endif /* __SOF_AUDIO_VOLUME_H__ */
5 changes: 5 additions & 0 deletions src/audio/volume/volume_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ int volume_init(struct processing_module *mod)
cd->muted[i] = false;
}

cd->is_same_volume = true;
/* all target volume are same */
cd->ramp_channel_counter = 1;

switch (cd->ramp_type) {
#if CONFIG_COMP_VOLUME_LINEAR_RAMP
case SOF_VOLUME_LINEAR:
Expand Down Expand Up @@ -221,6 +225,7 @@ int volume_set_config(struct processing_module *mod, uint32_t config_id,
return ret;
}
}
volume_set_ramp_channel(cd, cd->channels);

volume_ramp_check(mod);
break;
Expand Down
5 changes: 5 additions & 0 deletions src/audio/volume/volume_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ int volume_init(struct processing_module *mod)
}

md->private = cd;
cd->is_same_volume = true;

for (channel = 0; channel < channels_count; channel++) {
if (vol->config[0].channel_id == IPC4_ALL_CHANNELS_MASK)
Expand All @@ -174,6 +175,8 @@ int volume_init(struct processing_module *mod)

init_ramp(cd, vol->config[0].curve_duration, target_volume[0]);

volume_set_ramp_channel(cd, channels_count);

cd->mailbox_offset = offsetof(struct ipc4_fw_registers, peak_vol_regs);
cd->mailbox_offset += instance_id * sizeof(struct ipc4_peak_volume_regs);

Expand Down Expand Up @@ -256,6 +259,8 @@ static int volume_set_volume(struct processing_module *mod, const uint8_t *data,
}
}

volume_set_ramp_channel(cd, channels_count);

cd->scale_vol = vol_get_processing_function(dev, cd);

volume_prepare_ramp(dev, cd);
Expand Down

0 comments on commit f5f57b2

Please sign in to comment.