summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-02 13:51:34 -0500
committerXANTRONIX Development2022-02-02 13:51:34 -0500
commitd008e5271eafe044233db6d158bf91c9efa39331 (patch)
treeca332f0ede4e59571e029f93fc778f9be981eec9
parentc5c552efb3516b516a7ea703687e2a55573c9ffd (diff)
downloadxas-d008e5271eafe044233db6d158bf91c9efa39331.tar.gz
xas-d008e5271eafe044233db6d158bf91c9efa39331.tar.bz2
xas-d008e5271eafe044233db6d158bf91c9efa39331.zip
Channel count first seems...nicer, somehow.
-rw-r--r--examples/say.c6
-rw-r--r--examples/test.c6
-rw-r--r--include/xas/audio.h10
-rw-r--r--include/xas/mixer.h4
-rw-r--r--include/xas/riff.h2
-rw-r--r--src/audio.c20
-rw-r--r--src/mixer.c12
-rw-r--r--src/riff.c42
-rw-r--r--src/synth.c2
-rw-r--r--src/vox.c2
10 files changed, 53 insertions, 53 deletions
diff --git a/examples/say.c b/examples/say.c
index d72c7ff..389e338 100644
--- a/examples/say.c
+++ b/examples/say.c
@@ -95,9 +95,9 @@ int main(int argc, char **argv) {
}
if ((output = xas_riff_new_file(argv[1],
+ XAS_AUDIO_STREAM_STEREO,
XAS_AUDIO_STREAM_PCM_16_BIT,
sample_rate,
- XAS_AUDIO_STREAM_STEREO,
O_WRONLY | O_CREAT | O_TRUNC)) == NULL) {
goto error_riff_new_file;
}
@@ -124,9 +124,9 @@ int main(int argc, char **argv) {
goto error_synth_new_r;
}
- if ((mixer = xas_mixer_new(XAS_AUDIO_STREAM_PCM_16_BIT,
+ if ((mixer = xas_mixer_new(XAS_AUDIO_STREAM_STEREO,
+ XAS_AUDIO_STREAM_PCM_16_BIT,
sample_rate,
- XAS_AUDIO_STREAM_STEREO,
buffer_size)) == NULL) {
goto error_mixer_new;
}
diff --git a/examples/test.c b/examples/test.c
index 56632a5..779434c 100644
--- a/examples/test.c
+++ b/examples/test.c
@@ -83,9 +83,9 @@ int main(int argc, char **argv) {
}
if ((wave = xas_riff_new_file(argv[1],
+ XAS_AUDIO_STREAM_STEREO,
XAS_AUDIO_STREAM_PCM_16_BIT,
sample_rate,
- XAS_AUDIO_STREAM_STEREO,
O_WRONLY | O_CREAT | O_TRUNC)) == NULL) {
goto error_riff_new_file;
}
@@ -108,9 +108,9 @@ int main(int argc, char **argv) {
goto error_synth_new_r;
}
- if ((mixer = xas_mixer_new(XAS_AUDIO_STREAM_PCM_16_BIT,
+ if ((mixer = xas_mixer_new(XAS_AUDIO_STREAM_STEREO,
+ XAS_AUDIO_STREAM_PCM_16_BIT,
sample_rate,
- XAS_AUDIO_STREAM_STEREO,
buffer_size)) == NULL) {
goto error_mixer_new;
}
diff --git a/include/xas/audio.h b/include/xas/audio.h
index 9c40dd8..8d4469d 100644
--- a/include/xas/audio.h
+++ b/include/xas/audio.h
@@ -33,9 +33,9 @@ typedef void (*xas_audio_cleanup)(void *ctx,
struct _xas_audio_stream {
enum xas_audio_stream_type type;
- size_t sample_size,
- sample_rate,
- channels;
+ size_t channels,
+ sample_size,
+ sample_rate;
size_t buffer_size,
buffer_count;
@@ -54,17 +54,17 @@ struct _xas_audio_stream {
xas_audio_stream *xas_audio_stream_new_sink(xas_audio_drain drain,
xas_audio_cleanup cleanup,
void *ctx,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size);
xas_audio_stream *xas_audio_stream_new_source(xas_audio_fill fill,
xas_audio_cleanup cleanup,
void *ctx,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size);
void xas_audio_stream_destroy(xas_audio_stream *stream);
diff --git a/include/xas/mixer.h b/include/xas/mixer.h
index 9fd77cb..73fd363 100644
--- a/include/xas/mixer.h
+++ b/include/xas/mixer.h
@@ -25,9 +25,9 @@ typedef struct _xas_mixer {
size_t buffer_size;
} xas_mixer;
-xas_mixer *xas_mixer_new(size_t sample_size,
+xas_mixer *xas_mixer_new(size_t channels,
+ size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size);
void xas_mixer_destroy(xas_mixer *mixer);
diff --git a/include/xas/riff.h b/include/xas/riff.h
index ca78af1..f78e9e9 100644
--- a/include/xas/riff.h
+++ b/include/xas/riff.h
@@ -50,9 +50,9 @@ typedef struct _xas_riff xas_riff;
#pragma pack(pop)
xas_audio_stream *xas_riff_new_file(const char *path,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
int flags);
xas_audio_stream *xas_riff_open_file(const char *path, int flags);
diff --git a/src/audio.c b/src/audio.c
index 641bb93..f5dc5ee 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -8,23 +8,23 @@ static xas_audio_stream *stream_new(enum xas_audio_stream_type type,
void *callback,
xas_audio_cleanup cleanup,
void *ctx,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size) {
xas_audio_stream *stream;
size_t total = sizeof(xas_audio_stream)
- + sample_size * channels * buffer_size;
+ + channels * sample_size * buffer_size;
if ((stream = malloc(total)) == NULL) {
goto error_malloc_stream;
}
stream->type = type;
+ stream->channels = channels;
stream->sample_size = sample_size;
stream->sample_rate = sample_rate;
- stream->channels = channels;
stream->buffer_size = buffer_size;
stream->buffer_count = 0;
stream->callback = callback;
@@ -40,34 +40,34 @@ error_malloc_stream:
xas_audio_stream *xas_audio_stream_new_sink(xas_audio_drain drain,
xas_audio_cleanup cleanup,
void *ctx,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size) {
return stream_new(XAS_AUDIO_STREAM_SINK,
drain,
cleanup,
ctx,
+ channels,
sample_size,
sample_rate,
- channels,
buffer_size);
}
xas_audio_stream *xas_audio_stream_new_source(xas_audio_fill fill,
xas_audio_cleanup cleanup,
void *ctx,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size) {
return stream_new(XAS_AUDIO_STREAM_SOURCE,
fill,
cleanup,
ctx,
+ channels,
sample_size,
sample_rate,
- channels,
buffer_size);
}
@@ -100,7 +100,7 @@ error_stream_drain:
}
static inline void *ptr(xas_audio_stream *stream, void *buf, size_t index) {
- return ((uint8_t *)buf) + stream->sample_size * stream->channels * index;
+ return ((uint8_t *)buf) + stream->channels * stream->sample_size * index;
}
ssize_t xas_audio_stream_write(xas_audio_stream *stream,
@@ -118,7 +118,7 @@ ssize_t xas_audio_stream_write(xas_audio_stream *stream,
memcpy(ptr(stream, stream + 1, stream->buffer_count),
ptr(stream, samples, index_i),
- remaining * stream->sample_size * stream->channels);
+ remaining * stream->channels * stream->sample_size);
if (stream->drain(stream->ctx,
ptr(stream, stream + 1, 0),
@@ -159,7 +159,7 @@ ssize_t xas_audio_stream_write(xas_audio_stream *stream,
*/
memcpy(ptr(stream, stream + 1, stream->buffer_count),
ptr(stream, samples, index_i),
- remaining * stream->sample_size * stream->channels);
+ remaining * stream->channels * stream->sample_size);
index_i += remaining;
diff --git a/src/mixer.c b/src/mixer.c
index 32c557d..9706b09 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -71,7 +71,7 @@ static ssize_t mixer_fill(xas_mixer *mixer,
memset(mixer->buf,
'\0',
- output->sample_size * output->channels * output->buffer_size);
+ output->channels * output->sample_size * output->buffer_size);
while (input) {
void (*mixer_apply)(int16_t *,
@@ -120,7 +120,7 @@ static ssize_t mixer_fill(xas_mixer *mixer,
memcpy(samples,
mixer->buf,
- total * output->sample_size * output->channels);
+ total * output->channels * output->sample_size);
return total;
@@ -129,9 +129,9 @@ error_audio_read_stream:
return -1;
}
-xas_mixer *xas_mixer_new(size_t sample_size,
+xas_mixer *xas_mixer_new(size_t channels,
+ size_t sample_size,
size_t sample_rate,
- size_t channels,
size_t buffer_size) {
xas_mixer *mixer;
@@ -139,16 +139,16 @@ xas_mixer *xas_mixer_new(size_t sample_size,
goto error_malloc_mixer;
}
- if ((mixer->buf = malloc(sample_size * channels * buffer_size)) == NULL) {
+ if ((mixer->buf = malloc(channels * sample_size * buffer_size)) == NULL) {
goto error_malloc_buf;
}
if ((mixer->output = xas_audio_stream_new_source((xas_audio_fill)mixer_fill,
NULL,
mixer,
+ channels,
sample_size,
sample_rate,
- channels,
buffer_size)) == NULL) {
goto error_audio_stream_new_source;
}
diff --git a/src/riff.c b/src/riff.c
index a920d10..0184a30 100644
--- a/src/riff.c
+++ b/src/riff.c
@@ -12,9 +12,9 @@ struct _xas_riff {
int fd;
size_t size;
- size_t sample_size,
- sample_rate,
- channels;
+ size_t channels,
+ sample_size,
+ sample_rate;
};
static int header_write(xas_riff *riff) {
@@ -70,9 +70,9 @@ error_io:
}
static xas_riff *new_file(const char *path,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
int flags) {
xas_riff *riff;
@@ -88,9 +88,9 @@ static xas_riff *new_file(const char *path,
riff->file = path;
riff->size = 0;
+ riff->channels = channels;
riff->sample_size = sample_size;
riff->sample_rate = sample_rate;
- riff->channels = channels;
if (header_write(riff) < 0) {
goto error_header_write;
@@ -167,9 +167,9 @@ static int wave_header_parse(xas_riff *riff,
goto error_invalid_wave_data_format_id;
}
+ riff->channels = header->wave.channels;
riff->sample_size = header->wave.sample_size;
riff->sample_rate = header->wave.sample_rate;
- riff->channels = header->wave.channels;
return 0;
@@ -199,9 +199,9 @@ static xas_riff *open_fd(int fd) {
riff->file = NULL;
riff->fd = fd;
riff->size = 0;
+ riff->channels = 0;
riff->sample_size = 0;
riff->sample_rate = 0;
- riff->channels = 0;
if ((readlen = read(fd, &header, sizeof(header))) < 0) {
goto error_read;
@@ -246,9 +246,9 @@ static xas_riff *open_file(const char *path, int flags) {
riff->file = path;
riff->size = 0;
+ riff->channels = 0;
riff->sample_size = 0;
riff->sample_rate = 0;
- riff->channels = 0;
if (lseek(riff->fd, 0, SEEK_SET) < 0) {
goto error_lseek;
@@ -299,8 +299,8 @@ static ssize_t audio_drain(xas_riff *riff,
void *samples,
size_t count,
xas_audio_stream *stream) {
- size_t len = count * stream->sample_size
- * stream->channels;
+ size_t len = count * stream->channels
+ * stream->sample_size;
ssize_t wrlen;
@@ -310,7 +310,7 @@ static ssize_t audio_drain(xas_riff *riff,
riff->size += wrlen;
- return wrlen / stream->sample_size / stream->channels;
+ return wrlen / stream->channels / stream->sample_size;
error_write:
return -1;
@@ -320,8 +320,8 @@ static ssize_t audio_fill(xas_riff *riff,
void *samples,
size_t count,
xas_audio_stream *stream) {
- size_t len = count * stream->sample_size
- * stream->channels;
+ size_t len = count * stream->channels
+ * stream->sample_size;
ssize_t rdlen;
@@ -329,24 +329,24 @@ static ssize_t audio_fill(xas_riff *riff,
goto error_read;
}
- return rdlen / stream->sample_size / stream->channels;
+ return rdlen / stream->channels / stream->sample_size;
error_read:
return -1;
}
xas_audio_stream *xas_riff_new_file(const char *path,
+ size_t channels,
size_t sample_size,
size_t sample_rate,
- size_t channels,
int flags) {
xas_audio_stream *stream;
xas_riff *riff;
if ((riff = new_file(path,
+ channels,
sample_size,
sample_rate,
- channels,
flags)) == NULL) {
goto error_new_file;
}
@@ -355,9 +355,9 @@ xas_audio_stream *xas_riff_new_file(const char *path,
if ((stream = xas_audio_stream_new_sink((xas_audio_drain)audio_drain,
(xas_audio_cleanup)close_file,
riff,
+ channels,
sample_size,
sample_rate,
- channels,
4096)) == NULL) {
goto error_audio_stream_new_sink;
}
@@ -365,9 +365,9 @@ xas_audio_stream *xas_riff_new_file(const char *path,
if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill,
(xas_audio_cleanup)close_file,
riff,
+ channels,
sample_size,
sample_rate,
- channels,
4096)) == NULL) {
goto error_audio_stream_new_sink;
}
@@ -394,9 +394,9 @@ xas_audio_stream *xas_riff_open_file(const char *path, int flags) {
if ((stream = xas_audio_stream_new_sink((xas_audio_drain)audio_drain,
(xas_audio_cleanup)close_file,
riff,
+ riff->channels,
riff->sample_size,
riff->sample_rate,
- riff->channels,
4096)) == NULL) {
goto error_audio_stream_new_sink;
}
@@ -404,9 +404,9 @@ xas_audio_stream *xas_riff_open_file(const char *path, int flags) {
if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill,
(xas_audio_cleanup)close_file,
riff,
+ riff->channels,
riff->sample_size,
riff->sample_rate,
- riff->channels,
4096)) == NULL) {
goto error_audio_stream_new_sink;
}
@@ -432,9 +432,9 @@ xas_audio_stream *xas_riff_open_fd(int fd) {
if ((stream = xas_audio_stream_new_source((xas_audio_fill)audio_fill,
(xas_audio_cleanup)close_file,
riff,
+ riff->channels,
riff->sample_size,
riff->sample_rate,
- riff->channels,
4096)) == NULL) {
goto error_audio_stream_new_sink;
}
diff --git a/src/synth.c b/src/synth.c
index a482875..2e77748 100644
--- a/src/synth.c
+++ b/src/synth.c
@@ -45,9 +45,9 @@ xas_audio_stream *xas_synth_new(size_t sample_size,
if ((stream = xas_audio_stream_new_source((xas_audio_fill)synth_fill,
(xas_audio_cleanup)synth_cleanup,
synth,
+ XAS_AUDIO_STREAM_MONO,
sample_size,
sample_rate,
- XAS_AUDIO_STREAM_MONO,
buffer_size)) == NULL) {
goto error_audio_stream_new_source;
}
diff --git a/src/vox.c b/src/vox.c
index df3e084..7fec432 100644
--- a/src/vox.c
+++ b/src/vox.c
@@ -275,8 +275,8 @@ xas_audio_stream *xas_vox_stream_new(xas_vox *vox) {
return xas_audio_stream_new_source((xas_audio_fill)vox_fill,
(xas_audio_cleanup)vox_cleanup,
vox,
+ XAS_AUDIO_STREAM_MONO,
vox->sample_size,
vox->sample_rate,
- XAS_AUDIO_STREAM_MONO,
vox->buffer_size);
}