To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / CollidoscopeApp / include / AudioEngine.h @ 7:a4a336624f5a
History | View | Annotate | Download (3.88 KB)
| 1 |
/*
|
|---|---|
| 2 |
|
| 3 |
Copyright (C) 2016 Queen Mary University of London
|
| 4 |
Author: Fiore Martin
|
| 5 |
|
| 6 |
This file is part of Collidoscope.
|
| 7 |
|
| 8 |
Collidoscope is free software: you can redistribute it and/or modify
|
| 9 |
it under the terms of the GNU General Public License as published by
|
| 10 |
the Free Software Foundation, either version 3 of the License, or
|
| 11 |
(at your option) any later version.
|
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful,
|
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
GNU General Public License for more details.
|
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License
|
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
*/
|
| 21 |
|
| 22 |
#pragma once
|
| 23 |
|
| 24 |
#include <array> |
| 25 |
|
| 26 |
#include "cinder/audio/Context.h" |
| 27 |
#include "cinder/audio/ChannelRouterNode.h" |
| 28 |
#include "cinder/audio/MonitorNode.h" |
| 29 |
#include "cinder/audio/FilterNode.h" |
| 30 |
#include "BufferToWaveRecorderNode.h" |
| 31 |
#include "PGranularNode.h" |
| 32 |
#include "RingBufferPack.h" |
| 33 |
|
| 34 |
#include "Messages.h" |
| 35 |
#include "Config.h" |
| 36 |
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Audio engine of the application. It uses the Cinder library to process audio in input and output.
|
| 40 |
* The audio engine manages both waves. All methods have a waveIndx parameter to address a specific wave.
|
| 41 |
*/
|
| 42 |
class AudioEngine |
| 43 |
{
|
| 44 |
public:
|
| 45 |
|
| 46 |
AudioEngine(); |
| 47 |
|
| 48 |
~AudioEngine(); |
| 49 |
|
| 50 |
// no copies
|
| 51 |
AudioEngine( const AudioEngine © ) = delete;
|
| 52 |
AudioEngine & operator=(const AudioEngine ©) = delete;
|
| 53 |
|
| 54 |
/**
|
| 55 |
* Set up of the audio engine.
|
| 56 |
*/
|
| 57 |
void setup( const Config& Config ); |
| 58 |
|
| 59 |
size_t getSampleRate(); |
| 60 |
|
| 61 |
void record( size_t index );
|
| 62 |
|
| 63 |
void loopOn( size_t waveIdx );
|
| 64 |
|
| 65 |
void loopOff( size_t waveIdx );
|
| 66 |
|
| 67 |
void noteOn( size_t waveIdx, int note ); |
| 68 |
|
| 69 |
void noteOff( size_t waveIdx, int note ); |
| 70 |
|
| 71 |
/**
|
| 72 |
* Returns the number of elements available to read in the wave ring buffer.
|
| 73 |
* The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread,
|
| 74 |
* when a new wave is recorded.
|
| 75 |
*/
|
| 76 |
size_t getRecordWaveAvailable( size_t index ); |
| 77 |
/**
|
| 78 |
* Called from the graphic thread. Reads count elements from the wave ring buffer into \a buffer.
|
| 79 |
* The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread,
|
| 80 |
* when a new wave is recorded.
|
| 81 |
*
|
| 82 |
*/
|
| 83 |
bool readRecordWave( size_t waveIdx, RecordWaveMsg* buffer, size_t count );
|
| 84 |
|
| 85 |
void setSelectionSize( size_t waveIdx, size_t size );
|
| 86 |
|
| 87 |
void setSelectionStart( size_t waveIdx, size_t start );
|
| 88 |
|
| 89 |
void setGrainDurationCoeff( size_t waveIdx, double coeff ); |
| 90 |
|
| 91 |
void setFilterCutoff( size_t waveIdx, double cutoff ); |
| 92 |
|
| 93 |
void checkCursorTriggers( size_t waveIdx, std::vector<CursorTriggerMsg>& cursorTriggers );
|
| 94 |
|
| 95 |
/**
|
| 96 |
* 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.
|
| 97 |
* It is used in the graphic thread to draw the oscilloscope.
|
| 98 |
*/
|
| 99 |
const ci::audio::Buffer& getAudioOutputBuffer( size_t waveIdx ) const; |
| 100 |
|
| 101 |
|
| 102 |
private:
|
| 103 |
|
| 104 |
// nodes for mic input
|
| 105 |
std::array< ci::audio::ChannelRouterNodeRef, NUM_WAVES > mInputRouterNodes; |
| 106 |
// nodes for recording audio input into buffer. Also sends chunks information through
|
| 107 |
// non-blocking queue
|
| 108 |
std::array< BufferToWaveRecorderNodeRef, NUM_WAVES > mBufferRecorderNodes; |
| 109 |
// pgranulars for loop synths
|
| 110 |
std::array< PGranularNodeRef, NUM_WAVES > mPGranularNodes; |
| 111 |
|
| 112 |
|
| 113 |
std::array< ci::audio::ChannelRouterNodeRef, NUM_WAVES > mOutputRouterNodes; |
| 114 |
// nodes to get the audio buffer scoped in the oscilloscope
|
| 115 |
std::array< ci::audio::MonitorNodeRef, NUM_WAVES > mOutputMonitorNodes; |
| 116 |
// nodes for lowpass filtering
|
| 117 |
std::array< cinder::audio::FilterLowPassNodeRef, NUM_WAVES> mLowPassFilterNodes; |
| 118 |
|
| 119 |
std::array< std::unique_ptr< RingBufferPack<CursorTriggerMsg> >, NUM_WAVES > mCursorTriggerRingBufferPacks; |
| 120 |
|
| 121 |
}; |