[Etoys] Small progress of sound delay issue.

Takashi Yamamiya tak at metatoys.org
Wed Nov 29 11:55:56 EST 2006


Hi,

I'm still working with sound issue. There is not great progress
though, I could find some direction how to deal with it. I guess
latency is reduced almost from 0.5 ms to 0.3 ms with this patch.
This is just current status.
(you can use it to copy vm-sound-ALSA to /usr/lib/squeak/3.9-9/)

What I did is;

- Setting periods count to two. (more periods cause more latency).
- Use "plughw:0,0" device instead of "default"

The defect is the sound quality becomes bad! So, I will try another
way. I think mmap is good to the purpose. API document said
snd_pcm_avail_update() is used with mmap.

http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#g8bb836bd0c414b59789d51a5f5379c08

Cheers,
- Takashi
-------------- next part --------------
Index: platforms/unix/vm-sound-ALSA/sqUnixSoundALSA.c
===================================================================
--- platforms/unix/vm-sound-ALSA/sqUnixSoundALSA.c	(revision 1586)
+++ platforms/unix/vm-sound-ALSA/sqUnixSoundALSA.c	(working copy)
@@ -33,7 +33,7 @@
 #include <errno.h>
 
 
-static char *sound_device	= "default";
+static char *sound_device	= "plughw:0,0";
 static char *sound_playback	= "Master";
 static char *sound_capture	= "Capture";
 
@@ -87,9 +87,10 @@
   int			 err;
   snd_pcm_hw_params_t	*hwparams;
   snd_pcm_sw_params_t	*swparams;
-  snd_pcm_uframes_t	 frames;
   unsigned int		 uval;
   int			 dir;
+  int                    periodsCount = 2;
+  snd_pcm_uframes_t      bufferSize;
 
   if (output_handle) sound_Stop();
 
@@ -104,10 +105,15 @@
   snd_pcm_hw_params_set_channels(output_handle, hwparams, output_channels);
   uval= samplesPerSec;
   snd_pcm_hw_params_set_rate_near(output_handle, hwparams, &uval, &dir);
-  frames= frameCount;
-  snd_pcm_hw_params_set_period_size_near(output_handle, hwparams, &frames, &dir);
+  snd(pcm_hw_params_set_periods_near(output_handle, hwparams, &periodsCount, &dir), "pcm_hw_params_set_periods_near");
+  bufferSize = frameCount * periodsCount;
+  snd(pcm_hw_params_set_buffer_size_near(output_handle, hwparams, &bufferSize), "pcm_hw_params_set_buffer_size_near");
+  
   snd(pcm_hw_params(output_handle, hwparams), "sound_Start: snd_pcm_hw_params");
 
+  fprintf(stderr, "Request: frames=%i, periods=%i\n", frameCount, 2);
+  fprintf(stderr, "Result: frames=%i, periods=%i\n", bufferSize / periodsCount, periodsCount);
+
   snd_pcm_sw_params_alloca(&swparams);
   snd(pcm_sw_params_current(output_handle, swparams), "sound_Start: snd_pcm_sw_params_current");
   snd(pcm_sw_params_set_start_threshold(output_handle, swparams, frameCount * SQ_SND_PLAY_START_THRESHOLD), "sound_Start: snd_pcm_sw_params_set_start_threshold");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vm-sound-ALSA
Type: application/octet-stream
Size: 32732 bytes
Desc: not available
Url : http://mailman.laptop.org/pipermail/etoys/attachments/20061130/acb07007/vm-sound-ALSA-0001.obj


More information about the Etoys mailing list