繁体   English   中英

获取外部耳机 (8):当我尝试使用 maximilian 时出现 EXC_BAD_ACCESS (code=1, address=0x0) 错误

[英]Getting External Headphones (8): EXC_BAD_ACCESS (code=1, address=0x0) error when I am trying to use maximilian

我正在使用带有 JUCE 的 maximilian 库进行测试。 我正在尝试使用 maxiSample 功能,并且我已经完全按照示例代码所说的方式实现了它。 每当我运行独立应用程序时,我都会收到错误“外部耳机 (8): EXC_BAD_ACCESS (code=1, address=0x0)”,它在 maximilian.cpp 的第 747 行给了我一个断点。 这不是我的耳机,因为它对任何播放设备都做同样的事情。 真是不知所措。

我在下面附上了我的 MainComponent.cpp。 任何建议都会很棒,谢谢!

#include "MainComponent.h"
#include "maximilian.h"

//==============================================================================
MainComponent::MainComponent()
{
    // Make sure you set the size of the component after
    // you add any child components.
    setSize (800, 600);

    // Some platforms require permissions to open input channels so request that here
    if (juce::RuntimePermissions::isRequired (juce::RuntimePermissions::recordAudio)
        && ! juce::RuntimePermissions::isGranted (juce::RuntimePermissions::recordAudio))
    {
        juce::RuntimePermissions::request (juce::RuntimePermissions::recordAudio,
                                           [&] (bool granted) { setAudioChannels (granted ? 2 : 0, 2); });
    }
    else
    {
        // Specify the number of input and output channels that we want to open
        setAudioChannels (2, 2);
    }
}

MainComponent::~MainComponent()
{
    // This shuts down the audio device and clears the audio source.
    shutdownAudio();
    sample1.load("/Users/(username)/JuceTestPlugins/maxiSample/Source/kick.wav");
}

//==============================================================================
void MainComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
{
    // This function will be called when the audio device is started, or when
    // its settings (i.e. sample rate, block size, etc) are changed.

    // You can use this function to initialise any resources you might need,
    // but be careful - it will be called on the audio thread, not the GUI thread.

    // For more details, see the help for AudioProcessor::prepareToPlay()
    
}

void MainComponent::getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill)
{
    // Your audio-processing code goes here!

    // For more details, see the help for AudioProcessor::getNextAudioBlock()

    // Right now we are not producing any data, in which case we need to clear the buffer
    // (to prevent the output of random noise)
    //bufferToFill.clearActiveBufferRegion();
    for(int sample = 0; sample < bufferToFill.buffer->getNumSamples(); ++sample){
        
        //float sample2 = sample1.
        //float wave = tesOsc.sinewave(200);
        //double sample2 = sample1.play();
        
//        leftSpeaker[sample] = (0.25 * wave);
//        rightSpeaker[sample] = leftSpeaker[sample];
        double *output;
        output[0] = sample1.play();
        output[1] = output[0];
        
    }
    
    
}

void MainComponent::releaseResources()
{
    // This will be called when the audio device stops, or when it is being
    // restarted due to a setting change.

    // For more details, see the help for AudioProcessor::releaseResources()
}

//==============================================================================
void MainComponent::paint (juce::Graphics& g)
{
    // (Our component is opaque, so we must completely fill the background with a solid colour)
    g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));

    // You can add your drawing code here!
}

void MainComponent::resized()
{
    // This is called when the MainContentComponent is resized.
    // If you add any child components, this is where you should
    // update their positions.
}

不能肯定地说,但有几件事引起了我的注意。

在 getNextAudioBlock() 中,您正在取消引用无效指针:

double *output;
output[0] = sample1.play();
output[1] = output[0];

指针变量output未初始化,可能会被垃圾或零填充,这将使程序从无效的 memory 读取。 这个问题最有可能导致EXC_BAD_ACCESS 此方法是从实时音频线程调用的,因此您可能会在非主线程(在本例中为External Headphones (8)的线程)崩溃。

我也不清楚你到底想在这里做什么,所以我很难说它应该是怎样的。 我可以说的是,将 sample1.play() 的结果分配给 double 值看起来很可疑。

通常,在处理juce::AudioSourceChannelInfo时,您将获得指向音频缓冲区的指针,如下所示:

auto** bufferPointer = bufferToFill.buffer->getArrayOfWritePointers()

此外,您正在 MainComponent 的析构函数中加载一个文件。 这至少是可疑的,为什么要在销毁期间加载文件?

MainComponent::~MainComponent()
{
    // This shuts down the audio device and clears the audio source.
    shutdownAudio();
    sample1.load("/Users/(username)/JuceTestPlugins/maxiSample/Source/kick.wav");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM