ofxPDSP
Sampler.h
1 
2 // Sampler.h
3 // ofxPDSP
4 // Nicola Pisanti, MIT License, 2016
5 
6 
7 #ifndef PDSP_SAMPLERS_SAMPLER_H_INCLUDED
8 #define PDSP_SAMPLERS_SAMPLER_H_INCLUDED
9 
10 #include "../pdspCore.h"
11 #include "SampleBuffer.h"
12 
13 namespace pdsp {
21 class Sampler : public Unit{
22 
23 public:
24  Sampler();
25 
29  Patchable& in_trig();
30 
35 
41 
46 
51 
56 
61 
67  void addSample(SampleBuffer* newSample, int channel=0);
68 
75  bool setSample(SampleBuffer* newSample, int index, int channel=0);
76 
80  float meter_position() const;
81 
82 private:
83  void prepareUnit( int expectedBufferSize, double sampleRate) override;
84  void releaseResources () override {};
85  void process (int bufferSize) noexcept override;
86 
87  template<bool pitchModChange>
88  void process_once( const float* pitchModBuffer)noexcept;
89 
90  template<bool pitchModAR, bool triggerAR>
91  void process_audio( const float* pitchModBuffer, const float* triggerBuffer, int bufferSize)noexcept;
92 
93  void selectSample( int n, int bufferSize, float trigger) noexcept;
94 
95  InputNode input_trig;
96  InputNode input_pitch_mod;
97  InputNode input_select;
98  InputNode input_start;
99  InputNode input_direction;
100  InputNode input_start_mod;
101  OutputNode output;
102 
103  float readIndex;
104  float inc;
105  SampleBuffer* sample;
106  int channel;
107  int sampleIndex;
108 
109  std::vector<SampleBuffer*> samples;
110 
111  float incBase;
112  float direction;
113 
114  std::atomic<float> positionMeter;
115  float positionDivider;
116 
117  std::vector<int> channels;
118 
119  const float* selectBuffer;
120  int selectState;
121 
122  const float* startBuffer;
123  int startState;
124 
125  const float* startModBuffer;
126  int startModState;
127 
128 };
129 
130 
131 }
132 
133 
134 
135 #endif // PDSP_SAMPLERS_SAMPLER_H_INCLUDED
plays SampleBuffer
Definition: Sampler.h:21
bool setSample(SampleBuffer *newSample, int index, int channel=0)
Sets the SampleBuffer pointer at the given index to a new pointer.
Definition: Sampler.cpp:76
Patchable & in_start()
Sets "start" as selected input and returns this Unit ready to be patched. This input change the start...
Definition: Sampler.cpp:51
Abstract class for implementing Units.
Definition: BasicNodes.h:223
Abstract class for implementing Units and Modules.
Definition: BasicNodes.h:82
float meter_position() const
returns a value from 0.0f to 1.0f that broadly rapresent the "playhead" of the current sample...
Definition: Sampler.cpp:35
Contains the data loaded from an audio file.
Definition: SampleBuffer.h:28
Input of a Unit, process all the connected Outputs and sum them. Has an internal variable state...
Definition: BasicNodes.h:536
Patchable & out_signal()
Sets "signal" as selected output and returns this Unit ready to be patched. This is the default outpu...
Definition: Sampler.cpp:63
Thread-safe value control with smoothing.
Definition: SequencerBridge.h:11
void addSample(SampleBuffer *newSample, int channel=0)
adds a pointer to a SampleBuffer to an internal array of SampleBuffer pointers
Definition: Sampler.cpp:68
Patchable & in_pitch()
Sets "pitch" as selected input and returns this Unit ready to be patched. This input change the sampl...
Definition: Sampler.cpp:43
Output of a Unit, contains a buffer of rendered floats and has a variable state flag.
Definition: BasicNodes.h:354
Patchable & in_select()
Sets "select" as selected input and returns this Unit ready to be patched. This input change the samp...
Definition: Sampler.cpp:47
Patchable & in_direction()
Sets "direction" as selected input and returns this Unit ready to be patched. A positive value will s...
Definition: Sampler.cpp:59
Patchable & in_trig()
Sets "trig" as selected input and returns this Unit ready to be patched. This is the default input...
Definition: Sampler.cpp:39
Patchable & in_start_mod()
Sets "start_mod" as selected input and returns this Unit ready to be patched. This input change how m...
Definition: Sampler.cpp:55