annotate audioio/AudioGenerator.h @ 412:c1b2b8b84165 tonioni

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