Mercurial > hg > opencollidoscope
changeset 2:dd889fff8423
added some comments
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Mon, 11 Jul 2016 17:03:40 +0200 |
parents | b5bcad8e7803 |
children | 7fb593d53361 |
files | CollidoscopeApp/include/AudioEngine.h CollidoscopeApp/include/BufferToWaveRecorderNode.h CollidoscopeApp/include/Chunk.h CollidoscopeApp/include/Config.h CollidoscopeApp/include/EnvASR.h CollidoscopeApp/include/Oscilloscope.h CollidoscopeApp/src/AudioEngine.cpp CollidoscopeApp/src/Config.cpp CollidoscopeApp/src/MIDI.cpp |
diffstat | 9 files changed, 142 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/CollidoscopeApp/include/AudioEngine.h Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/include/AudioEngine.h Mon Jul 11 17:03:40 2016 +0200 @@ -14,6 +14,10 @@ #include "Config.h" +/** + * Audio engine of the application. It uses the Cinder library to process audio in input and output. + * The audio engine manages both waves. All methods have a waveIndx parameter to address a specific wave. + */ class AudioEngine { public: @@ -26,6 +30,9 @@ AudioEngine( const AudioEngine © ) = delete; AudioEngine & operator=(const AudioEngine ©) = delete; + /** + * Set up of the audio engine. + */ void setup( const Config& Config ); size_t getSampleRate(); @@ -40,9 +47,19 @@ void noteOff( size_t waveIdx, int note ); + /** + * Returns the number of elements available to read in the wave ring buffer. + * The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread, + * when a new wave is recorded. + */ size_t getRecordWaveAvailable( size_t index ); - - bool readRecordWave( size_t waveIdx, RecordWaveMsg*, size_t count ); + /** + * Called from the graphic thread. Reads count elements from the wave ring buffer into \a buffer. + * The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread, + * when a new wave is recorded. + * + */ + bool readRecordWave( size_t waveIdx, RecordWaveMsg* buffer, size_t count ); void setSelectionSize( size_t waveIdx, size_t size ); @@ -54,6 +71,10 @@ void checkCursorTriggers( size_t waveIdx, std::vector<CursorTriggerMsg>& cursorTriggers ); + /** + * 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. + * It is used in the graphic thread to draw the oscilloscope. + */ const ci::audio::Buffer& getAudioOutputBuffer( size_t waveIdx ) const; @@ -76,4 +97,4 @@ std::array< std::unique_ptr< RingBufferPack<CursorTriggerMsg> >, NUM_WAVES > mCursorTriggerRingBufferPacks; -}; \ No newline at end of file +};
--- a/CollidoscopeApp/include/BufferToWaveRecorderNode.h Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/include/BufferToWaveRecorderNode.h Mon Jul 11 17:03:40 2016 +0200 @@ -12,7 +12,14 @@ typedef ci::audio::dsp::RingBufferT<RecordWaveMsg> RecordWaveMsgRingBuffer; - +/** + * A \a Node in the audio graph of the Cinder audio library that records input in a buffer. + * + * This class is similar to \a cinder::audio::BufferRecorderNode (it's a derivative work of this class indeed) but it has an additional feature. + * When recording it uses the audio input samples to compute the size values of the visual chunks. + * The chunks values are stored in a ring buffer and fetched by the graphic thread to paint the wave as it gets recorded. + * + */ class BufferToWaveRecorderNode : public ci::audio::SampleRecorderNode { public: @@ -54,8 +61,10 @@ //! Returns the frame of the last buffer overrun or 0 if none since the last time this method was called. When this happens, it means the recorded buffer probably has skipped some frames. uint64_t getLastOverrun(); + //! returns a reference to the ring buffer when the size values of the chunks is stored, when a new wave is recorder RecordWaveMsgRingBuffer& getRingBuffer() { return mRingBuffer; } + //!returns a pointer to the buffer where the audio is recorder. This is used by the PGranular to create the granular synthesis ci::audio::Buffer* getRecorderBuffer() { return &mRecorderBuffer; }
--- a/CollidoscopeApp/include/Chunk.h Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/include/Chunk.h Mon Jul 11 17:03:40 2016 +0200 @@ -6,6 +6,15 @@ class DrawInfo; +/** + * + * A chunk of audio in Collidoscope low-fi visual wave. + * + * The visual wave of Collidoscope is made out of a number of bars that mimics in a low-fi fashion the typical waveform based representation of audio. + * A Chunk is one of the bars of the visual wave. + * + */ + class Chunk { @@ -14,27 +23,62 @@ const static float kWidth; const static float kHalfWidth; + /** + * Constructor, takes as argument the index of this chunk in the wave + */ Chunk( size_t index ); + /** + * Sets the top value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0] + */ void inline setTop(float t) { mAudioTop = t; mAnimate = 0.0f; mResetting = false; /* startes the animation to crate a chunk */ } + /** + * Sets the bottom value of this chunk. The value is passed in audio coordinates : [-1.0, 1.0] + */ void inline setBottom(float b) { mAudioBottom = b; mAnimate = 0.0f; mResetting = false; } + /** + * Get the top value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0] + */ float inline getTop() const { return mAudioTop; } + /** + * Get the bottom value of this chunk. The value is returned in audio coordinates : [-1.0, 1.0] + */ float inline getBottom() const { return mAudioBottom; } + /** + * Reset this chunks. When a chunk is reset it starts shrinking until it disappears. + * + */ void reset(){ mResetting = true; } + /** + * Called in the graphic loop. It update this chunk. + */ void update( const DrawInfo& di ); + /** + * Called in the graphic loop. It draws this chunk. + */ void draw( const DrawInfo& di, ci::gl::BatchRef &batch ); + /** + * Called in the graphic loop. It draws this chunk all the way to the bottom of the screen. + * This method is called when the chunk is the first or last in a selection. + */ void drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ); + /** + * Informs this chunk that it's the first chunk of the selection. + */ void setAsSelectionStart(bool start){ isSelectionStart = start; } + /** + * Informs this chunk that it's the last chunk of the selection. + */ void setAsSelectionEnd(bool end){ isSelectionEnd = end; }
--- a/CollidoscopeApp/include/Config.h Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/include/Config.h Mon Jul 11 17:03:40 2016 +0200 @@ -6,6 +6,12 @@ #include "cinder/Xml.h" +/** + * Configuration class gathers in one place all the values recided at runtime + * + * Reading the configuration from an XML file is partially implemented but not used at the moment + * + */ class Config { public: @@ -21,22 +27,26 @@ std::string getInputDeviceKey() const { - return mAudioInputDeviceKey; // Komplete 1/2 - //return "{0.0.1.00000000}.{a043bc8c-1dd1-4c94-82b4-ad8320cac5a5}"; // Komplete 3/4 - //return "{0.0.1.00000000}.{828b681b-cc0c-44e1-93c9-5f1f46f5926f}"; // Realtek + return mAudioInputDeviceKey; } + /** + * Returns number of chunks in a wave + */ std::size_t getNumChunks() const { return mNumChunks; } - /* return wave lenght in seconds */ + /** returns wave lenght in seconds */ double getWaveLen() const { return mWaveLen; } + /** + * Returns wave's selection color + */ ci::Color getWaveSelectionColor(size_t waveIdx) const { if (waveIdx == 0){ @@ -47,19 +57,18 @@ } } + /** + * The size of the ring buffer used to trigger a visual cursor from the audio thread when a new grain is created + */ std::size_t getCursorTriggerMessageBufSize() const { return 512; } - // returns the index of the wave associated to the MIDI channel passed as argument + /** returns the index of the wave associated to the MIDI channel passed as argument */ size_t getWaveForMIDIChannel( unsigned char channelIdx ) { return channelIdx; - /*for ( int i = 0; i < NUM_WAVES; i++ ){ - if ( channelIdx == mMidiChannels[i] ) - return i; - }*/ } double getMaxGrainDurationCoeff() const @@ -82,11 +91,19 @@ return 6; } + /** + * Returns the maximum size of a wave selection in number of chunks. + */ size_t getMaxSelectionNumChunks() const { return 37; } + /** + * The value returned is used when creating the oscilloscope. + * The oscilloscope represents the audio output buffer graphically. However it doesn't need to be as refined as the + * audio wave and it's downsampled using the following formula : number of oscilloscope points = size o audio output buffer / getOscilloscopeNumPointsDivider() + */ size_t getOscilloscopeNumPointsDivider() const { return 4;
--- a/CollidoscopeApp/include/EnvASR.h Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/include/EnvASR.h Mon Jul 11 17:03:40 2016 +0200 @@ -2,6 +2,16 @@ namespace collidoscope { + +/* + * An ASR envelope with linear shape. It is modeled after the STK envelope classes. + * The tick() method advances the computation of the envelope one sample and returns the computed sample + * The class is templated for the type of the samples that each tick of the envelope produces. + * + * Client classes can set/get the current state of the envelope with the + * respective getter/setter methods + * + */ template <typename T> class EnvASR { @@ -88,4 +98,4 @@ }; -} \ No newline at end of file +}
--- a/CollidoscopeApp/include/Oscilloscope.h Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/include/Oscilloscope.h Mon Jul 11 17:03:40 2016 +0200 @@ -4,16 +4,28 @@ #include "DrawInfo.h" + + +/** + * The oscilloscope that oscillates when Collidoscope is played + */ class Oscilloscope { public: + /** + * Constructor, accepts as argument the number of points that make up the oscilloscope line + */ Oscilloscope( size_t numPoints ): mNumPoints( numPoints ), mLine( std::vector<ci::vec2>( numPoints, ci::vec2() ) ) {} + /** + * Sets the value of a point of the oscilloscope. The value is passed as an audio coordinate [-1.0, 1.0]. + * A reference to DrawInfo is passed to calculate the graphic coordinate of the point based on the audio value passed. + */ void setPoint( int index, float audioVal, const DrawInfo &di ){ if ( audioVal > 1.0f ){ @@ -45,6 +57,9 @@ } + /** + * Draws this oscilloscope as a cinder::PolyLine2f + */ void draw() { ci::gl::color(1.0f, 1.0f, 1.0f);
--- a/CollidoscopeApp/src/AudioEngine.cpp Fri Jul 08 11:39:18 2016 +0200 +++ b/CollidoscopeApp/src/AudioEngine.cpp Mon Jul 11 17:03:40 2016 +0200 @@ -5,6 +5,7 @@ using namespace ci::audio; +/* Frequency ratios in the chromatic scale */ double chromaticRatios[] = { 1, 1.0594630943591, @@ -20,6 +21,14 @@ 1.8877486253586 }; + +/* + * Calculates the ratio between the frequency of the midi note passed as argument and middle C note ( MIDI value = 60 ). + * This is used for pitch shifting the granular synth output, according to the key pressed by the user. + * The middle C is taken as reference in pitch in the pitch shifting of Collidoscope output. + * That is, with the middle C the output is not pitch shifted at all and is equal in frequency to the recorder sample. + * + */ inline double calculateMidiNoteRatio( int midiNote ) { int distanceFromCenter = midiNote - 60; // 60 is the central midi note @@ -174,6 +183,7 @@ return mBufferRecorderNodes[waveIdx]->getRingBuffer().getAvailableRead(); } + bool AudioEngine::readRecordWave( size_t waveIdx, RecordWaveMsg* buffer, size_t count ) { return mBufferRecorderNodes[waveIdx]->getRingBuffer().read( buffer, count );