JUCE框架教程(8)——DSP Module基础
JUCE的DSP模块是JUCE官方提供的DSP库,它包含了很多基本的DSP插件,能帮助您快速搭建一个音频插件。
如何使用DSP模块
1.在项目中引入DSP库
2.初始化
juce::dsp::Chorus<float> chorus;
3.准备和重置DSP
在prepareToPlay
函数中,最后加入
juce::dsp::ProcessSpec spec;
spec.maximumBlockSize = samplesPerBlock;
spec.sampleRate = sampleRate;
chorus.prepare(spec);
chorus.reset();
4.新建参数
void DSPAudioProcessor::parameterChanged(const juce::String& parameterID, float newValue) {
if (parameterID == "RATE") chorus.setRate(newValue);
//......
}
5.处理DSP
void DSPAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
juce::dsp::AudioBlock<float> sampleBlock(buffer);
chorus.process(juce::dsp::ProcessContextReplacing<float>(sampleBlock));
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
// Make sure to reset the state if your inner loop is processing
// the samples and the outer loop is handling the channels.
// Alternatively, you can process the samples with the channels
// interleaved by keeping the same state.
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
// ..do something to the data...
}
}
这样,我们就完成了将一个DSP插件应用到工程的过程。