您现在的位置是:首页 >技术交流 >Juce音频算法demo网站首页技术交流
Juce音频算法demo
用juce 平台写一个声卡进直接声卡出的demo 程序?

2023/6/2
以下是在JUCE平台上实现声卡输入直接输出的示例代码和步骤:
步骤 1: 创建一个新的JUCE项目
首先,您需要创建一个新的JUCE项目并设置其最小配置。您可以使用Projucer应用程序完成此操作。您可以从官方网站下载并安装该应用程序。
创建一个名为“SoundCardDemo”的新项目,并设置以下选项(在Projucer中选择菜单“Projucer Project” > “Project Settings”):
Target platform:Windows;
Config type: VST3 Plug-in;
Plugin channel configuration: Mono in, Mono out;
Minimum API level: Windows 7。
保存并生成你的项目,然后转到下一步。
步骤 2: 编写代码
打开您的项目代码编辑器,您将看到生成的默认代码。我们将在其中添加一些代码以读取声卡输入并将其直接输出。
打开 PluginProcessor.h 文件,添加以下代码:
cpp
复制代码
class SoundCardDemoAudioProcessor : public juce::AudioProcessor
{
public:
//==============================================================================
SoundCardDemoAudioProcessor();
~SoundCardDemoAudioProcessor() override;
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
#endif
void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
//==============================================================================
juce::AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
const juce::String getName() const override;
private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SoundCardDemoAudioProcessor)
};
这是您的插件处理器类。现在,我们将添加一些实现代码。
打开 PluginProcessor.cpp 文件,在 include 语句下面添加以下代码:
cpp
复制代码
SoundCardDemoAudioProcessor::SoundCardDemoAudioProcessor()
{
}
SoundCardDemoAudioProcessor::~SoundCardDemoAudioProcessor()
{
}
void SoundCardDemoAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
}
void SoundCardDemoAudioProcessor::releaseResources()
{
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool SoundCardDemoAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
return true;
}
#endif
void SoundCardDemoAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
// simply copy the input channels to the output channels
for (auto channel = 0; channel < totalNumInputChannels; ++channel)
buffer.copyFrom(channel, 0, buffer, channel, 0, buffer.getNumSamples());
}
juce::AudioProcessorEditor* SoundCardDemoAudioProcessor::createEditor()
{
return nullptr; // no editor needed
}
bool SoundCardDemoAudioProcessor::hasEditor() const
{
return false;
}
const juce::String SoundCardDemoAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool SoundCardDemoAudioProcessor::acceptsMidi() const
{
return false;
}
bool SoundCardDemoAudioProcessor::producesMidi() const
{
return false;
}
double SoundCardDemoAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int SoundCardDemoAudioProcessor::getNumPrograms()
{
return 1;
}
int SoundCardDemoAudioProcessor::getCurrentProgram()
{
return 0;
}
void SoundCardDemoAudioProcessor::setCurrentProgram (int index)
{
}
const juce::String SoundCardDemoAudioProcessor::getProgramName (int index)
{
return {};
}
void SoundCardDemoAudioProcessor::changeProgramName (int index, const juce::String& newName)
{
}
这些是您的插件处理器类的实现。它将声卡输入直接输出。在 processBlock 函数中,我们只是从输入缓冲区复制数据到输出缓冲区。
现在,我们需要做一些设置以