chiark / gitweb /
Merge tag 'branchpoint-5.1' into release
[disorder] / lib / uaudio.c
index 3625901eeccc44e1ef29c3c199ba133c9ae96b6a..343290df1fb68006d30731f1f431d3d4343d5f33 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
@@ -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
@@ -50,18 +54,25 @@ size_t uaudio_sample_size;
 
 /** @brief Set a uaudio option */
 void uaudio_set(const char *name, const char *value) {
+  if(!value) {
+    if(uaudio_options)
+      hash_remove(uaudio_options, name);
+    return;
+  }
   if(!uaudio_options)
     uaudio_options = hash_new(sizeof(char *));
   value = xstrdup(value);
   hash_add(uaudio_options, name, &value, HASH_INSERT_OR_REPLACE);
 }
 
-/** @brief Set a uaudio option */
-char *uaudio_get(const char *name) {
-  const char *value = (uaudio_options ?
-                       *(char **)hash_find(uaudio_options, name)
-                       : NULL);
-  return value ? xstrdup(value) : NULL;
+/** @brief Get a uaudio option */
+char *uaudio_get(const char *name, const char *default_value) {
+  if(!uaudio_options)
+    return default_value ? xstrdup(default_value) : 0;
+  char **valuep = hash_find(uaudio_options, name);
+  if(!valuep)
+    return default_value ? xstrdup(default_value) : 0;
+  return xstrdup(*valuep);
 }
 
 /** @brief Set sample format