Mercurial > hg > svapp
comparison audio/AudioGenerator.h @ 468:56acd9368532 bqaudioio
Initial work toward switching to bqaudioio library (so as to get I/O, not just O)
author | Chris Cannam |
---|---|
date | Tue, 04 Aug 2015 13:27:42 +0100 |
parents | audioio/AudioGenerator.h@72c662fe7ea3 |
children | b23bebfdfaba |
comparison
equal
deleted
inserted
replaced
466:45054b36ddbf | 468:56acd9368532 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _AUDIO_GENERATOR_H_ | |
17 #define _AUDIO_GENERATOR_H_ | |
18 | |
19 class Model; | |
20 class NoteModel; | |
21 class FlexiNoteModel; | |
22 class DenseTimeValueModel; | |
23 class SparseOneDimensionalModel; | |
24 class Playable; | |
25 class ClipMixer; | |
26 class ContinuousSynth; | |
27 | |
28 #include <QObject> | |
29 #include <QMutex> | |
30 | |
31 #include <set> | |
32 #include <map> | |
33 #include <vector> | |
34 | |
35 #include "base/BaseTypes.h" | |
36 | |
37 class AudioGenerator : public QObject | |
38 { | |
39 Q_OBJECT | |
40 | |
41 public: | |
42 AudioGenerator(); | |
43 virtual ~AudioGenerator(); | |
44 | |
45 /** | |
46 * Add a data model to be played from and initialise any necessary | |
47 * audio generation code. Returns true if the model will be | |
48 * played. The model will be added regardless of the return | |
49 * value. | |
50 */ | |
51 virtual bool addModel(Model *model); | |
52 | |
53 /** | |
54 * Remove a model. | |
55 */ | |
56 virtual void removeModel(Model *model); | |
57 | |
58 /** | |
59 * Remove all models. | |
60 */ | |
61 virtual void clearModels(); | |
62 | |
63 /** | |
64 * Reset playback, clearing buffers and the like. | |
65 */ | |
66 virtual void reset(); | |
67 | |
68 /** | |
69 * Set the target channel count. The buffer parameter to mixModel | |
70 * must always point to at least this number of arrays. | |
71 */ | |
72 virtual void setTargetChannelCount(int channelCount); | |
73 | |
74 /** | |
75 * Return the internal processing block size. The frameCount | |
76 * argument to all mixModel calls must be a multiple of this | |
77 * value. | |
78 */ | |
79 virtual sv_frame_t getBlockSize() const; | |
80 | |
81 /** | |
82 * Mix a single model into an output buffer. | |
83 */ | |
84 virtual sv_frame_t mixModel(Model *model, sv_frame_t startFrame, sv_frame_t frameCount, | |
85 float **buffer, sv_frame_t fadeIn = 0, sv_frame_t fadeOut = 0); | |
86 | |
87 /** | |
88 * Specify that only the given set of models should be played. | |
89 */ | |
90 virtual void setSoloModelSet(std::set<Model *>s); | |
91 | |
92 /** | |
93 * Specify that all models should be played as normal (if not | |
94 * muted). | |
95 */ | |
96 virtual void clearSoloModelSet(); | |
97 | |
98 protected slots: | |
99 void playClipIdChanged(const Playable *, QString); | |
100 | |
101 protected: | |
102 sv_samplerate_t m_sourceSampleRate; | |
103 int m_targetChannelCount; | |
104 int m_waveType; | |
105 | |
106 bool m_soloing; | |
107 std::set<Model *> m_soloModelSet; | |
108 | |
109 struct NoteOff { | |
110 | |
111 NoteOff(float _freq, sv_frame_t _frame) : frequency(_freq), frame(_frame) { } | |
112 | |
113 float frequency; | |
114 sv_frame_t frame; | |
115 | |
116 struct Comparator { | |
117 bool operator()(const NoteOff &n1, const NoteOff &n2) const { | |
118 return n1.frame < n2.frame; | |
119 } | |
120 }; | |
121 }; | |
122 | |
123 | |
124 typedef std::map<const Model *, ClipMixer *> ClipMixerMap; | |
125 | |
126 typedef std::multiset<NoteOff, NoteOff::Comparator> NoteOffSet; | |
127 typedef std::map<const Model *, NoteOffSet> NoteOffMap; | |
128 | |
129 typedef std::map<const Model *, ContinuousSynth *> ContinuousSynthMap; | |
130 | |
131 QMutex m_mutex; | |
132 | |
133 ClipMixerMap m_clipMixerMap; | |
134 NoteOffMap m_noteOffs; | |
135 static QString m_sampleDir; | |
136 | |
137 ContinuousSynthMap m_continuousSynthMap; | |
138 | |
139 bool usesClipMixer(const Model *); | |
140 bool wantsQuieterClips(const Model *); | |
141 bool usesContinuousSynth(const Model *); | |
142 | |
143 ClipMixer *makeClipMixerFor(const Model *model); | |
144 ContinuousSynth *makeSynthFor(const Model *model); | |
145 | |
146 static void initialiseSampleDir(); | |
147 | |
148 virtual sv_frame_t mixDenseTimeValueModel | |
149 (DenseTimeValueModel *model, sv_frame_t startFrame, sv_frame_t frameCount, | |
150 float **buffer, float gain, float pan, sv_frame_t fadeIn, sv_frame_t fadeOut); | |
151 | |
152 virtual sv_frame_t mixClipModel | |
153 (Model *model, sv_frame_t startFrame, sv_frame_t frameCount, | |
154 float **buffer, float gain, float pan); | |
155 | |
156 virtual sv_frame_t mixContinuousSynthModel | |
157 (Model *model, sv_frame_t startFrame, sv_frame_t frameCount, | |
158 float **buffer, float gain, float pan); | |
159 | |
160 static const sv_frame_t m_processingBlockSize; | |
161 | |
162 float **m_channelBuffer; | |
163 sv_frame_t m_channelBufSiz; | |
164 int m_channelBufCount; | |
165 }; | |
166 | |
167 #endif | |
168 |