Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
08-25-2008, 10:41 PM
|
#1
|
LQ Newbie
Registered: Aug 2008
Posts: 3
Rep:
|
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.
the code is as below(sample code) :
snd_pcm_open(&pcm_handle, "dmix", SND_PCM_STREAM_PLAYBACK, 0);
set_params(); //same copied from alsa-utils/aplay/aplay.c
while(audio_data)
{
read_audio_data(audio_data, &data_len);
pcm_writei(audio_data. data_len);
}
and the audio_data plays correctlly when i use:
snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
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.
|
|
|
08-26-2008, 02:27 AM
|
#2
|
LQ Newbie
Registered: Aug 2008
Posts: 3
Original Poster
Rep:
|
test-1
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.
|
|
|
08-26-2008, 10:26 PM
|
#3
|
LQ Newbie
Registered: Aug 2008
Posts: 3
Original Poster
Rep:
|
test-2
I tested in my program for use dmix like this:
snd_pcm_open(&pcm_handle, "plug:dmix", 0);
set_params();
while(audio_data)
{
read_audiodata(audio_data, data_len);
snd_pcm_writei(pcm_handle, audio_data, data_len);
}
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:
Plug PCM: Direct Stream Mixing PCM
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 44100
exact rate : 44100 (44100/1)
msbits : 16
buffer_size : 16384
period_size : 1024
period_time : 23219
tick_time : 0
tstamp_mode : NONE
period_step : 1
sleep_min : 0
avail_min : 1024
xfer_align : 1024
start_threshold : 16384
stop_threshold : 16384
silence_threshold: 0
silence_size : 0
boundary : 1073741824
Hardware PCM card 0 'embed platform' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_NONINTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 44100
exact rate : 44100 (44100/1)
msbits : 16
buffer_size : 16384
period_size : 1024
period_time : 23219
tick_time : 10000
tstamp_mode : NONE
period_step : 1
sleep_min : 0
avail_min : 1024
xfer_align : 1024
start_threshold : 1
stop_threshold : 1073741824
silence_threshold: 0
silence_size : 1073741824
boundary : 1073741824
and can anyone help me or just give me some sample code about how to playback two streams in two thread using alsa-lib functions. thanks.
|
|
|
03-26-2009, 04:35 AM
|
#4
|
LQ Newbie
Registered: Mar 2009
Posts: 1
Rep:
|
Hi ,
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.
Thanks
Roy
|
|
|
All times are GMT -5. The time now is 11:35 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|