Skip to content

Commit

Permalink
audio: volume: remove delta calculation in ramp loop
Browse files Browse the repository at this point in the history
it is not changed during ramp calculation, so move it to set
channel volume part.

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 committed Sep 15, 2023
1 parent 484d123 commit 8cd500e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/audio/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ static inline int32_t volume_windows_fade_ramp(struct vol_data *cd, int32_t ramp
{
int32_t time_ratio; /* Q2.30 */
int32_t pow_value; /* Q2.30 */
int32_t volume_delta = cd->tvolume[channel] - cd->rvolume[channel]; /* Q16.16 */

if (!cd->initial_ramp)
return cd->tvolume[channel];

time_ratio = (((int64_t)ramp_time) << 30) / (cd->initial_ramp << 3);
pow_value = volume_pow_175(time_ratio);
return cd->rvolume[channel] + Q_MULTSR_32X32((int64_t)volume_delta, pow_value, 16, 30, 16);
return cd->rvolume[channel] + Q_MULTSR_32X32((int64_t)cd->volume_delta[channel],
pow_value, 16, 30, 16);
}
#endif

Expand Down Expand Up @@ -452,6 +452,7 @@ int volume_set_chan(struct processing_module *mod, int chan,

cd->tvolume[chan] = v;
cd->rvolume[chan] = cd->volume[chan];
cd->volume_delta[chan] = v - cd->volume[chan];
cd->vol_ramp_elapsed_frames = 0;

/* Check ramp type */
Expand Down
1 change: 1 addition & 0 deletions src/audio/volume/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct vol_data {
int32_t tvolume[SOF_IPC_MAX_CHANNELS]; /**< target volume */
int32_t mvolume[SOF_IPC_MAX_CHANNELS]; /**< mute volume */
int32_t rvolume[SOF_IPC_MAX_CHANNELS]; /**< ramp start volume */
int32_t volume_delta[SOF_IPC_MAX_CHANNELS]; /**< delta volume */
int32_t ramp_coef[SOF_IPC_MAX_CHANNELS]; /**< parameter for slope */
/**< store current volume 4 times for scale_vol function */
int32_t *vol;
Expand Down
2 changes: 2 additions & 0 deletions src/audio/volume/volume_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ int volume_init(struct processing_module *mod)
target_volume[channel_cfg],
vol->config[channel_cfg].curve_type,
vol->config[channel_cfg].curve_duration);

cd->volume_delta[channel] = target_volume[channel] - cd->volume[channel];
}

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

0 comments on commit 8cd500e

Please sign in to comment.