To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CollidoscopeApp / include / AudioEngine.h @ 3:7fb593d53361

History | View | Annotate | Download (3.16 KB)

1
#pragma once
2

    
3
#include <array>
4

    
5
#include "cinder/audio/Context.h"
6
#include "cinder/audio/ChannelRouterNode.h"
7
#include "cinder/audio/MonitorNode.h"
8
#include "cinder/audio/FilterNode.h"
9
#include "BufferToWaveRecorderNode.h"
10
#include "PGranularNode.h"
11
#include "RingBufferPack.h"
12

    
13
#include "Messages.h"
14
#include "Config.h"
15

    
16

    
17
/**
18
 * Audio engine of the application. It uses the Cinder library to process audio in input and output. 
19
 * The audio engine manages both waves. All methods have a waveIndx parameter to address a specific wave.
20
 */ 
21
class AudioEngine
22
{
23
public:
24

    
25
    AudioEngine();
26

    
27
    ~AudioEngine();
28

    
29
    // no copies
30
    AudioEngine( const AudioEngine &copy ) = delete;
31
    AudioEngine & operator=(const AudioEngine &copy) = delete;
32

    
33
    /**
34
    * Set up of the audio engine. 
35
    */
36
    void setup( const Config& Config );
37

    
38
    size_t getSampleRate();
39

    
40
    void record( size_t index );
41

    
42
    void loopOn( size_t waveIdx );
43

    
44
    void loopOff( size_t waveIdx );
45

    
46
    void noteOn( size_t waveIdx, int note );
47

    
48
    void noteOff( size_t waveIdx, int note );
49

    
50
    /**
51
    * Returns the number of elements available to read in the wave ring buffer.
52
    * The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread, 
53
    * when a new wave is recorded.
54
    */ 
55
    size_t getRecordWaveAvailable( size_t index );
56
    /**
57
    * Called from the graphic thread. Reads count elements from the wave ring buffer into \a buffer.
58
    * The wave ring buffer is used to pass the size of the wave chunks from the audio thread to the graphic thread, 
59
    * when a new wave is recorded.
60
    *
61
    */
62
    bool readRecordWave( size_t waveIdx, RecordWaveMsg* buffer, size_t count );
63

    
64
    void setSelectionSize( size_t waveIdx, size_t size );
65

    
66
    void setSelectionStart( size_t waveIdx, size_t start );
67

    
68
    void setGrainDurationCoeff( size_t waveIdx, double coeff );
69

    
70
    void setFilterCutoff( size_t waveIdx, double cutoff );
71

    
72
    void checkCursorTriggers( size_t waveIdx, std::vector<CursorTriggerMsg>& cursorTriggers );
73

    
74
    /**
75
     * 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. 
76
     * It is used in the graphic thread to draw the oscilloscope.
77
     */
78
    const ci::audio::Buffer& getAudioOutputBuffer( size_t waveIdx ) const;
79

    
80

    
81
private:
82

    
83
    // nodes for mic input 
84
    std::array< ci::audio::ChannelRouterNodeRef, NUM_WAVES > mInputRouterNodes;
85
    // nodes for recording audio input into buffer. Also sends chunks information through 
86
    // non-blocking queue 
87
    std::array< BufferToWaveRecorderNodeRef, NUM_WAVES > mBufferRecorderNodes;
88
    // pgranulars for loop synths 
89
    std::array< PGranularNodeRef, NUM_WAVES > mPGranularNodes;
90

    
91

    
92
    std::array< ci::audio::ChannelRouterNodeRef, NUM_WAVES > mOutputRouterNodes;
93
    // nodes to get the audio buffer scoped in the oscilloscope 
94
    std::array< ci::audio::MonitorNodeRef, NUM_WAVES > mOutputMonitorNodes;
95
    // nodes for lowpass filtering
96
    std::array< cinder::audio::FilterLowPassNodeRef, NUM_WAVES> mLowPassFilterNodes;
97

    
98
    std::array< std::unique_ptr< RingBufferPack<CursorTriggerMsg> >, NUM_WAVES > mCursorTriggerRingBufferPacks;
99

    
100
};