scons --> make
[aftubes.git] / buffer.c
blobdfa11b668bb241753bf39c3c5af4187edf4cd00b
1 #include "buffer.h"
2 #include "stdlib.h"
4 void buffer_init(struct buffer *buf)
6 buf->n_samples = 0;
7 buf->data = NULL;
10 err_t buffer_alloc(struct buffer *buf, size_t n_samples)
12 void *new_buf;
13 if (buf->n_samples != n_samples){
14 new_buf = realloc(buf->data, n_samples * aformat_get_sample_size(&buf->format));
15 if (!new_buf){
16 return make_error(ENOMEM, NULL, "memory full: allocating buffer (%d samples)", n_samples);
18 buf->data = new_buf;
19 buf->n_samples = n_samples;
21 return EOK;