1 #ifndef AUDIOGRAPHER_SR_CONVERTER_H
2 #define AUDIOGRAPHER_SR_CONVERTER_H
4 #include <samplerate.h>
6 #include "audiographer/flag_debuggable.h"
7 #include "audiographer/sink.h"
8 #include "audiographer/throwing.h"
9 #include "audiographer/types.h"
10 #include "audiographer/utils/listed_source.h"
12 namespace AudioGrapher
15 /// Samplerate converter
16 class SampleRateConverter
17 : public ListedSource<float>
19 , public FlagDebuggable<>
23 /// Constructor. \n RT safe
24 SampleRateConverter (uint32_t channels);
25 ~SampleRateConverter ();
27 /// Init converter \n Not RT safe
28 void init (nframes_t in_rate, nframes_t out_rate, int quality = 0);
30 /// Returns max amount of frames that will be output \n RT safe
31 nframes_t allocate_buffers (nframes_t max_frames);
33 /** Does sample rate conversion.
34 * Note that outpt size may vary a lot.
35 * May or may not output several contexts of data.
36 * \n Should be RT safe.
37 * \TODO Check RT safety from libsamplerate
39 void process (ProcessContext<float> const & c);
40 using Sink<float>::process;
44 void set_end_of_input (ProcessContext<float> const & c);
49 nframes_t max_frames_in;
51 float * leftover_data;
52 nframes_t leftover_frames;
53 nframes_t max_leftover_frames;
56 nframes_t data_out_size;
64 #endif // AUDIOGRAPHER_SR_CONVERTER_H