Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio: Peak volume: Add Kconfig to select the period of reporting peak meter value. #7715

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/audio/module_adapter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,42 @@ config COMP_PEAK_VOL
This option enables reporting to host peak vol regs.
See: struct ipc4_peak_volume_regs

choice "PEAK_METER_UPDATE_PERIOD_CHOICE"
prompt "The periods(ms) of updating peak meter value"
default PEAK_METER_UPDATE_10MS
depends on COMP_PEAK_VOL

config PEAK_METER_UPDATE_1MS
bool "1ms"
help
Update the peak meter value every 1ms

config PEAK_METER_UPDATE_10MS
bool "10ms"
help
Update the peak meter value every 10ms

config PEAK_METER_UPDATE_100MS
bool "100ms"
help
Update the peak meter value every 100ms

config PEAK_METER_UPDATE_1000MS
bool "1000ms"
help
Update the peak meter value every 1000ms
endchoice

config PEAK_METER_UPDATE_PERIOD
int
depends on COMP_PEAK_VOL
default 1 if PEAK_METER_UPDATE_1MS
default 10 if PEAK_METER_UPDATE_10MS
default 100 if PEAK_METER_UPDATE_100MS
default 1000 if PEAK_METER_UPDATE_1000MS
help
Decide which period of update the peak volume meter value

config COMP_GAIN
bool "GAIN component"
default y
Expand Down
14 changes: 14 additions & 0 deletions src/audio/module_adapter/module/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ static int set_volume_ipc4(struct vol_data *cd, uint32_t const channel,
cd->peak_regs.target_volume[channel] = target_volume;
/* update peak meter in peak_regs */
cd->peak_regs.peak_meter[channel] = 0;
cd->peak_cnt = 0;

/* init target volume */
cd->tvolume[channel] = target_volume;
Expand Down Expand Up @@ -1169,6 +1170,14 @@ static int volume_process(struct processing_module *mod,

avail_frames -= frames;
}
#if CONFIG_COMP_PEAK_VOL
cd->peak_cnt++;
andrula-song marked this conversation as resolved.
Show resolved Hide resolved
if (cd->peak_cnt == cd->peak_report_cnt) {
cd->peak_cnt = 0;
peak_vol_update(cd);
memset(cd->peak_regs.peak_meter, 0, sizeof(cd->peak_regs.peak_meter));
}
#endif

return 0;
}
Expand Down Expand Up @@ -1247,6 +1256,11 @@ static int volume_prepare(struct processing_module *mod)
comp_dbg(dev, "volume_prepare()");

#if CONFIG_IPC_MAJOR_4
cd->peak_cnt = 0;
cd->peak_report_cnt = CONFIG_PEAK_METER_UPDATE_PERIOD * 1000 / mod->dev->period;
if (cd->peak_report_cnt == 0)
cd->peak_report_cnt = 1;

ret = volume_params(mod);
if (ret < 0)
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu
int remaining_samples = frames * nch;
int32_t tmp;

memset(cd->peak_regs.peak_meter, 0, sizeof(uint32_t) * cd->channels);
x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed);
y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size);

Expand All @@ -94,8 +93,6 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu
x = audio_stream_wrap(source, x + n);
y = audio_stream_wrap(sink, y + n);
}
/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S24LE */

Expand Down Expand Up @@ -126,7 +123,6 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu
int remaining_samples = frames * nch;
int32_t tmp;

memset(cd->peak_regs.peak_meter, 0, sizeof(uint32_t) * cd->channels);
x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed);
y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size);
bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples);
Expand Down Expand Up @@ -156,9 +152,6 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu
x = audio_stream_wrap(source, x + n);
y = audio_stream_wrap(sink, y + n);
}

/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S32LE */

Expand Down Expand Up @@ -189,7 +182,6 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
int remaining_samples = frames * nch;
int32_t tmp;

memset(cd->peak_regs.peak_meter, 0, sizeof(uint32_t) * cd->channels);
x = audio_stream_wrap(source, (char *)audio_stream_get_rptr(source) + bsource->consumed);
y = audio_stream_wrap(sink, (char *)audio_stream_get_wptr(sink) + bsink->size);

Expand All @@ -216,9 +208,6 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
x = audio_stream_wrap(source, x + n);
y = audio_stream_wrap(sink, y + n);
}

/* update peak vol */
peak_vol_update(cd);
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
cd->peak_regs.peak_meter[i] = MAX(cd->peak_vol[i],
cd->peak_vol[i + channels_count])
<< (attenuation + PEAK_24S_32C_ADJUST);
/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S24LE */

Expand Down Expand Up @@ -243,9 +241,6 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea
for (i = 0; i < channels_count; i++)
cd->peak_regs.peak_meter[i] = MAX(cd->peak_vol[i],
cd->peak_vol[i + channels_count]) << attenuation;

/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S32LE */

Expand Down Expand Up @@ -364,8 +359,6 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
m = MAX(m, cd->peak_vol[i + channels_count * 3]);
cd->peak_regs.peak_meter[i] = m;
}
/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S16LE */

Expand Down Expand Up @@ -404,8 +397,6 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
ae_f32x2 peak_vol;
uint32_t *peak_meter = cd->peak_regs.peak_meter;

memset(peak_meter, 0, sizeof(int32_t) * cd->channels);

bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples);
bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples);
while (samples) {
Expand Down Expand Up @@ -448,8 +439,6 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
out0 = audio_stream_wrap(sink, out0 + n);
in0 = audio_stream_wrap(source, in0 + n);
}
/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S24LE */

Expand Down Expand Up @@ -485,7 +474,6 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea
ae_f32x2 peak_vol;
uint32_t *peak_meter = cd->peak_regs.peak_meter;

memset(peak_meter, 0, sizeof(uint32_t) * cd->channels);
bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples);
bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples);
while (samples) {
Expand Down Expand Up @@ -528,8 +516,6 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea
out0 = audio_stream_wrap(sink, out0 + n);
in0 = audio_stream_wrap(source, in0 + n);
}
/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S32LE */

Expand Down Expand Up @@ -566,8 +552,6 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
ae_f32x2 peak_vol;
uint32_t *peak_meter = cd->peak_regs.peak_meter;

memset(peak_meter, 0, sizeof(int32_t) * cd->channels);

while (samples) {
m = audio_stream_samples_without_wrap_s16(source, in0);
n = MIN(m, samples);
Expand Down Expand Up @@ -614,8 +598,6 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n);
bsink->size += VOL_S16_SAMPLES_TO_BYTES(n);
}
/* update peak vol */
peak_vol_update(cd);
}
#endif /* CONFIG_FORMAT_S16LE */
#endif /* HIFI3 VERSION */
Expand Down
2 changes: 2 additions & 0 deletions src/include/sof/audio/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ struct vol_data {
struct ipc4_peak_volume_regs peak_regs;
/**< store temp peak volume 4 times for scale_vol function */
int32_t *peak_vol;
uint32_t peak_cnt; /**< accumulated period of volume processing*/
uint32_t peak_report_cnt; /**< the period number to update peak meter*/
#endif
int32_t volume[SOF_IPC_MAX_CHANNELS]; /**< current volume */
int32_t tvolume[SOF_IPC_MAX_CHANNELS]; /**< target volume */
Expand Down