Skip to contentSkip to conversation

a11y: howto reduce latency with alsa's dmix plugin?

DISCUSSION Halim Sahin 2 participants 9 messages Aug 23, 2009 – Sep 4, 2009

lore
Share & tools
lore
#0 lore raw

Hello,
Is there a way to reduce latency on audiocard if the dmix plugin is in use?
I am asking because there is a strange problem with asistive technologies which are outputing through alsa.
E. G. speech-dispatcher takes almost a half sec to stop the speech-synthesizer.
If the user navigates quickly through menus, there are simultane outputs at a time.
(tested with an usb logitech headset, snd-intel8x0 based card, snd-hda-intel).
The same problem can be reproduced by running mplayer with alsa output driver and pressing
quickly left/right arrow.
You should hear several samples at a time.

Using an sblive card which doesn't use dmix doesn't have such problems.

Using the dmix plugin should audio much faster to avoid this problem.

Please help!!!
Regards
Halim

#1 lore raw

really no idea? Re: a11y: howto reduce latency with alsa's dmix plugin?

Quoted 23 lines · Halim Sahin

Hello,
Is there a way to reduce latency on audiocard if the dmix plugin is in use?
I am asking because there is a strange problem with asistive technologies which are outputing through alsa.
E. G. speech-dispatcher takes almost a half sec to stop the speech-synthesizer.
If the user navigates quickly through menus, there are simultane outputs at a time.
(tested with an usb logitech headset, snd-intel8x0 based card, snd-hda-intel).
The same problem can be reproduced by running mplayer with alsa output driver and pressing
quickly left/right arrow.
You should hear several samples at a time.

Using an sblive card which doesn't use dmix doesn't have such problems.

Using the dmix plugin should audio much faster to avoid this problem.

Please help!!!
Regards
Halim

Signature · 3 lines
Halim Sahin
E-Mail:				
halim.sahin (at) t-online.de
#2 lore raw
In reply to Halim Sahin

At Sun, 23 Aug 2009 09:55:18 +0000 (UTC),

Quoted 17 lines · Halim Sahin

Hello,
Is there a way to reduce latency on audiocard if the dmix plugin is in use?
I am asking because there is a strange problem with asistive technologies which are outputing through alsa.
E. G. speech-dispatcher takes almost a half sec to stop the speech-synthesizer.
If the user navigates quickly through menus, there are simultane outputs at a time.
(tested with an usb logitech headset, snd-intel8x0 based card, snd-hda-intel).
The same problem can be reproduced by running mplayer with alsa output driver and pressing
quickly left/right arrow.
You should hear several samples at a time.

Quoted 3 lines

Using an sblive card which doesn't use dmix doesn't have such problems.

Using the dmix plugin should audio much faster to avoid this problem.

It's a bit hard to guess. This could be the difference of PCM drain implementation between hw and dmix, but a half second is still too long.

Could you prepare a small test case to reproduce the buggy behavior?

thanks,

Takashi

#3 lore raw
Quoted 21 lines · Takashi Iwai

At Sun, 23 Aug 2009 09:55:18 +0000 (UTC),

Quoted 19 lines · Halim Sahin

Hello,
Is there a way to reduce latency on audiocard if the dmix plugin is in use?
I am asking because there is a strange problem with asistive technologies which are outputing through alsa.
E. G. speech-dispatcher takes almost a half sec to stop the speech-synthesizer.
If the user navigates quickly through menus, there are simultane outputs at a time.
(tested with an usb logitech headset, snd-intel8x0 based card, snd-hda-intel).
The same problem can be reproduced by running mplayer with alsa output driver and pressing
quickly left/right arrow.
You should hear several samples at a time.

Using an sblive card which doesn't use dmix doesn't have such problems.

Quoted 7 lines
Quoted 1 line

Using the dmix plugin should audio much faster to avoid this problem.

It's a bit hard to guess. This could be the difference of PCM drain implementation between hw and dmix, but a half second is still too long.

Could you prepare a small test case to reproduce the buggy behavior?

Yes that's easy:
The following should be tested with active dmix.
1. login to a textconsole
2. mplayer -ao alsa your_favourite_file
3. Press space during playback.

Result: it takes about an half sec to stop the playback.

The second test would be:
1. login to a console
2. mplayer -ao alsa:device=hw=0,0 your_file
3. press space during playback
Result:
The playback stops without delay

Hope you can help.
Thanks for your response
Kind regards
Halim

Quoted 4 lines

thanks,

Takashi

Signature · 3 lines
Halim Sahin
E-Mail:				
halim.sahin (at) t-online.de
#4 lore raw

At Tue, 01 Sep 2009 12:32:27 +0200,

Quoted 32 lines · Halim Sahin
Quoted 21 lines · Takashi Iwai

At Sun, 23 Aug 2009 09:55:18 +0000 (UTC),

Quoted 19 lines · Halim Sahin

Hello,
Is there a way to reduce latency on audiocard if the dmix plugin is in use?
I am asking because there is a strange problem with asistive technologies which are outputing through alsa.
E. G. speech-dispatcher takes almost a half sec to stop the speech-synthesizer.
If the user navigates quickly through menus, there are simultane outputs at a time.
(tested with an usb logitech headset, snd-intel8x0 based card, snd-hda-intel).
The same problem can be reproduced by running mplayer with alsa output driver and pressing
quickly left/right arrow.
You should hear several samples at a time.

Using an sblive card which doesn't use dmix doesn't have such problems.

Quoted 7 lines
Quoted 1 line

Using the dmix plugin should audio much faster to avoid this problem.

It's a bit hard to guess. This could be the difference of PCM drain implementation between hw and dmix, but a half second is still too long.

Could you prepare a small test case to reproduce the buggy behavior?

Quoted 7 lines

Yes that's easy:
The following should be tested with active dmix.
1. login to a textconsole
2. mplayer -ao alsa your_favourite_file
3. Press space during playback.

Result: it takes about an half sec to stop the playback.

This isn't a test case to analyze. If the app you mentioned is using libao as the backend, then yes, it's the same issue. If not, it just appears same, but you don't know whether it's the same.

At best, we need a small C code that reproduces the behavior.

Quoted 6 lines

The second test would be:
1. login to a console
2. mplayer -ao alsa:device=hw=0,0 your_file
3. press space during playback
Result:
The playback stops without delay

This could be also the difference whether the device supports pause or not, too.

Takashi

#5 lore raw
Quoted 1 line · Takashi Iwai

At best, we need a small C code that reproduces the behavior.

Ok here is a small example.
It's a modified version of pcm_min.c.
Simply press ctrl+c to reproduce the problematic behaviour. on my machine it takes about an half sek to stop with an usb head which uses dmix.
Using an sblive card (without dmix) stopps immediately.

/*
* This extra small demo sends a random samples to your speakers. */

#include <alsa/asoundlib.h>
#include <signal.h>
#include <unistd.h>
static char *device = "default";

snd_output_t *output = NULL;

unsigned char buffer[16 * 1024]; /* some random data */

snd_pcm_t *handle;

void suspend (int signum)
{
int err;

  printf ("trying to stop\n");
  if ((err = snd_pcm_drop (handle)) < 0)
    printf ("cannot pause\n");

  sleep (1);
  snd_pcm_close (handle);

exit (1);
}

int main (void)
{
int err;

unsigned int i;

snd_pcm_sframes_t frames;

  signal (SIGINT, suspend);
  for (i = 0; i < sizeof (buffer); i++)
    buffer[i] = random () & 0xff;

  if ((err = snd_pcm_open (&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
   {
     printf ("Playback open error: %s\n", snd_strerror (err));
     exit (EXIT_FAILURE);
   }
  if ((err = snd_pcm_set_params (handle,
                                 SND_PCM_FORMAT_U8,
                                 SND_PCM_ACCESS_RW_INTERLEAVED,
                                 1, 48000, 1, 500000)) < 0)
   {                            /* 0.5sec */
     printf ("Playback open error: %s\n", snd_strerror (err));
     exit (EXIT_FAILURE);
   }

  for (i = 0; i < 16; i++)
   {
     frames = snd_pcm_writei (handle, buffer, sizeof (buffer));
     if (frames < 0)
       frames = snd_pcm_recover (handle, frames, 0);
     if (frames < 0)
      {
        printf ("snd_pcm_writei failed: %s\n", snd_strerror (err));
        break;
      }
     if (frames > 0 && frames < (long) sizeof (buffer))
       printf ("Short write (expected %li, wrote %li)\n",
               (long) sizeof (buffer), frames);
   }

snd_pcm_close (handle);
return 0;
}

Hope you can help.
Kind regards
Halim

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw

At Wed, 02 Sep 2009 10:56:17 +0200,

Quoted 9 lines · Halim Sahin
Quoted 1 line · Takashi Iwai

At best, we need a small C code that reproduces the behavior.

Ok here is a small example.
It's a modified version of pcm_min.c.
Simply press ctrl+c to reproduce the problematic behaviour. on my machine it takes about an half sek to stop with an usb head which uses dmix.

Hmm, I cannot reproduce the problem, at least, dmix + HD-audio. After removing sleep(1), it quits immediately.

Doesn't this problem happen if you use usb-audio with "hw" PCM?

It's possible that the behavior of snd_pcm_drop() of usb-audio is different from others because of URB handling.

Takashi

#7 lore raw
Quoted 6 lines · Takashi Iwai

At Wed, 02 Sep 2009 10:56:17 +0200,

Quoted 4 lines · Halim Sahin
Quoted 1 line · Takashi Iwai

At best, we need a small C code that reproduces the behavior.

Quoted 8 lines
Quoted 5 lines

Ok here is a small example.
It's a modified version of pcm_min.c.
Simply press ctrl+c to reproduce the problematic behaviour. on my machine it takes about an half sek to stop with an usb head which uses dmix.

Hmm, I cannot reproduce the problem, at least, dmix + HD-audio. After removing sleep(1), it quits immediately.

Yes you can't, because the program doesn't run.
The sleep shouldn't be removed to see the problem.
When speech-dispatcher is running and someone tries to stop the output, the programm doesn't exit.
Think about it like a pause key :-).

The sblive stopps emmidiately with inserted sleep the usb headset doesn't.

Quoted 1 line

Doesn't this problem happen if you use usb-audio with "hw" PCM?

The pcm_min example of alsalib doesn't run this way. --8<---------------cut here---------------start------------->8---

ALSA lib pcm.c:7125:(snd_pcm_set_params) Sample format not available for PLAYBAC
K: Invalid argument
Playback open error: Invalid argument
--8<---------------cut here---------------end--------------->8---

Can you tell me which sampleformat works with this device???

Quoted 2 lines

It's possible that the behavior of snd_pcm_drop() of usb-audio is different from others because of URB handling.

The stop problem also happends on my laptop with hd audio and ad1981 chip.

with kind regards
Halim

#8 lore raw

At Fri, 04 Sep 2009 11:09:17 +0200,

Quoted 15 lines · Halim Sahin
Quoted 12 lines · Takashi Iwai

At Wed, 02 Sep 2009 10:56:17 +0200,

Quoted 9 lines · Halim Sahin
Quoted 1 line · Takashi Iwai

At best, we need a small C code that reproduces the behavior.

Ok here is a small example.
It's a modified version of pcm_min.c.
Simply press ctrl+c to reproduce the problematic behaviour. on my machine it takes about an half sek to stop with an usb head which uses dmix.

Quoted 5 lines
Quoted 2 lines

Hmm, I cannot reproduce the problem, at least, dmix + HD-audio. After removing sleep(1), it quits immediately.

Yes you can't, because the program doesn't run. The sleep shouldn't be removed to see the problem.

I don't understand here.
So, how is the problem exactly? In which point is the delay expected and where not expected?

You catch a signal and add a delay there -- so the program works, no? If you are checking whether snd_pcm_drop() is executed immediately or not, you should put a printf() after snd_pcm_drop() to indicate when the function call finishes.

Quoted 2 lines

When speech-dispatcher is running and someone tries to stop the output, the programm doesn't exit.

So, "doesn't exit" is the intended behavior?

Quoted 4 lines

Think about it like a pause key :-).

The sblive stopps emmidiately with inserted sleep the usb headset doesn't.

In that sense, HD-audio + dmix works as well. There is no 0.5 sec delay in snd_pcm_drop() itself but the code to sleep immediately.

Quoted 5 lines
Quoted 1 line

Doesn't this problem happen if you use usb-audio with "hw" PCM?

The pcm_min example of alsalib doesn't run this way. --8<---------------cut here---------------start------------->8---

Quoted 7 lines

ALSA lib pcm.c:7125:(snd_pcm_set_params) Sample format not available for PLAYBAC
K: Invalid argument
Playback open error: Invalid argument
--8<---------------cut here---------------end--------------->8---

Can you tell me which sampleformat works with this device???

Use plughw instead.

Quoted 5 lines
Quoted 2 lines

It's possible that the behavior of snd_pcm_drop() of usb-audio is different from others because of URB handling.

The stop problem also happends on my laptop with hd audio and ad1981 chip.

Works fine on my machine. There shouldn't be any difference with the codec chip regarding this, and very unlikely due to the difference of controller chip, too. So, the hardware shouldn't be a problem as long as you use the relatively new version of alsa-driver.

The question might be the alsa-lib version. I've tested only with the latest one, alsa-lib-1.0.21.

Takashi