summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audioio.cc137
-rw-r--r--src/audioio.h86
-rw-r--r--src/device.cc6
-rw-r--r--src/device.h5
-rw-r--r--src/mixer.h11
-rw-r--r--src/sink.cc10
-rw-r--r--src/source.cc8
7 files changed, 108 insertions, 155 deletions
diff --git a/src/audioio.cc b/src/audioio.cc
index 75457da..f3dd449 100644
--- a/src/audioio.cc
+++ b/src/audioio.cc
@@ -27,6 +27,8 @@
*/
#include "audioio.h"
+#include <math.h>
+
#include "device.h"
#include "mixer.h"
#include "source.h"
@@ -36,34 +38,6 @@
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
-*/
-
#define MAGIC 0xdeadbeef
struct aio_t {
@@ -160,102 +134,89 @@ int aio_read(struct aio_t *h, char *pcm, unsigned int maxsize)
{
CHECK_HANDLE(h);
- if(h->source) {
- return h->source->readSamples(pcm, maxsize);
- }
+ if(!h->source) return MISSING_HANDLE;
- return MISSING_HANDLE;
+ int s = h->source->readSamples(pcm, maxsize);
+ if(s < 0) return SAMPLE_READ_ERROR;
+ return s;
}
int aio_write(struct aio_t *h, const char *pcm, unsigned int size)
{
CHECK_HANDLE(h);
- if(h->sink) {
- return h->sink->writeSamples(pcm, size);
- }
+ if(!h->sink) return MISSING_HANDLE;
- return MISSING_HANDLE;
+ int s = h->sink->writeSamples(pcm, size);
+ if(s < 0) return SAMPLE_WRITE_ERROR;
+ return s;
}
-int aio_set_playback_mixer_level(struct aio_t *h, unsigned int c, float level)
+static int set_mixer_level(Mixer *m, unsigned int c, float l)
{
- CHECK_HANDLE(h);
+ if(!m) return MISSING_MIXER_HANDLE;
- if(h->sink_mixer) {
- h->sink_mixer->setLevel(c, level);
- return 0;
- }
+ if(m->setLevel(c, l)) return NO_SUCH_CHANNEL;
+ return 0;
+}
- return MISSING_HANDLE;
+int aio_set_playback_mixer_level(struct aio_t *h, unsigned int c, float l)
+{
+ CHECK_HANDLE(h);
+ return set_mixer_level(h->sink_mixer, c, l);
}
-int aio_get_playback_mixer_level(struct aio_t *h, unsigned int c, float *level)
+int aio_set_capture_mixer_level(struct aio_t *h, unsigned int c, float l)
{
CHECK_HANDLE(h);
+ return set_mixer_level(h->source_mixer, c, l);
+}
- if(h->sink_mixer) {
- float l = h->sink_mixer->level(c);
- if(l < -1000) return INVALID_MIXER_LEVEL;
- *level = l;
- return 0;
- }
+static int get_mixer_level(Mixer *m, unsigned int c, float *l)
+{
+ if(!m) return MISSING_MIXER_HANDLE;
- return MISSING_HANDLE;
+ float lvl = m->level(c);
+ if(isinf(lvl)) return INVALID_MIXER_LEVEL;
+ *l = lvl;
+ return 0;
}
-int aio_get_playback_mixer_level_range(struct aio_t *h, float *min, float *max)
+int aio_get_playback_mixer_level(struct aio_t *h, unsigned int c, float *l)
{
CHECK_HANDLE(h);
-
- if(h->sink_mixer) {
- Mixer::range_t r = h->sink_mixer->range();
- *min = r.min;
- *max = r.max;
- return 0;
- }
-
- return MISSING_HANDLE;
+ return get_mixer_level(h->sink_mixer, c, l);
}
-int aio_set_capture_mixer_level(struct aio_t *h, unsigned int c, float level)
+int aio_get_capture_mixer_level(struct aio_t *h, unsigned int c, float *l)
{
CHECK_HANDLE(h);
+ return get_mixer_level(h->source_mixer, c, l);
+}
- if(h->source_mixer) {
- h->source_mixer->setLevel(c, level);
- return 0;
- }
+static int get_mixer_level_range(Mixer *m, float *min, float *max)
+{
+ if(!m) return MISSING_MIXER_HANDLE;
+
+ Mixer::range_t r = m->range();
+ if(isinf(r.min) || isinf(r.max)) return MIXER_ERROR;
- return MISSING_HANDLE;
+ *min = r.min;
+ *max = r.max;
+
+ return 0;
}
-int aio_get_capture_mixer_level(struct aio_t *h, unsigned int c, float *level)
+int aio_get_playback_mixer_level_range(struct aio_t *h, float *min, float *max)
{
CHECK_HANDLE(h);
-
- if(h->source_mixer) {
- float l = h->source_mixer->level(c);
- if(l < -1000) return INVALID_MIXER_LEVEL;
- *level = l;
- return 0;
- }
-
- return MISSING_HANDLE;
+ return get_mixer_level_range(h->sink_mixer, min, max);
}
int aio_get_capture_mixer_level_range(struct aio_t *h, float *min, float *max)
{
CHECK_HANDLE(h);
-
- if(h->source_mixer) {
- Mixer::range_t r = h->source_mixer->range();
- *min = r.min;
- *max = r.max;
- return 0;
- }
-
- return MISSING_HANDLE;
+ return get_mixer_level_range(h->source_mixer, min, max);
}
int aio_get_samplerate(struct aio_t *h)
@@ -265,7 +226,7 @@ int aio_get_samplerate(struct aio_t *h)
if(h->source) return h->source->samplerate();
else if(h->sink) return h->sink->samplerate();
- return MISSING_HANDLE;
+ return MISSING_PCM_HANDLE;
}
int aio_get_buffer_size(struct aio_t *h)
@@ -275,7 +236,7 @@ int aio_get_buffer_size(struct aio_t *h)
if(h->source) return h->source->frames();
else if(h->sink) return h->sink->frames();
- return MISSING_HANDLE;
+ return MISSING_PCM_HANDLE;
}
int aio_close(struct aio_t *h)
diff --git a/src/audioio.h b/src/audioio.h
index 40a445b..7866751 100644
--- a/src/audioio.h
+++ b/src/audioio.h
@@ -36,27 +36,15 @@ extern "C" {
#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
+#define MISSING_MIXER_HANDLE -102
+#define MISSING_PCM_HANDLE -104
+#define MIXER_INIT_FAILED -105
+#define NO_SUCH_CHANNEL -106
+#define SAMPLE_READ_ERROR -107
+#define SAMPLE_WRITE_ERROR -108
+#define MIXER_ERROR -109
+#define COULD_NOT_OPEN_DEVICE -110
+#define INVALID_MIXER_LEVEL -111
struct aio_t;
@@ -109,47 +97,69 @@ int aio_read(struct aio_t *handle, char *pcm, unsigned int maxsize);
*/
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.
+ * Adjust playback channel mixer levels.
* @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.
+ * @return Returns error code.
*/
-int aio_set_mixer_level(struct ai_t *handle, unsigned int channel, float level);
+int aio_set_playback_mixer_level(struct aio_t *handle, unsigned int channel,
+ float level);
/**
- * Get channel mixer levels.
- * @param err An int pointer containing error value if function is unsuccessful.
+ * Get playback channel mixer levels.
* @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.
+ * @param level A pointer to a float which after a successful call will contain
+ * the channel amplification level in dB.
+ * @return Returns error code.
*/
-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);
+/**
+ * Get playback channel amplification range in dB.
+ * @param handle A pointer to the handle to be used.
+ * @param min A pointer to a float in which the min value will be returned.
+ * @param max A pointer to a float in which the max value will be returned.
+ * @return Returns error code.
+ */
int aio_get_playback_mixer_level_range(struct aio_t *handle,
float *min, float *max);
+/**
+ * Adjust capture channel mixer levels.
+ * @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 error code.
+ */
int aio_set_capture_mixer_level(struct aio_t *handle, unsigned int channel,
float level);
+/**
+ * Get channel mixer levels.
+ * @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.
+ * @param level A pointer to a float which after a successful call will contain
+ * the channel amplification level in dB.
+ * @return Returns error code.
+ */
int aio_get_capture_mixer_level(struct aio_t *handle, unsigned int channel,
float *level);
+/**
+ * Get capture channel amplification range in dB.
+ * @param handle A pointer to the handle to be used.
+ * @param min A pointer to a float in which the min value will be returned.
+ * @param max A pointer to a float in which the max value will be returned.
+ * @return Returns error code.
+ */
int aio_get_capture_mixer_level_range(struct aio_t *handle,
float *min, float *max);
diff --git a/src/device.cc b/src/device.cc
index f68a90a..b4c6379 100644
--- a/src/device.cc
+++ b/src/device.cc
@@ -34,12 +34,6 @@ Device::Device(std::string device)
Device::~Device()
{
- /*
- if(handle) {
- snd_pcm_drain(handle);
- snd_pcm_close(handle);
- }
- */
}
std::vector<std::string> Device::mixerNames()
diff --git a/src/device.h b/src/device.h
index 5129d36..d1c3a9e 100644
--- a/src/device.h
+++ b/src/device.h
@@ -31,11 +31,6 @@
#include <vector>
#include <string>
-// Make API behave like ALSA 1.x.x with ALSA 0.9.x
-#define ALSA_PCM_NEW_HW_PARAMS_API
-
-#include <asoundlib.h>
-
#include "mixer.h"
#include "source.h"
#include "sink.h"
diff --git a/src/mixer.h b/src/mixer.h
index 0adcdda..a5e5a98 100644
--- a/src/mixer.h
+++ b/src/mixer.h
@@ -99,17 +99,22 @@ public:
std::vector<std::string> enumValues();
/**
- * Get/set mixer volume level in dB.
- * On error (no such channel) -INF is returned.
+ * Set mixer volume level in dB.
+ * Returns 0 on succes. On error (no such channel) 1 returned.
*/
int setLevel(int channel, float level);
- // 0 on success, 1 on error.
+
+ /**
+ * Get mixer volume level in dB.
+ * On error (no such channel) -INF is returned.
+ */
float level(int channel);
typedef struct {
float min;
float max;
} range_t;
+
/**
* Poll the valid volume range of this mixer in dB.
*/
diff --git a/src/sink.cc b/src/sink.cc
index 4f7cd0f..779dd38 100644
--- a/src/sink.cc
+++ b/src/sink.cc
@@ -45,22 +45,16 @@ int Sink::writeSamples(const char *pcm, size_t size)
{
int rc;
- /*
- if(size < frames * sizeof(short) * channels) {
- throw PcmBufferTooSmall();
- }
- */
-
rc = snd_pcm_writei(handle, pcm, size / sizeof(short));
if(rc == -EPIPE) {
// EPIPE means overrun
- //snd_pcm_prepare(handle);
+ snd_pcm_prepare(handle);
return -2;
} else if (rc < 0) {
return -1; // Read Error
}
- return rc * sizeof(short) /* * channels */ ;
+ return rc * sizeof(short) * _channels;
}
unsigned int Sink::samplerate()
diff --git a/src/source.cc b/src/source.cc
index 187a28e..03faa15 100644
--- a/src/source.cc
+++ b/src/source.cc
@@ -46,12 +46,6 @@ int Source::readSamples(char *pcm, size_t maxsize)
{
int rc;
- /*
- if(size < frames * sizeof(short) * channels) {
- throw PcmBufferTooSmall();
- }
- */
-
rc = snd_pcm_readi(handle, pcm, maxsize / sizeof(short));
if(rc == -EPIPE) {
// EPIPE means overrun
@@ -61,7 +55,7 @@ int Source::readSamples(char *pcm, size_t maxsize)
return -1; // Read Error
}
- return rc * sizeof(short) /* * channels */;
+ return rc * sizeof(short) * _channels;
}
unsigned int Source::samplerate()