1

On an embedded system, I have discovered that only one application can use the sound card simultaneously. To my limited knowledge, to solve the issue, the ALSA provides the dmix plug-in to perform the mixing in the user-space, and thus to allow multiple applications to share the sound card.

While trying to figure out how to use the dmix, I have stumbled on an issue. When playing an audio file (stereo, 16-bit, 44.1KHz), the audio as if overlapping with itself, in a weird echo effect, with the number of echos growing as a snowball further down the playback time. (Already 10 seconds into playback, the sound "intensifies" to the point where I have to stop it for fear of permanent damage to the speaker.)

From my perception, only the first second of audio is played back normally, and the weirdness starts around the second second. I have tried to tune the buffering settings of aplay to no avail: the effect is not related to the buffering.

This works:

aplay /mnt/annie-honestly.wav

But this displays the weird echo effect:

aplay -Dplug:dmix /mnt/annie-honestly.wav

I have tried to google the issue up, but I'm not even sure how to call the effect/problem, and I found nothing in the flood of the other ALSA problems.

P.S. Linux v3.18.24, ALSA-lib/-utils v1.0.29. The hardware: FreeScale i.MX35 with the SGTL5000 sound chip (used in 48KHz mode).

  • The code in alsa-lib's src/pcm/pcm_dmix_generic.c does not actually support atomic memory accesses. Somebody would need to add those. – CL. Jun 8 '16 at 18:29
  • @CL, can you elaborate? probably a link? What is the purpose of those cmpxchgs? Do you imply that the dmix is lockless and relies on the atomic ops to perform mixing/muxing? (I'm total noob in alsa, sorry.) – Dummy00001 Jun 9 '16 at 7:59
  • Yes. The code needs to be ported to your architecture. – CL. Jun 9 '16 at 8:25
  • @CL, Thanks for the information! P.S. Why the generic code doesn't use the C11's stdatomic? Is it feasible to employ the stdatomic for the purpose? – Dummy00001 Jun 9 '16 at 8:31
  • The code is older than C11. In theory, it should be possible. – CL. Jun 9 '16 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.