MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / Process

Method Process

Source/SampleCanvas.cpp:86–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86void SampleCanvas::Process(double time)
87{
88 PROFILER(SampleCanvas);
89
90 IAudioReceiver* target = GetTarget();
91
92 if (!mEnabled || target == nullptr)
93 return;
94
95 float canvasPos = GetCurPos(time);
96
97 mCanvas->SetCursorPos(canvasPos);
98
99 int bufferSize = target->GetBuffer()->BufferSize();
100 assert(bufferSize == gBufferSize);
101
102 gWorkChannelBuffer.Clear();
103
104 const std::vector<CanvasElement*>& elements = mCanvas->GetElements();
105 for (int elemIdx = 0; elemIdx < elements.size(); ++elemIdx)
106 {
107 SampleCanvasElement* element = static_cast<SampleCanvasElement*>(elements[elemIdx]);
108 Sample* clip = element->GetSample();
109 float vol = element->GetVolume();
110 if (clip == nullptr || element->IsMuted())
111 continue;
112
113 for (int i = 0; i < bufferSize; ++i)
114 {
115 float sampleIndex = 0;
116
117 float pos = GetCurPos(time + i * gInvSampleRateMs);
118
119 sampleIndex = ofMap(pos, element->GetStart(), element->GetEnd(), 0, clip->LengthInSamples());
120
121 if (sampleIndex >= 0 && sampleIndex < clip->LengthInSamples())
122 {
123 for (int ch = 0; ch < target->GetBuffer()->NumActiveChannels(); ++ch)
124 {
125 int sampleChannel = MAX(ch, clip->NumChannels() - 1);
126 gWorkChannelBuffer.GetChannel(ch)[i] += GetInterpolatedSample(sampleIndex, clip->Data()->GetChannel(sampleChannel), clip->LengthInSamples()) * vol;
127 }
128 }
129 }
130 }
131
132 for (int ch = 0; ch < target->GetBuffer()->NumActiveChannels(); ++ch)
133 {
134 ChannelBuffer* out = GetTarget()->GetBuffer();
135 Add(out->GetChannel(ch), gWorkChannelBuffer.GetChannel(ch), gBufferSize);
136 GetVizBuffer()->WriteChunk(gWorkChannelBuffer.GetChannel(ch), gBufferSize, ch);
137 }
138}
139
140double SampleCanvas::GetCurPos(double time) const
141{

Callers

nothing calls this directly

Calls 15

ofMapFunction · 0.85
GetInterpolatedSampleFunction · 0.85
AddFunction · 0.85
SetCursorPosMethod · 0.80
BufferSizeMethod · 0.80
GetBufferMethod · 0.80
sizeMethod · 0.80
GetVolumeMethod · 0.80
IsMutedMethod · 0.80
GetStartMethod · 0.80
GetEndMethod · 0.80
LengthInSamplesMethod · 0.80

Tested by

no test coverage detected