Skip to content

Commit 531c255

Browse files
committed
Audio: Volume: Fix the ramping and ZC mode align
This patch fixes an issue where processing smaller parts of the period can break the data align constraints. The frames count value from zc_get() function or from cd->vol_ramp_frames is rounded up to next align compatible frames count. The failure with align constraints appeared as glitches in audio with some 44.1 kHz family sample rates. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 07815d2 commit 531c255

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/audio/volume/volume.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ static int volume_process(struct processing_module *mod,
556556
struct output_stream_buffer *output_buffers, int num_output_buffers)
557557
{
558558
struct vol_data *cd = module_get_private_data(mod);
559+
struct audio_stream *source = input_buffers[0].data;
559560
uint32_t avail_frames = input_buffers[0].size;
560561
uint32_t frames;
561562
int64_t prev_sum = 0;
@@ -571,12 +572,27 @@ static int volume_process(struct processing_module *mod,
571572
frames = avail_frames;
572573
} else if (cd->ramp_type == SOF_VOLUME_LINEAR_ZC) {
573574
/* with ZC ramping look for next ZC offset */
574-
frames = cd->zc_get(input_buffers[0].data, cd->vol_ramp_frames, &prev_sum);
575+
frames = cd->zc_get(source, cd->vol_ramp_frames, &prev_sum);
576+
/* Align frames count to audio stream constraints. If it rounds to zero
577+
* round it up to smallest nonzero aligned frames count.
578+
*/
579+
frames = audio_stream_align_frames_round_nearest(source, frames);
580+
if (!frames)
581+
frames = audio_stream_align_frames_round_up(source, 1);
575582
} else {
576-
/* without ZC process max ramp chunk */
577-
frames = cd->vol_ramp_frames;
583+
/* During volume ramp align the number of frames used in this
584+
* gain step. Align up since with low rates this would typically
585+
* become zero.
586+
*/
587+
frames = audio_stream_align_frames_round_up(source, cd->vol_ramp_frames);
578588
}
579589

590+
/* Cancel the gain step for ZC or smaller ramp step if it exceeds
591+
* the available frames.
592+
*/
593+
if (frames > avail_frames)
594+
frames = avail_frames;
595+
580596
if (!cd->ramp_finished) {
581597
volume_ramp(mod);
582598
cd->vol_ramp_elapsed_frames += frames;

0 commit comments

Comments
 (0)