diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-05-12 23:38:38 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-05-12 23:38:38 +0000 |
commit | a64e85acf96bc0c55363fe55c9e9116aef2a8584 (patch) | |
tree | 69ec57b46bdebe0e7496bf11ea9a54cdf5806904 /bbuffer.c | |
parent | 2eb6dec8e9f0114bdbad59cf8f11f197f8fdaaf3 (diff) |
resampling works
git-svn-id: file:///home/lennart/svn/public/libsydney/trunk@4 9ba3c220-e4d3-45a2-8aa3-73fcc9aff6ce
Diffstat (limited to 'bbuffer.c')
-rw-r--r-- | bbuffer.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/bbuffer.c b/bbuffer.c new file mode 100644 index 0000000..63aa145 --- /dev/null +++ b/bbuffer.c @@ -0,0 +1,77 @@ +#include <sys/types.h> + +#include "bbuffer.h" +#include "sydney.h" +#include "malloc.h" +#include "macro.h" + +int bbuffer_init(bbuffer_t *b, unsigned nchannels, size_t sample_size) { + sa_assert(b); + sa_assert(nchannels > 0); + sa_assert(sample_size > 0); + + b->nchannels = nchannels; + b->sample_size = sample_size; + + if (!(b->data = sa_new0(void *, nchannels))) { + b->size = NULL; + return SA_ERROR_OOM; + } + + if (!(b->size = sa_new0(size_t, nchannels))) { + sa_free(b->data); + b->data = NULL; + return SA_ERROR_OOM; + } + + return SA_SUCCESS; +} + +void bbuffer_done(bbuffer_t *b) { + unsigned i; + sa_assert(b); + + if (b->data) { + for (i = 0; i < b->nchannels; i++) + sa_free(b->data[i]); + + sa_free(b->data); + } + + sa_free(b->size); + + b->data = NULL; + b->size = NULL; +} + +void* bbuffer_get(bbuffer_t *b, unsigned channel, size_t size, int interleave) { + sa_assert(b); + sa_assert(channel < b->nchannels); + sa_assert(size > 0); + + if (interleave) { + + if (!b->data[0] || size * b->nchannels > b->size[0]) { + sa_free(b->data[0]); + b->size[0] = size * b->nchannels; + + if (!(b->data[0] = sa_malloc(b->size[0]))) + return NULL; + } + + return (uint8_t*) b->data[0] + (b->sample_size * channel); + + } else { + + if (!b->data[channel] || size > b->size[channel]) { + + sa_free(b->data[channel]); + b->size[channel] = size; + + if (!(b->data[channel] = sa_malloc(size))) + return NULL; + } + + return b->data[channel]; + } +} |