chiark / gitweb /
Uniform audio backend for Core Audio. There is an untested OSS one
[disorder] / lib / uaudio.h
diff --git a/lib/uaudio.h b/lib/uaudio.h
new file mode 100644 (file)
index 0000000..6b0dea1
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * This file is part of DisOrder.
+ * Copyright (C) 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * 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/>.
+ */
+
+/** @file lib/uaudio.h
+ * @brief Uniform audio interface
+ */
+
+#ifndef UAUDIO_H
+#define UAUDIO_H
+
+/** @brief Callback to get audio data
+ * @param buffer Where to put audio data
+ * @param max_samples How many samples to supply
+ * @param userdata As passed to uaudio_open()
+ * @return Number of samples filled
+ *
+ * One sample is a single 16-bit signed value.
+ */
+typedef size_t uaudio_callback(int16_t *buffer,
+                               size_t max_samples,
+                               void *userdata);
+
+/** @brief Audio API definition */
+struct uaudio {
+  /** @brief Name of this API */
+  const char *name;
+
+  /** @brief List of options, terminated by NULL */
+  const char *const *options;
+
+  /** @brief Do slow setup
+   * @param ua Handle returned by uaudio_open()
+   * @param callback Called for audio data
+   * @param userdata Passed to @p callback
+   *
+   * This does resource-intensive setup for the output device.
+   *
+   * For instance it might open mixable audio devices or network sockets.  It
+   * will create any background thread required.  However, it must not exclude
+   * other processes from outputting sound.
+   */
+  void (*start)(uaudio_callback *callback,
+                void *userdata);
+
+  /** @brief Tear down
+   * @param ua Handle returned by uaudio_open()
+   *
+   * This undoes the effect of @c start.
+   */
+  void (*stop)(void);
+
+  /** @brief Enable output
+   *
+   * A background thread will start calling @c callback as set by @c
+   * start and playing the audio data received from it.
+   */
+  void (*activate)(void);
+
+  /** @brief Disable output
+   *
+   * The background thread will stop calling @c callback.
+   */
+  void (*deactivate)(void);
+
+};
+                                
+void uaudio_set(const char *name, const char *value);
+const char *uaudio_get(const char *name);
+
+#if HAVE_COREAUDIO_AUDIOHARDWARE_H
+extern const struct uaudio uaudio_coreaudio;
+#endif
+
+#if HAVE_ALSA_ASOUNDLIB_H
+extern const struct uaudio uaudio_alsa;
+#endif
+
+#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST
+extern const struct uaudio uaudio_oss;
+#endif
+
+extern const struct uaudio uaudio_rtp;
+
+extern const struct uaudio *uaudio_apis[];
+
+#endif /* UAUDIO_H */
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+indent-tabs-mode:nil
+End:
+*/