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

Method Process

Source/Vocoder.cpp:74–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void Vocoder::Process(double time)
75{
76 PROFILER(Vocoder);
77
78 IAudioReceiver* target = GetTarget();
79
80 if (target == nullptr)
81 return;
82
83 SyncBuffers();
84
85 if (!mEnabled)
86 {
87 for (int ch = 0; ch < GetBuffer()->NumActiveChannels(); ++ch)
88 {
89 Add(target->GetBuffer()->GetChannel(ch), GetBuffer()->GetChannel(ch), GetBuffer()->BufferSize());
90 GetVizBuffer()->WriteChunk(GetBuffer()->GetChannel(ch), GetBuffer()->BufferSize(), ch);
91 }
92
93 GetBuffer()->Reset();
94 return;
95 }
96
97 ComputeSliders(0);
98
99 float inputPreampSq = mInputPreamp * mInputPreamp;
100 float carrierPreampSq = mCarrierPreamp * mCarrierPreamp;
101 float volSq = mVolume * mVolume;
102
103 int bufferSize = GetBuffer()->BufferSize();
104
105 int zerox = 0; //count up zero crossings
106 bool positive = true;
107 for (int i = 0; i < bufferSize; ++i)
108 {
109 if ((GetBuffer()->GetChannel(0)[i] < 0 && positive) ||
110 (GetBuffer()->GetChannel(0)[i] > 0 && !positive))
111 {
112 ++zerox;
113 positive = !positive;
114 }
115 }
116 bool fricative = zerox > (bufferSize * mFricativeThresh); //if a % of the samples are zero crossings, this is a fricative
117 if (fricative)
118 mFricDetected = true; //draw that we detected a fricative
119
120 mGate.ProcessAudio(time, GetBuffer());
121
122 mRollingInputBuffer.WriteChunk(GetBuffer()->GetChannel(0), bufferSize, 0);
123
124 //copy rolling input buffer into working buffer and window it
125 mRollingInputBuffer.ReadChunk(mFFTData.mTimeDomain, VOCODER_WINDOW_SIZE, 0, 0);
126 Mult(mFFTData.mTimeDomain, mWindower, VOCODER_WINDOW_SIZE);
127 Mult(mFFTData.mTimeDomain, inputPreampSq, VOCODER_WINDOW_SIZE);
128
129 mFFT.Forward(mFFTData.mTimeDomain,
130 mFFTData.mRealValues,
131 mFFTData.mImaginaryValues);

Callers

nothing calls this directly

Calls 15

AddFunction · 0.85
MultFunction · 0.85
ofRandomFunction · 0.85
FloatWrapFunction · 0.85
NumActiveChannelsMethod · 0.80
GetChannelMethod · 0.80
GetBufferMethod · 0.80
BufferSizeMethod · 0.80
WriteChunkMethod · 0.80
ReadChunkMethod · 0.80
ForwardMethod · 0.80
ComputeMethod · 0.80

Tested by

no test coverage detected