[xiph-cvs] cvs commit: ices/src im_alsa.c im_alsa.h

Karl Heyes karl at xiph.org
Mon Mar 1 12:58:03 PST 2004



karl        04/03/01 15:58:03

  Modified:    src      im_alsa.c im_alsa.h
  Log:
  allow more xml configuration for the alsa input

Revision  Changes    Path
1.8       +26 -11    ices/src/im_alsa.c

Index: im_alsa.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_alsa.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- im_alsa.c	17 Jan 2004 04:24:10 -0000	1.7
+++ im_alsa.c	1 Mar 2004 20:58:02 -0000	1.8
@@ -1,7 +1,7 @@
 /* im_alsa.c
  * - Raw PCM input from ALSA devices
  *
- * $Id: im_alsa.c,v 1.7 2004/01/17 04:24:10 karl Exp $
+ * $Id: im_alsa.c,v 1.8 2004/03/01 20:58:02 karl Exp $
  *
  * by Jason Chu <jchu at uvic.ca>, based
  * on im_oss.c which is...
@@ -159,7 +159,8 @@
     int format = AFMT_S16_LE;
     int channels, rate;
     int use_metadata = 1; /* Default to on */
-    unsigned int buffered_time;
+    unsigned int buffered_time, exact_rate;
+    int dir;
 
     snd_pcm_stream_t stream = SND_PCM_STREAM_CAPTURE;
     snd_pcm_hw_params_t *hwparams;
@@ -178,6 +179,8 @@
     s->fd = NULL; /* Set it to something invalid, for now */
     s->rate = 44100; /* Defaults */
     s->channels = 2; 
+    s->buffer_time = 500000;
+    s->periods = 2;
 
     thread_mutex_create(&s->metadatalock);
 
@@ -195,6 +198,10 @@
             use_metadata = atoi(current->value);
         else if(!strcmp(current->name, "metadatafilename"))
             ices_config->metadata_filename = current->value;
+        else if(!strcmp(current->name, "buffer-time"))
+            s->buffer_time = atoi (current->value) * 1000;
+        else if(!strcmp(current->name, "periods"))
+            s->periods = atoi (current->value);
         else
             LOG_WARN1("Unknown parameter %s for alsa module", current->name);
 
@@ -224,9 +231,17 @@
         LOG_ERROR1("Couldn't set sample format to SND_PCM_FORMAT_S16_LE: %s", snd_strerror(err));
         goto fail;
     }
-    if ((err = snd_pcm_hw_params_set_rate_near(s->fd, hwparams, &s->rate, 0)) < 0)
+    exact_rate = s->rate;
+    err = snd_pcm_hw_params_set_rate_near(s->fd, hwparams, &exact_rate, 0);
+    if (err < 0)
     {
-        LOG_ERROR1("Error setting rate: %s", snd_strerror(err));
+        LOG_ERROR2("Could not set sample rate to %d: %s", exact_rate, snd_strerror(err));
+        goto fail;
+    }
+    if (exact_rate != s->rate)
+    {
+        LOG_WARN2("samplerate %d Hz not supported by your hardware try using "
+                "%d instead", s->rate, exact_rate);
         goto fail;
     }
     if ((err = snd_pcm_hw_params_set_channels(s->fd, hwparams, s->channels)) < 0)
@@ -234,15 +249,14 @@
         LOG_ERROR1("Error setting channels: %s", snd_strerror(err));
         goto fail;
     }
-    if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, 2, 0)) < 0)
+    if ((err = snd_pcm_hw_params_set_buffer_time_near(s->fd, hwparams, &s->buffer_time, &dir)) < 0)
     {
-        LOG_ERROR1("Error setting periods: %s", snd_strerror(err));
+        LOG_ERROR2("Error setting buffer time %u: %s", s->buffer_time, snd_strerror(err));
         goto fail;
     }
-    buffered_time = 500000;
-    if ((err = snd_pcm_hw_params_set_buffer_time_near(s->fd, hwparams, &buffered_time, 0)) < 0)
+    if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, s->periods, 0)) < 0)
     {
-        LOG_ERROR1("Error setting buffersize: %s", snd_strerror(err));
+        LOG_ERROR2("Error setting %u periods: %s", s->periods, snd_strerror(err));
         goto fail;
     }
     if ((err = snd_pcm_hw_params(s->fd, hwparams)) < 0)
@@ -252,8 +266,9 @@
     }
 
     /* We're done, and we didn't fail! */
-    LOG_INFO3("Opened audio device %s at %d channel(s), %d Hz", 
-            device, s->channels, s->rate);
+    LOG_INFO1 ("Opened audio device %s", device);
+    LOG_INFO4 ("using %d channel(s), %d Hz, buffer %u ms (%u periods)",
+            s->channels, s->rate, s->buffer_time/1000, s->periods);
 
     if(use_metadata)
     {

<p><p>1.5       +3 -1      ices/src/im_alsa.h

Index: im_alsa.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_alsa.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- im_alsa.h	11 Jan 2004 03:11:05 -0000	1.4
+++ im_alsa.h	1 Mar 2004 20:58:02 -0000	1.5
@@ -1,7 +1,7 @@
 /* im_alsa.h
  * - read pcm data from oss devices
  *
- * $Id: im_alsa.h,v 1.4 2004/01/11 03:11:05 karl Exp $
+ * $Id: im_alsa.h,v 1.5 2004/03/01 20:58:02 karl Exp $
  *
  * by Jason Chu  <jchu at uvic.ca>, based
  * on im_oss.c which is...
@@ -25,6 +25,8 @@
 {
     unsigned int rate;
     int channels;
+    unsigned buffer_time;
+    unsigned periods;
 
     snd_pcm_t *fd;
     char **metadata;

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list