chiark / gitweb /
plugins/tracklength-gstreamer.c: Rewrite to use `GstDiscoverer'.
[disorder] / lib / uaudio.c
index 7f506ee348e60b05d31b88abfd5a18ed9bb87893..a9ac103cd485bbb0a1570aecf2ae598b2ebb7ad9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2009 Richard Kettlewell
+ * Copyright (C) 2009, 2013 Richard Kettlewell
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -11,7 +11,7 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -24,6 +24,7 @@
 #include "uaudio.h"
 #include "hash.h"
 #include "mem.h"
+#include "log.h"
 
 /** @brief Options for chosen uaudio API */
 static hash *uaudio_options;
@@ -40,6 +41,9 @@ int uaudio_channels;
 /** @brief Whether samples are signed or unsigned */
 int uaudio_signed;
 
+/** @brief Frames of buffer to tolerate inside chosen API */
+int uaudio_buffer;
+
 /** @brief Sample size in bytes
  *
  * NB one sample is a single point sample; up to @c uaudio_channels samples may
@@ -71,7 +75,7 @@ char *uaudio_get(const char *name, const char *default_value) {
   return xstrdup(*valuep);
 }
 
-/** @brief Set sample format 
+/** @brief Set sample format
  * @param rate Sample rate in KHz
  * @param channels Number of channels (i.e. 2 for stereo)
  * @param bits Number of bits per channel (typically 8 or 16)
@@ -96,6 +100,21 @@ void uaudio_set_format(int rate, int channels, int bits, int signed_) {
   uaudio_sample_size = bits / CHAR_BIT;
 }
 
+/** @brief Choose the default audio API by context
+ * @param apis Table of APIs or a null pointer
+ * @param context @ref UAUDIO_API_SERVER or @ref UAUDIO_API_CLIENT
+ * @return Default API or a null pointer
+ */
+const struct uaudio *uaudio_default(const struct uaudio *const *apis,
+                                    unsigned context) {
+  if(apis) {
+    for(int n = 0; apis[n]; ++n)
+      if(apis[n]->flags & context)
+        return apis[n];
+  }
+  return 0;
+}
+
 /*
 Local Variables:
 c-basic-offset:2