how to use alsa dmix device to playback two stram in two threads-develop
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to use alsa dmix device to playback two stram in two threads-develop
Hi:
i'm a newbie in linux alsa programing. and now i'm going to write a program that can plays mp3 and wav together. mp3 for background music and wav as the key-sound like ding.. on an embeded system.
and the alsa-lib works correctlly on my platfrom, linux kernel is 2.6.23.9, alsa-lib is 1.0.15.
i can use: aplay -D dmix test.wav& aplay -D dmix test2.wav to hear that two sounds playback correctlly. but when i use the same code to open dmix device in my program. there is some noise when playing sound.
to open the pcm device, but wrong when use dmix. i dumped all the info by using :
snd_pcm_dump(handle, log);
and all the dmix/default/hardware params are same. can anyone give me some suggestion about how to check it? and i'm worndering the layer between "default" and "dmix", and why aplay can works by dmix but my program can not. Hope for kindly help.
i,ve done some test on my program. and i got some messages:
when i put 1024/4096 or some 2^N number bytes data into the pcm_write funciton, the sound works good. by reading "test.sw".
and in my mp3 playback operation, the decompressed buffer size is like 4608, is not fit for 2^N number.
and i guess that i should decode more than one frame and then put the 18432(perhaps) bytes of pcm date to pcm_write funciton.
pcm_write = snd_pcm_writei();
i'm still testting and hoping suggestions.
btw, it's afternoon time @ china and i think it's night on this forum.
and when i use two thread to write audio_data, the sound appears not playing at the same time, part of the first sound plays and then the other.
but when i use the same program to run at two process, in cmd line like:
$ aplaytest test1.sw & aplaytest test2.sw
the sounds played correctlly, both sounds played at the same time, at least heared by my ear.
and seems dmix pluging device support process streams mixing but not thread streams mixing, am i right?
and perhaps i got the wrong alsa config in set_param() funcitons. i paste the dump info here:
I am also getting some scratchy noise output when using dmix to play multiple streams from the same application.
when i forked out one of the streams it seems to work correct.
Did you get any other solution for it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.