Skip to contentSkip to conversation

pcm: dmix: fix access to sum-buffer in non-interleaved mixing mode

PATCH In review Vijay Palaniswamy (RBEI/ECF3) 2 participants 2 messages Aug 12, 2020 – Aug 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcm: dmix: fix access to sum-buffer in non-interleaved mixing mode

Hi All,

When dmix uses non-interleaved mixing mode the offset and step width to sum_buffer was calculated by using the dmix channels instead of the slave channels. This leads to audio distortions due to frame corruption. Issue happens while doing channel wise mixing of src and destination buffers.

Attached the patch to fix the offset and step width calculation based on slave channels for sum buffer. So mixed data will be saved in respective channels of sum buffer.

Steps to reproduce the issue:
With below configuratio, Do aplay on both device in parallel for audio distortion

pcm.dmix_2_channels {
        type dmix
        ipc_key 5678293
        ipc_perm 0660
        ipc_gid audio
        bindings [0 1]

        slave {
                pcm "hardware"
                channels 2
                periods  4
                period_time 40000
        }
}
pcm.dmix_1_channels {
        type dmix
        ipc_key 5678293
        ipc_perm 0660
        ipc_gid audio
        bindings [0]

        slave {
                pcm "hardware"
                channels 1
                periods  4
                period_time 40000
        }
}
pcm.hardware {
        type hw
        card 0
        channels 2
        rate 48000
        format S16_LE
}

Best regards

Palaniswamy Vijay

From fa6384f586e442864f22ad4f30b32d89b398d937 Mon Sep 17 00:00:00 2001
From: Vijay Palaniswamy <[email protected]>
Date: Thu, 23 Jul 2020 11:49:10 +0530
Subject: [PATCH] pcm: dmix: fix access to sum-buffer in non-interleaved mixing
mode

When dmix uses non-interleaved mixing mode the offset and step width to sum_buffer was calculated by using the dmix channels instead of the slave channels. This leads to audio distortions due to frame corruption.

example:
- With below configuratio, Do aplay on both device in parallel for audio distortion

pcm.dmix_2_channels {
        type dmix
        ipc_key 5678293
        ipc_perm 0660
        ipc_gid audio
        bindings [0 1]

        slave {
                pcm "hardware"
                channels 2
                periods  4
                period_time 40000
        }
}
pcm.dmix_1_channels {
        type dmix
        ipc_key 5678293
        ipc_perm 0660
        ipc_gid audio
        bindings [0]

        slave {
                pcm "hardware"
                channels 1
                periods  4
                period_time 40000
        }
}
pcm.hardware {
        type hw
        card 0
        channels 2
        rate 48000
        format S16_LE
}
---
 src/pcm/pcm_dmix.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/pcm/pcm_dmix.c +4 -4
index e9343b1..8bce7ac 100644
@@ -212,10 +212,10 @@ static void mix_areas(snd_pcm_direct_t *dmix,
 		do_mix_areas(size,
 			     ((unsigned char *)dst_areas[dchn].addr + dst_areas[dchn].first / 8) + dst_ofs * dst_step,
 			     ((unsigned char *)src_areas[chn].addr + src_areas[chn].first / 8) + src_ofs * src_step,
-			     dmix->u.dmix.sum_buffer + channels * dst_ofs + chn,
+			     dmix->u.dmix.sum_buffer + dmix->shmptr->s.channels * dst_ofs + dchn,
 			     dst_step,
 			     src_step,
-			     channels * sizeof(signed int));
+			     dmix->shmptr->s.channels * sizeof(signed int));
 	}
 }
 
@@ -280,10 +280,10 @@ static void remix_areas(snd_pcm_direct_t *dmix,
 		do_remix_areas(size,
 			       ((unsigned char *)dst_areas[dchn].addr + dst_areas[dchn].first / 8) + dst_ofs * dst_step,
 			       ((unsigned char *)src_areas[chn].addr + src_areas[chn].first / 8) + src_ofs * src_step,
-			       dmix->u.dmix.sum_buffer + channels * dst_ofs + chn,
+			       dmix->u.dmix.sum_buffer + dmix->shmptr->s.channels * dst_ofs + dchn,
 			       dst_step,
 			       src_step,
-			       channels * sizeof(signed int));
+			       dmix->shmptr->s.channels * sizeof(signed int));
 	}
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 82 lines · On Wed, 12 Aug 2020 08:18:25 +0200, Vijay Palaniswamy (RBEI/ECF3) wrote:

Hi All,

When dmix uses non-interleaved mixing mode the offset and step width to sum_buffer was calculated by using the dmix channels instead of the slave channels. This leads to audio distortions due to frame corruption.

Issue happens while doing channel wise mixing of src and destination buffers.

Attached the patch to fix the offset and step width calculation based on slave channels for sum buffer. So mixed data will be saved in respective channels of sum buffer.

Steps to reproduce the issue:

With below configuratio, Do aplay on both device in parallel for audio distortion

pcm.dmix_2_channels {

        type dmix

        ipc_key 5678293

        ipc_perm 0660

        ipc_gid audio

        bindings [0 1]

        slave {

                pcm "hardware"

                channels 2

                periods  4

                period_time 40000

        }

}

pcm.dmix_1_channels {

        type dmix

        ipc_key 5678293

        ipc_perm 0660

        ipc_gid audio

        bindings [0]

        slave {

                pcm "hardware"

                channels 1

                periods  4

                period_time 40000

        }

}

pcm.hardware {

        type hw

        card 0

        channels 2

        rate 48000

        format S16_LE
Quoted 5 lines

}

Best regards

Palaniswamy Vijay

Applied now. Thanks.

Takashi