JUCE框架教程(8)——DSP Module基础

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插件应用到工程的过程。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值