summaryrefslogtreecommitdiff
path: root/src/audioio.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/audioio.cc')
-rw-r--r--src/audioio.cc137
1 files changed, 49 insertions, 88 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)