comparison audioio/AudioGenerator.h @ 0:db6fcbd4405c

initial import
author Chris Cannam
date Tue, 10 Jan 2006 16:33:16 +0000
parents
children df5923e33d01
comparison
equal deleted inserted replaced
-1:000000000000 0:db6fcbd4405c
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 A waveform viewer and audio annotation editor.
5 Chris Cannam, Queen Mary University of London, 2005
6
7 This is experimental software. Not for distribution.
8 */
9
10 #ifndef _AUDIO_GENERATOR_H_
11 #define _AUDIO_GENERATOR_H_
12
13 class Model;
14 class ViewManager;
15 class DenseTimeValueModel;
16 class SparseOneDimensionalModel;
17 class RealTimePluginInstance;
18
19 #include <set>
20 #include <map>
21
22 class AudioGenerator
23 {
24 public:
25 AudioGenerator(ViewManager *);
26 virtual ~AudioGenerator();
27
28 /**
29 * Add a data model to be played from and initialise any
30 * necessary audio generation code.
31 */
32 virtual void addModel(Model *model);
33
34 /**
35 * Remove a model.
36 */
37 virtual void removeModel(Model *model);
38
39 /**
40 * Remove all models.
41 */
42 virtual void clearModels();
43
44 /**
45 * Reset playback, clearing plugins and the like.
46 */
47 virtual void reset();
48
49 /**
50 * Set the target channel count. The buffer parameter to mixModel
51 * must always point to at least this number of arrays.
52 */
53 virtual void setTargetChannelCount(size_t channelCount);
54
55 /**
56 * Return the internal processing block size. The frameCount
57 * argument to all mixModel calls must be a multiple of this
58 * value.
59 */
60 virtual size_t getBlockSize() const;
61
62 /**
63 * Mix a single model into an output buffer.
64 */
65 virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount,
66 float **buffer);
67
68 protected:
69 ViewManager *m_viewManager;
70 size_t m_sourceSampleRate;
71 size_t m_targetChannelCount;
72
73 struct NoteOff {
74
75 int pitch;
76 size_t frame;
77
78 struct Comparator {
79 bool operator()(const NoteOff &n1, const NoteOff &n2) const {
80 return n1.frame < n2.frame;
81 }
82 };
83 };
84
85 typedef std::map<SparseOneDimensionalModel *,
86 RealTimePluginInstance *> PluginMap;
87
88 typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
89 typedef std::map<SparseOneDimensionalModel *, NoteOffSet> NoteOffMap;
90
91 PluginMap m_synthMap;
92 NoteOffMap m_noteOffs;
93
94 virtual size_t mixDenseTimeValueModel
95 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
96 float **buffer, float gain, float pan);
97
98 virtual size_t mixSparseOneDimensionalModel
99 (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount,
100 float **buffer, float gain, float pan);
101
102 static const size_t m_pluginBlockSize;
103 };
104
105 #endif
106