LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 08-25-2008, 10:41 PM   #1
bluefalconjun
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Rep: Reputation: 0
Unhappy 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.
 
Old 08-26-2008, 02:27 AM   #2
bluefalconjun
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Post 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.
 
Old 08-26-2008, 10:26 PM   #3
bluefalconjun
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Post 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.
 
Old 03-26-2009, 04:35 AM   #4
sroyx2k
LQ Newbie
 
Registered: Mar 2009
Posts: 1

Rep: Reputation: 0
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
 
  


Reply

Tags
alsa, dmix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ALSA Won't Recognize Sound Device (Even though I Get Playback) kpworrell Slackware 8 07-08-2006 05:01 AM
Permission to use alsa dmix Ian_Hawdon Linux - Software 10 12-21-2005 09:09 AM
alsa dmix in ubuntu compujas Linux - General 2 08-17-2005 08:54 AM
ALSA dmix + Skype = no go zenith_zth Linux - Hardware 0 06-12-2005 04:38 PM
alsa,amd64,chroot and dmix wrongman Debian 0 03-17-2005 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration