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 (samplecnt_t in_rate, samplecnt_t out_rate, int quality = 0);
31 /// Returns max amount of samples that will be output \n RT safe
32 samplecnt_t allocate_buffers (samplecnt_t max_samples);
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 samplecnt_t max_samples_in;
52 float * leftover_data;
53 samplecnt_t leftover_samples;
54 samplecnt_t max_leftover_samples;
57 samplecnt_t data_out_size;
65 #endif // AUDIOGRAPHER_SR_CONVERTER_H