Fix export, which has been broken since the boost::signals2 changes. Also update...
[ardour.git] / libs / audiographer / audiographer / general / sr_converter.h
1 #ifndef AUDIOGRAPHER_SR_CONVERTER_H
2 #define AUDIOGRAPHER_SR_CONVERTER_H
3
4 #include <samplerate.h>
5
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"
11
12 namespace AudioGrapher
13 {
14
15 /// Samplerate converter
16 class SampleRateConverter
17   : public ListedSource<float>
18   , public Sink<float>
19   , public FlagDebuggable<>
20   , public Throwing<>
21 {
22   public:
23         /// Constructor. \n RT safe
24         SampleRateConverter (uint32_t channels);
25         ~SampleRateConverter ();
26
27         /// Init converter \n Not RT safe
28         void init (nframes_t in_rate, nframes_t out_rate, int quality = 0);
29         
30         /// Returns max amount of frames that will be output \n RT safe
31         nframes_t allocate_buffers (nframes_t max_frames);
32         
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
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         nframes_t      max_frames_in;
50         
51         float *        leftover_data;
52         nframes_t      leftover_frames;
53         nframes_t      max_leftover_frames;
54
55         float *        data_out;
56         nframes_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