1 #ifndef AUDIOGRAPHER_CHUNKER_H
2 #define AUDIOGRAPHER_CHUNKER_H
4 #include "listed_source.h"
12 class Chunker : public ListedSource<T>, public Sink<T>
15 Chunker (nframes_t chunk_size)
16 : chunk_size (chunk_size)
19 buffer = new T[chunk_size];
27 void process (ProcessContext<T> const & context)
29 if (position + context.frames() < chunk_size) {
30 memcpy (&buffer[position], (float const *)context.data(), context.frames() * sizeof(T));
31 position += context.frames();
33 nframes_t const frames_to_copy = chunk_size - position;
34 memcpy (&buffer[position], context.data(), frames_to_copy * sizeof(T));
35 ProcessContext<T> c_out (context, buffer, chunk_size);
36 ListedSource<T>::output (c_out);
38 memcpy (buffer, &context.data()[frames_to_copy], (context.frames() - frames_to_copy) * sizeof(T));
39 position = context.frames() - frames_to_copy;
42 using Sink<T>::process;
53 #endif // AUDIOGRAPHER_CHUNKER_H