f@5: /* f@5: f@5: Copyright (C) 2016 Queen Mary University of London f@5: Author: Fiore Martin f@5: f@5: This file is part of Collidoscope. f@5: f@5: Collidoscope is free software: you can redistribute it and/or modify f@5: it under the terms of the GNU General Public License as published by f@5: the Free Software Foundation, either version 3 of the License, or f@5: (at your option) any later version. f@5: f@5: This program is distributed in the hope that it will be useful, f@5: but WITHOUT ANY WARRANTY; without even the implied warranty of f@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@5: GNU General Public License for more details. f@5: f@5: You should have received a copy of the GNU General Public License f@5: along with this program. If not, see . f@5: */ f@5: f@0: #pragma once f@0: f@0: #include f@0: f@0: #include "cinder/audio/Context.h" f@0: #include "cinder/audio/ChannelRouterNode.h" f@0: #include "cinder/audio/MonitorNode.h" f@0: #include "cinder/audio/FilterNode.h" f@0: #include "BufferToWaveRecorderNode.h" f@0: #include "PGranularNode.h" f@0: #include "RingBufferPack.h" f@0: f@0: #include "Messages.h" f@0: #include "Config.h" f@0: f@0: f@2: /** f@2: * Audio engine of the application. It uses the Cinder library to process audio in input and output. f@2: * The audio engine manages both waves. All methods have a waveIndx parameter to address a specific wave. f@2: */ f@0: class AudioEngine f@0: { f@0: public: f@0: f@0: AudioEngine(); f@0: f@0: ~AudioEngine(); f@0: f@0: // no copies f@0: AudioEngine( const AudioEngine © ) = delete; f@0: AudioEngine & operator=(const AudioEngine ©) = delete; f@0: f@2: /** f@2: * Set up of the audio engine. f@2: */ f@0: void setup( const Config& Config ); f@0: f@0: size_t getSampleRate(); f@0: f@0: void record( size_t index ); f@0: f@0: void loopOn( size_t waveIdx ); f@0: f@0: void loopOff( size_t waveIdx ); f@0: f@0: void noteOn( size_t waveIdx, int note ); f@0: f@0: void noteOff( size_t waveIdx, int note ); f@0: f@2: /** f@2: * Returns the number of elements available to read in the wave ring buffer. f@2: * The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread, f@2: * when a new wave is recorded. f@2: */ f@0: size_t getRecordWaveAvailable( size_t index ); f@2: /** f@16: * Called from the graphic thread. Reads \a count elements from the wave ring buffer into \a buffer. f@2: * The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread, f@2: * when a new wave is recorded. f@2: * f@2: */ f@2: bool readRecordWave( size_t waveIdx, RecordWaveMsg* buffer, size_t count ); f@0: f@0: void setSelectionSize( size_t waveIdx, size_t size ); f@0: f@0: void setSelectionStart( size_t waveIdx, size_t start ); f@0: f@0: void setGrainDurationCoeff( size_t waveIdx, double coeff ); f@0: f@0: void setFilterCutoff( size_t waveIdx, double cutoff ); f@0: f@0: void checkCursorTriggers( size_t waveIdx, std::vector& cursorTriggers ); f@0: f@2: /** f@2: * Returns a const reference to the audio output buffer. This is the buffer that is sent off to the audio interface at each audio cycle. f@2: * It is used in the graphic thread to draw the oscilloscope. f@2: */ f@0: const ci::audio::Buffer& getAudioOutputBuffer( size_t waveIdx ) const; f@0: f@0: f@0: private: f@0: f@0: // nodes for mic input f@0: std::array< ci::audio::ChannelRouterNodeRef, NUM_WAVES > mInputRouterNodes; f@0: // nodes for recording audio input into buffer. Also sends chunks information through f@0: // non-blocking queue f@0: std::array< BufferToWaveRecorderNodeRef, NUM_WAVES > mBufferRecorderNodes; f@16: // pgranulars wrapped in a Cinder::Node f@0: std::array< PGranularNodeRef, NUM_WAVES > mPGranularNodes; f@0: f@0: f@0: std::array< ci::audio::ChannelRouterNodeRef, NUM_WAVES > mOutputRouterNodes; f@0: // nodes to get the audio buffer scoped in the oscilloscope f@0: std::array< ci::audio::MonitorNodeRef, NUM_WAVES > mOutputMonitorNodes; f@0: // nodes for lowpass filtering f@0: std::array< cinder::audio::FilterLowPassNodeRef, NUM_WAVES> mLowPassFilterNodes; f@0: f@0: std::array< std::unique_ptr< RingBufferPack >, NUM_WAVES > mCursorTriggerRingBufferPacks; f@0: f@2: };