Mercurial > hg > opencollidoscope
comparison CollidoscopeApp/include/PGranularNode.h @ 3:7fb593d53361
added comments
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Tue, 12 Jul 2016 18:29:38 +0200 |
parents | 02467299402e |
children | 75b744078d66 |
comparison
equal
deleted
inserted
replaced
2:dd889fff8423 | 3:7fb593d53361 |
---|---|
28 static const int kNoMidiNote = -50; | 28 static const int kNoMidiNote = -50; |
29 | 29 |
30 explicit PGranularNode( ci::audio::Buffer *grainBuffer, CursorTriggerMsgRingBuffer &triggerRingBuffer ); | 30 explicit PGranularNode( ci::audio::Buffer *grainBuffer, CursorTriggerMsgRingBuffer &triggerRingBuffer ); |
31 ~PGranularNode(); | 31 ~PGranularNode(); |
32 | 32 |
33 // set selection size in samples | 33 /** Set selection size in samples */ |
34 void setSelectionSize( size_t size ) | 34 void setSelectionSize( size_t size ) |
35 { | 35 { |
36 mSelectionSize.set( size ); | 36 mSelectionSize.set( size ); |
37 } | 37 } |
38 | 38 |
39 /** Set selection start in samples */ | |
39 void setSelectionStart( size_t start ) | 40 void setSelectionStart( size_t start ) |
40 { | 41 { |
41 mSelectionStart.set( start ); | 42 mSelectionStart.set( start ); |
42 } | 43 } |
43 | 44 |
44 void setGrainsDurationCoeff( double coeff ) | 45 void setGrainsDurationCoeff( double coeff ) |
45 { | 46 { |
46 mGrainDurationCoeff.set( coeff ); | 47 mGrainDurationCoeff.set( coeff ); |
47 } | 48 } |
48 | 49 |
49 // used for trigger callback in PGRanular | 50 /* PGranularNode passes itself as trigger callback in PGranular */ |
50 void operator()( char msgType, int ID ); | 51 void operator()( char msgType, int ID ); |
51 | 52 |
52 ci::audio::dsp::RingBufferT<NoteMsg>& getNoteRingBuffer() { return mNoteMsgRingBufferPack.getBuffer(); } | 53 ci::audio::dsp::RingBufferT<NoteMsg>& getNoteRingBuffer() { return mNoteMsgRingBufferPack.getBuffer(); } |
53 | 54 |
54 protected: | 55 protected: |
57 | 58 |
58 void process( ci::audio::Buffer *buffer ) override; | 59 void process( ci::audio::Buffer *buffer ) override; |
59 | 60 |
60 private: | 61 private: |
61 | 62 |
63 // Wraps a std::atomic but get() returns a boost::optional that is set to a real value only when the atomic has changed. | |
64 // It is used to avoid calling PGranulat setter methods with * the same value at each audio callback. | |
62 template< typename T> | 65 template< typename T> |
63 class LazyAtomic | 66 class LazyAtomic |
64 { | 67 { |
65 public: | 68 public: |
66 LazyAtomic( T val ) : | 69 LazyAtomic( T val ) : |
88 private: | 91 private: |
89 std::atomic<T> mAtomic; | 92 std::atomic<T> mAtomic; |
90 T mPreviousVal; | 93 T mPreviousVal; |
91 }; | 94 }; |
92 | 95 |
96 // creates or re-start a PGranular and sets the pitch according to the MIDI note passed as argument | |
93 void handleNoteMsg( const NoteMsg &msg ); | 97 void handleNoteMsg( const NoteMsg &msg ); |
94 | 98 |
95 // pointer to PGranular object | 99 // pointers to PGranular objects |
96 std::unique_ptr < collidoscope::PGranular<float, RandomGenerator, PGranularNode > > mPGranularLoop; | 100 std::unique_ptr < collidoscope::PGranular<float, RandomGenerator, PGranularNode > > mPGranularLoop; |
97 std::array<std::unique_ptr < collidoscope::PGranular<float, RandomGenerator, PGranularNode > >, kMaxVoices> mPGranularNotes; | 101 std::array<std::unique_ptr < collidoscope::PGranular<float, RandomGenerator, PGranularNode > >, kMaxVoices> mPGranularNotes; |
102 // maps midi notes to pgranulars. When a noteOff is received maks sure the right PGranular is turned off | |
98 std::array<int, kMaxVoices> mMidiNotes; | 103 std::array<int, kMaxVoices> mMidiNotes; |
99 | 104 |
100 // pointer to the random generator struct passed over to PGranular | 105 // pointer to the random generator struct passed over to PGranular |
101 std::unique_ptr< RandomGenerator > mRandomOffset; | 106 std::unique_ptr< RandomGenerator > mRandomOffset; |
102 | 107 |
103 /* buffer containing the recorder audio, to pass to PGranular in initialize() */ | 108 // buffer containing the recorder audio, to pass to PGranular in initialize() |
104 ci::audio::Buffer *mGrainBuffer; | 109 ci::audio::Buffer *mGrainBuffer; |
105 | 110 |
106 ci::audio::BufferRef mTempBuffer; | 111 ci::audio::BufferRef mTempBuffer; |
107 | 112 |
108 CursorTriggerMsgRingBuffer &mTriggerRingBuffer; | 113 CursorTriggerMsgRingBuffer &mTriggerRingBuffer; |