finalize PROGRAM_NAME change for ardour3
[ardour.git] / libs / audiographer / audiographer / sr_converter.h
1 #ifndef AUDIOGRAPHER_SR_CONVERTER_H
2 #define AUDIOGRAPHER_SR_CONVERTER_H
3
4 #include <samplerate.h>
5
6 #include "debuggable.h"
7 #include "listed_source.h"
8 #include "sink.h"
9 #include "throwing.h"
10 #include "types.h"
11
12 namespace AudioGrapher
13 {
14
15 class SampleRateConverter
16   : public ListedSource<float>
17   , public Sink<float>
18   , public Debuggable<>
19   , public Throwing<>
20 {
21   public:
22         SampleRateConverter (uint32_t channels);
23         ~SampleRateConverter ();
24
25         // not RT safe
26         void init (nframes_t in_rate, nframes_t out_rate, int quality = 0);
27         
28         // returns max amount of frames that will be output
29         nframes_t allocate_buffers (nframes_t max_frames);
30         
31         // could be RT safe (check libsamplerate to be sure)
32         void process (ProcessContext<float> const & c);
33         using Sink<float>::process;
34
35   private:
36
37         void set_end_of_input (ProcessContext<float> const & c);
38         void reset ();
39
40         bool           active;
41         uint32_t       channels;
42         nframes_t      max_frames_in;
43         
44         float *        leftover_data;
45         nframes_t      leftover_frames;
46         nframes_t      max_leftover_frames;
47
48         float *        data_out;
49         nframes_t      data_out_size;
50
51         SRC_DATA       src_data;
52         SRC_STATE*     src_state;
53 };
54
55 } // namespace
56
57 #endif // AUDIOGRAPHER_SR_CONVERTER_H