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 Oct 13, 2023
1 parent bd7e739 commit ba03358
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
23 changes: 22 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_counter(struct vol_data *cd, uint32_t channels_count)
{
int i;
bool is_same_volume = true;

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

if (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 @@ -315,6 +333,9 @@ static inline void volume_ramp(struct processing_module *mod)
cd->volume[i] = new_vol;
}

for (i = cd->ramp_channel_counter; 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
3 changes: 3 additions & 0 deletions src/audio/volume/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ 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 */
uint32_t ramp_channel_counter; /**< channels need new ramp volume */
};

/** \brief Volume processing functions map. */
Expand Down Expand Up @@ -308,4 +309,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_counter(struct vol_data *cd, uint32_t channels_count);

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

/* 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 @@ -217,6 +220,7 @@ int volume_set_config(struct processing_module *mod, uint32_t config_id,
return ret;
}
}
volume_set_ramp_channel_counter(cd, cd->channels);

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

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

volume_set_ramp_channel_counter(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 @@ -258,6 +260,8 @@ static int volume_set_volume(struct processing_module *mod, const uint8_t *data,
}
}

volume_set_ramp_channel_counter(cd, channels_count);

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

volume_prepare_ramp(dev, cd);
Expand Down

0 comments on commit ba03358

Please sign in to comment.