diff options
author | XANTRONIX Development | 2022-02-02 13:51:34 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-02 13:51:34 -0500 |
commit | d008e5271eafe044233db6d158bf91c9efa39331 (patch) | |
tree | ca332f0ede4e59571e029f93fc778f9be981eec9 /src | |
parent | c5c552efb3516b516a7ea703687e2a55573c9ffd (diff) | |
download | xas-d008e5271eafe044233db6d158bf91c9efa39331.tar.gz xas-d008e5271eafe044233db6d158bf91c9efa39331.tar.bz2 xas-d008e5271eafe044233db6d158bf91c9efa39331.zip |
Channel count first seems...nicer, somehow.
Diffstat (limited to 'src')
-rw-r--r-- | src/audio.c | 20 | ||||
-rw-r--r-- | src/mixer.c | 12 | ||||
-rw-r--r-- | src/riff.c | 42 | ||||
-rw-r--r-- | src/synth.c | 2 | ||||
-rw-r--r-- | src/vox.c | 2 |
5 files changed, 39 insertions, 39 deletions
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; } @@ -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; } @@ -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); } |