Skip to contentSkip to conversation

time stamp and dmix

DISCUSSION jw,Lee 2 participants 6 messages Jun 14, 2005 – Jun 17, 2005

lore
Share & tools
lore

jw,Lee

author
#0 lore raw

Hi,
I use ALSA lib v1.0.6
and I got some question about time stamp and dmix in ALSA lib.

1>I want to make application that use dmix like mplayer with dmix option (one or more application play sound concurrently->this is what I want). then, I must use snd_pcm_dmix_open instead snd_pcm_open?
I tried to find function related snd_pcm_dmix_* in mplayer source, but I cannot find. How can I make it?

2>How can I get the currnt time stamp? I coded like this

    snd_pcm_status_alloca(&alsa_status);
    snd_pcm_status_get_tstamp(alsa_status, &aud_time_stamp);

But I get the answer '0'.

Please give me some advice.

Thanx in advance.

Best Regards.

-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20

#1 lore raw
Quoted 6 lines · jw,Lee

I use ALSA lib v1.0.6
and I got some question about time stamp and dmix in ALSA lib.

1>I want to make application that use dmix like mplayer with dmix option (one or more application play sound concurrently->this is what I want). then, I must use snd_pcm_dmix_open instead snd_pcm_open?

Use snd_pcm_open with an appropriate device name. For dmix, this would be something like "dmix:plughw:X".

In later ALSA versions, sound cards that cannot do hardware mixing automatically use dmix when being accessed with the "default" device name.

Quoted 1 line

2>How can I get the currnt time stamp?

With gettimeofday(). ;-)

What do you mean with "current time"? Real time elapsed since playback started? Number of samples sent to the hardware, or played by the hardware?

Regards,
Clemens

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

author
#2 lore raw
Quoted 9 lines · Clemens Ladisch <clemens <at> ladisch.de> writes:
Quoted 6 lines · jw,Lee

I use ALSA lib v1.0.6
and I got some question about time stamp and dmix in ALSA lib.

1>I want to make application that use dmix like mplayer with dmix option (one or more application play sound concurrently->this is what I want). then, I must use snd_pcm_dmix_open instead snd_pcm_open?

Quoted 6 lines

Use snd_pcm_open with an appropriate device name. For dmix, this would be something like "dmix:plughw:X".

In later ALSA versions, sound cards that cannot do hardware mixing automatically use dmix when being accessed with the "default" device name.

Thanks Clemens.

I figured it out playing sound.
As your comment, I just open "plug:dmixer" with snd_pcm_open. But I still have some problem.

1. somethig different sound output compare with "plughw:0,0" . when I use "plughw:0,0", I get the clean sound.
But I uss "plug:dmixer", there is some noise..:)

2. This is something related with playing speed. when I use "plughw:0,0", my app play sound profectly with various mp3 file. but If I use "plug:dmixer" some mp3 file play fast.

Please give me some advice.

Thanx in advance.
Regard, jw

Quoted 8 lines
Quoted 1 line

2>How can I get the currnt time stamp?

With gettimeofday().

What do you mean with "current time"? Real time elapsed since playback started? Number of samples sent to the hardware, or played by the hardware?

Quoted 9 lines

Regards,
Clemens

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

#3 lore raw
Quoted 2 lines · jw,Lee

when I use "plughw:0,0", I get the clean sound.
But I uss "plug:dmixer", there is some noise..:)

Update alsa-lib, there have been many bugfixes in dmix.

Quoted 3 lines

when I use "plughw:0,0", my app play sound profectly with various mp3 file. but If I use "plug:dmixer" some mp3 file play fast.

The "plug:" should automatically convert sample rates. Which application is this?

Regards,
Clemens

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

author
#4 lore raw

Thank you for reply Clemens.

Quoted 5 lines · Clemens Ladisch <clemens <at> ladisch.de> writes:
Quoted 2 lines · jw,Lee

when I use "plughw:0,0", I get the clean sound.
But I uss "plug:dmixer", there is some noise..:)

Quoted 8 lines

Update alsa-lib, there have been many bugfixes in dmix.

Quoted 3 lines

when I use "plughw:0,0", my app play sound profectly with various mp3 file. but If I use "plug:dmixer" some mp3 file play fast.

The "plug:" should automatically convert sample rates. Which application is this?

--> The application is what I'm making now.. :)
I think aout this problem...and I got some clue..
- the problem(noisy and fast),when I use "plug:dmixer", is something related with sampling rate. the symptoms looks like wrong sampling rate setting.

I use .asoundrc like this
--------------------------------
pcm.!default {
type plug
slave.pcm "dmixer"
}

pcm.dsp0 {
type plug
slave.pcm "dmixer"
}

pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 9216
        rate 44100
    }
}

ctl.mixer0 {
type hw
card 0
}
---------------------------------
and I set the hw parameter like this,

if((err=snd_pcm_open(&hPlayback, pcm_name, stream, 0)) < 0 ){
:
}
if((err=snd_pcm_hw_params_any(hPlayback, hw_params)) < 0 ){
:
}
if((err=snd_pcm_hw_params_set_access(hPlayback, hw_params,

                      SND_PCM_ACCESS_RW_INTERLEAVED)) < 0){

:
}

if( (err=snd_pcm_hw_params_set_format(hPlayback, hw_params,

           SND_PCM_FORMAT_S16)) < 0){

:
}

exact_rate = snd_pcm_hw_params_set_rate_near(hPlayback, hw_params,

                 &frequency_near, &dir);

if( (err=snd_pcm_hw_params_set_channels(hPlayback, hw_params,

                g_aud_channel)) < 0){

:
}

if((err=snd_pcm_hw_params_set_buffer_time_near(hPlayback, hw_params,

              &buffer_time, &dir))<0){

:
}

snd_pcm_hw_params_get_buffer_size(hw_params, &aud_b_size); fprintf(stderr,"BUFFER_SIZE=%d\n", aud_b_size);

if((err=snd_pcm_hw_params(hPlayback, hw_params))<0){
:
}

anything wrong?

I'll trying to update alsa-lib.
thanks Clemens

Quoted 9 lines

Regards,
Clemens

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

#5 lore raw
Quoted 7 lines · jw,Lee
Quoted 5 lines · Clemens Ladisch <clemens <at> ladisch.de> writes:
Quoted 3 lines · jw,Lee

when I use "plughw:0,0", my app play sound profectly with various mp3 file. but If I use "plug:dmixer" some mp3 file play fast.

Quoted 7 lines
Quoted 2 lines

The "plug:" should automatically convert sample rates. Which application is this?

--> The application is what I'm making now.. :)

exact_rate = snd_pcm_hw_params_set_rate_near(hPlayback, hw_params,

                 &frequency_near, &dir);

_set_rate_near() might select another frequency (although this shouldn't happen with the plug plugin). What is the value of frequency_near after the call?

Regards,
Clemens

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click