Chris@43: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@43: Chris@43: /* Chris@43: Sonic Visualiser Chris@43: An audio file viewer and annotation editor. Chris@43: Centre for Digital Music, Queen Mary, University of London. Chris@43: This file copyright 2006 Chris Cannam. Chris@43: Chris@43: This program is free software; you can redistribute it and/or Chris@43: modify it under the terms of the GNU General Public License as Chris@43: published by the Free Software Foundation; either version 2 of the Chris@43: License, or (at your option) any later version. See the file Chris@43: COPYING included with this distribution for more information. Chris@43: */ Chris@43: Chris@43: #ifndef _AUDIO_GENERATOR_H_ Chris@43: #define _AUDIO_GENERATOR_H_ Chris@43: Chris@43: class Model; Chris@43: class NoteModel; matthiasm@281: class FlexiNoteModel; Chris@43: class DenseTimeValueModel; Chris@43: class SparseOneDimensionalModel; Chris@108: class Playable; Chris@307: class ClipMixer; Chris@313: class ContinuousSynth; Chris@43: Chris@43: #include Chris@43: #include Chris@43: Chris@43: #include Chris@43: #include Chris@275: #include Chris@43: Chris@43: class AudioGenerator : public QObject Chris@43: { Chris@43: Q_OBJECT Chris@43: Chris@43: public: Chris@43: AudioGenerator(); Chris@43: virtual ~AudioGenerator(); Chris@43: Chris@43: /** Chris@43: * Add a data model to be played from and initialise any necessary Chris@43: * audio generation code. Returns true if the model will be Chris@108: * played. The model will be added regardless of the return Chris@108: * value. Chris@43: */ Chris@43: virtual bool addModel(Model *model); Chris@43: Chris@43: /** Chris@43: * Remove a model. Chris@43: */ Chris@43: virtual void removeModel(Model *model); Chris@43: Chris@43: /** Chris@43: * Remove all models. Chris@43: */ Chris@43: virtual void clearModels(); Chris@43: Chris@43: /** Chris@305: * Reset playback, clearing buffers and the like. Chris@43: */ Chris@43: virtual void reset(); Chris@43: Chris@43: /** Chris@43: * Set the target channel count. The buffer parameter to mixModel Chris@43: * must always point to at least this number of arrays. Chris@43: */ Chris@43: virtual void setTargetChannelCount(size_t channelCount); Chris@43: Chris@43: /** Chris@43: * Return the internal processing block size. The frameCount Chris@43: * argument to all mixModel calls must be a multiple of this Chris@43: * value. Chris@43: */ Chris@43: virtual size_t getBlockSize() const; Chris@43: Chris@43: /** Chris@43: * Mix a single model into an output buffer. Chris@43: */ Chris@43: virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount, Chris@43: float **buffer, size_t fadeIn = 0, size_t fadeOut = 0); Chris@43: Chris@43: /** Chris@43: * Specify that only the given set of models should be played. Chris@43: */ Chris@43: virtual void setSoloModelSet(std::sets); Chris@43: Chris@43: /** Chris@43: * Specify that all models should be played as normal (if not Chris@43: * muted). Chris@43: */ Chris@43: virtual void clearSoloModelSet(); Chris@43: Chris@43: protected slots: Chris@309: void playClipIdChanged(const Playable *, QString); Chris@43: Chris@43: protected: Chris@305: size_t m_sourceSampleRate; Chris@305: size_t m_targetChannelCount; rmb456@323: size_t m_waveType; Chris@43: Chris@43: bool m_soloing; Chris@43: std::set m_soloModelSet; Chris@43: Chris@43: struct NoteOff { Chris@43: Chris@308: NoteOff(float _freq, size_t _frame) : frequency(_freq), frame(_frame) { } Chris@275: Chris@308: float frequency; Chris@43: size_t frame; Chris@43: Chris@43: struct Comparator { Chris@43: bool operator()(const NoteOff &n1, const NoteOff &n2) const { Chris@43: return n1.frame < n2.frame; Chris@43: } Chris@43: }; Chris@43: }; Chris@43: Chris@307: Chris@307: typedef std::map ClipMixerMap; Chris@43: Chris@178: typedef std::multiset NoteOffSet; Chris@43: typedef std::map NoteOffMap; Chris@43: Chris@313: typedef std::map ContinuousSynthMap; Chris@313: Chris@43: QMutex m_mutex; Chris@313: Chris@307: ClipMixerMap m_clipMixerMap; Chris@43: NoteOffMap m_noteOffs; Chris@43: static QString m_sampleDir; Chris@43: Chris@313: ContinuousSynthMap m_continuousSynthMap; Chris@313: Chris@313: bool usesClipMixer(const Model *); Chris@349: bool wantsQuieterClips(const Model *); Chris@313: bool usesContinuousSynth(const Model *); Chris@313: Chris@307: ClipMixer *makeClipMixerFor(const Model *model); Chris@313: ContinuousSynth *makeSynthFor(const Model *model); Chris@307: Chris@108: static void initialiseSampleDir(); Chris@43: Chris@43: virtual size_t mixDenseTimeValueModel Chris@43: (DenseTimeValueModel *model, size_t startFrame, size_t frameCount, Chris@43: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@43: Chris@313: virtual size_t mixClipModel Chris@275: (Model *model, size_t startFrame, size_t frameCount, Chris@313: float **buffer, float gain, float pan); Chris@313: Chris@313: virtual size_t mixContinuousSynthModel Chris@313: (Model *model, size_t startFrame, size_t frameCount, Chris@313: float **buffer, float gain, float pan); Chris@275: Chris@305: static const size_t m_processingBlockSize; Chris@43: }; Chris@43: Chris@43: #endif Chris@43: