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

Method ProcessAudio

Source/Stutter.cpp:51–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void Stutter::ProcessAudio(double time, ChannelBuffer* buffer)
52{
53 PROFILER(Stutter);
54
55 float bufferSize = buffer->BufferSize();
56
57 mRecordBuffer.SetNumChannels(buffer->NumActiveChannels());
58 mStutterBuffer.SetNumActiveChannels(buffer->NumActiveChannels());
59
60 for (int ch = 0; ch < buffer->NumActiveChannels(); ++ch)
61 mRecordBuffer.WriteChunk(buffer->GetChannel(ch), bufferSize, ch);
62
63 if (mBlendRamp.Target(time) > 0 || mBlendRamp.Value(time) > 0)
64 {
65 if (mCurrentStutter.interval == kInterval_None)
66 {
67 mStutterLengthRamp.Start(time, mFreeStutterLength * gSampleRate, time + 20);
68 mStutterSpeed.Start(time, mFreeStutterSpeed, time + 20);
69 }
70
71 for (int i = 0; i < bufferSize; ++i)
72 {
73 if (mCurrentStutter.interval != kInterval_None)
74 mStutterLength = int(TheTransport->GetDuration(mCurrentStutter.interval) / 1000 * gSampleRate);
75 else
76 mStutterLength = int(mStutterLengthRamp.Value(time));
77
78 float offset = mStutterPos;
79 if (offset > mStutterLength)
80 offset -= mStutterLength;
81 int pos = int(offset);
82 int posNext = int(offset + 1) % mStutterLength;
83 float a = offset - pos;
84
85 for (int ch = 0; ch < buffer->NumActiveChannels(); ++ch)
86 {
87 float sample = GetStutterSampleWithWraparoundBlend(pos, ch);
88 float nextSample = GetStutterSampleWithWraparoundBlend(posNext, ch);
89 float stutterOut = (1 - a) * sample + a * nextSample; //interpolate
90
91 float fade = 1;
92 if (mFadeStutter)
93 fade -= (offset / mStutterLength) * (offset / mStutterLength);
94
95 float blend = mBlendRamp.Value(time);
96
97 buffer->GetChannel(ch)[i] = stutterOut * blend * fade + buffer->GetChannel(ch)[i] * (1 - blend);
98 buffer->GetChannel(ch)[i] = mJumpBlender[ch].Process(buffer->GetChannel(ch)[i], i);
99 }
100
101 //TODO(Ryan) what was this for?
102 //if (blend == 0 && mBlendRamp.Target() == 0)
103 // break;
104
105 mStutterPos += mStutterSpeed.Value(time);
106 if (mStutterPos > mStutterLength)
107 mStutterPos -= mStutterLength;
108 if (mStutterPos < 0)

Callers

nothing calls this directly

Calls 11

BufferSizeMethod · 0.80
SetNumChannelsMethod · 0.80
NumActiveChannelsMethod · 0.80
SetNumActiveChannelsMethod · 0.80
WriteChunkMethod · 0.80
GetChannelMethod · 0.80
TargetMethod · 0.80
GetDurationMethod · 0.80
ValueMethod · 0.45
StartMethod · 0.45
ProcessMethod · 0.45

Tested by

no test coverage detected