1 #ifndef AUDIOGRAPHER_SR_CONVERTER_H 2 #define AUDIOGRAPHER_SR_CONVERTER_H 3 4 #include <samplerate.h> 5 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" 12 13 namespace AudioGrapher 14 { 15 16 /// Samplerate converter 17 class LIBAUDIOGRAPHER_API SampleRateConverter 18 : public ListedSource<float> 19 , public Sink<float> 20 , public FlagDebuggable<> 21 , public Throwing<> 22 { 23 public: 24 /// Constructor. \n RT safe 25 SampleRateConverter (uint32_t channels); 26 ~SampleRateConverter (); 27 28 /// Init converter \n Not RT safe 29 void init (samplecnt_t in_rate, samplecnt_t out_rate, int quality = 0); 30 31 /// Returns max amount of samples that will be output \n RT safe 32 samplecnt_t allocate_buffers (samplecnt_t max_samples); 33 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 */ 39 void process (ProcessContext<float> const & c); 40 using Sink<float>::process; 41 42 private: 43 44 void set_end_of_input (ProcessContext<float> const & c); 45 void reset (); 46 47 bool active; 48 uint32_t channels; 49 samplecnt_t max_samples_in; 50 51 float * leftover_data; 52 samplecnt_t leftover_samples; 53 samplecnt_t max_leftover_samples; 54 55 float * data_out; 56 samplecnt_t data_out_size; 57 58 SRC_DATA src_data; 59 SRC_STATE* src_state; 60 }; 61 62 } // namespace 63 64 #endif // AUDIOGRAPHER_SR_CONVERTER_H 65