1 #ifndef AUDIOGRAPHER_SR_CONVERTER_H
2 #define AUDIOGRAPHER_SR_CONVERTER_H
4 #include <samplerate.h>
6 #include "audiographer/visibility.h"
7 #include "audiographer/flag_debuggable.h"
8 #include "audiographer/sink.h"
9 #include "audiographer/throwing.h"
10 #include "audiographer/types.h"
11 #include "audiographer/utils/listed_source.h"
13 namespace AudioGrapher
16 /// Samplerate converter
17 class LIBAUDIOGRAPHER_API SampleRateConverter
18 : public ListedSource<float>
20 , public FlagDebuggable<>
24 /// Constructor. \n RT safe
25 SampleRateConverter (uint32_t channels);
26 ~SampleRateConverter ();
28 /// Init converter \n Not RT safe
29 void init (framecnt_t in_rate, framecnt_t out_rate, int quality = 0);
31 /// Returns max amount of frames that will be output \n RT safe
32 framecnt_t allocate_buffers (framecnt_t max_frames);
34 /** Does sample rate conversion.
35 * Note that outpt size may vary a lot.
36 * May or may not output several contexts of data.
37 * \n Should be RT safe.
38 * \TODO Check RT safety from libsamplerate
40 void process (ProcessContext<float> const & c);
41 using Sink<float>::process;
45 void set_end_of_input (ProcessContext<float> const & c);
50 framecnt_t max_frames_in;
52 float * leftover_data;
53 framecnt_t leftover_frames;
54 framecnt_t max_leftover_frames;
57 framecnt_t data_out_size;
65 #endif // AUDIOGRAPHER_SR_CONVERTER_H