summaryrefslogtreecommitdiff
path: root/src/audioio.h
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-09-25 17:08:44 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-09-25 17:08:44 +0200
commit4f6b15ea26b5fa09f300f67e4ce1057c2b39a3aa (patch)
tree45d7bb4a9a90ef603b5a7a65a4d4d4309a7a1538 /src/audioio.h
parent0602763044f0f0f9163f2a888627213347d3dbb7 (diff)
New API, new name, new version.
Diffstat (limited to 'src/audioio.h')
-rw-r--r--src/audioio.h180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/audioio.h b/src/audioio.h
new file mode 100644
index 0000000..f003d02
--- /dev/null
+++ b/src/audioio.h
@@ -0,0 +1,180 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * audioio.h
+ *
+ * Thu Sep 25 15:55:14 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of LibAudioIO.
+ *
+ * LibAudioIO is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * LibAudioIO 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with LibAudioIO; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __LIBAUDIOIO_AUDIOIO_H__
+#define __LIBAUDIOIO_AUDIOIO_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NO_ERROR 0
+
+#define OUT_OF_MEMORY -101
+#define MISSING_HANDLE -102
+
+#define COULD_NOT_OPEN_DEVICE -203
+#define COULD_NOT_SET_HW_PARAMS -204
+#define COULD_NOT_INIT_PARAMS -205
+#define COULD_NOT_SET_ACCESS_MODE -206
+#define COULD_NOT_SET_FORMAT -207
+#define COULD_NOT_SET_CHANNELS -208
+#define COULD_NOT_SET_SAMPLE_RATE -209
+#define COULD_NOT_SET_PERIOD_SIZE -210
+
+#define BUFFER_TOO_SMALL -305
+#define BUFFER_OVERRUN -306
+#define READ_ERROR -307
+#define SHORT_READ -308
+
+#define MIXER_INIT_FAILED -400
+
+#define MIXER_NOT_INITIALISED -401
+#define INVALID_MIXER_LEVEL -402
+#define INVALID_CHANNEL_NUMBER -403
+#define COULD_NOT_SET_MIXER_LEVEL -404
+
+struct aio_t;
+
+/**
+ * Initalise the AudioIO library and connect to a soundcard and a mixer.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param device A string containing the device name to connect to. A list
+ * possible devices can be seen with the 'aplay -L' command. The device
+ * "default" are usually the one needed.
+ * @param mixer A string containing the mixer interface to connect to. A list
+ * of possible interfaces can be seen with the 'amixer scontrols' command.
+ * Usually the interface "Capture" is the one needed.
+ * @param samplerate An unsigned integer containing the desired samplerate in
+ * Hertz.
+ * @param channels An unsigned integer containing the desired number of
+ * channels. The channel samples will be interleaved in the data stream whe
+ * ai_read is called.
+ * @return A pointer to the newly created handle or NULL on failure.
+ */
+struct aio_t *aio_init(int *err,
+ const char *playback_device,
+ const char *playback_mixer,
+ const char *capture_device,
+ const char *capture_mixer,
+ unsigned int samplerate,
+ unsigned int channels);
+
+/**
+ * Read samples from the soundcard.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param handle A pointer to the handle to be used.
+ * @param pcm Buffer cotaining which will be filled with samples.
+ * @param maxsize The maximum number of bytes (not samples) to read.
+ * @return Returns the number of bytes (not samples) read or -1 on error.
+ * NOTE: to get the number of samples read, devide the return value with the
+ * sample width (2 bytes / 16 bits) and the number of interleaved channels
+ * (usually 1 or 2).
+ */
+int aio_read(struct aio_t *handle, char *pcm, unsigned int maxsize);
+
+/**
+ * Write samples to the soundcard.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param handle A pointer to the handle to be used.
+ * @param size The maximum number of bytes (not samples) to be written.
+ * @return Returns the number of bytes (not samples) written or -1 on error.
+ * NOTE: to get the number of samples read, devide the return value with the
+ * sample width (2 bytes / 16 bits) and the number of interleaved channels
+ * (usually 1 or 2).
+ */
+int aio_write(struct aio_t *handle, const char *pcm, unsigned int size);
+
+#if 0
+/**
+ * Adjust channel mixer levels.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param handle A pointer to the handle to be used.
+ * @param channel The channel number to set mixer level of. 0 or 1 should be
+ * used for the two channels of a stereo interface.
+ * @param level The mixer level to set in dB
+ * @return Returns -1 on error 0 otherwise.
+ */
+int aio_set_mixer_level(struct ai_t *handle, unsigned int channel, float level);
+
+/**
+ * Get channel mixer levels.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param handle A pointer to the handle to be used.
+ * @param channel The channel number to get mixer level of. 0 or 1 should be
+ * used for the two channels of a stereo interface.
+ * @return Returns the level in dB.
+ */
+int aio_get_mixer_level(struct aio_t *handle, unsigned int channel,
+ float *level);
+
+int aio_get_mixer_level_range(struct aio_t *handle, float *min, float *max);
+#endif
+
+int aio_set_playback_mixer_level(struct aio_t *handle, unsigned int channel,
+ float level);
+
+int aio_get_playback_mixer_level(struct aio_t *handle, unsigned int channel,
+ float *level);
+
+int aio_get_playback_mixer_level_range(struct aio_t *handle,
+ float *min, float *max);
+
+int aio_set_capture_mixer_level(struct aio_t *handle, unsigned int channel,
+ float level);
+
+int aio_get_capture_mixer_level(struct aio_t *handle, unsigned int channel,
+ float *level);
+
+int aio_get_capture_mixer_level_range(struct aio_t *handle,
+ float *min, float *max);
+
+/**
+ * Get actual samplerate.
+ * The samplerate set in ai_init may or may not match a possible samplerate for
+ * the audio hardware and therefore the ALSA library might decide to use another
+ * samplerate than the one specified.
+ * This function can be called to obtain the actual samplerate that the hardware
+ * has been configured to use.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param handle A pointer to the handle to be used.
+ * @return The samplerate as an integer or -1 on error.
+ */
+int aio_get_samplerate(struct aio_t *handle);
+
+/**
+ * Close and free the handle.
+ * @param err An int pointer containing error value if function is unsuccessful.
+ * @param handle A pointer to the handle to be closed.
+ */
+int aio_close(struct aio_t *handle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif/*__LIBAUDIOIO_AUDIOIO_H__*/