首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取外部耳机(8):当我试图使用马西米兰时EXC_BAD_ACCESS (code=1,address=0x0)错误

获取外部耳机(8):当我试图使用马西米兰时EXC_BAD_ACCESS (code=1,address=0x0)错误
EN

Stack Overflow用户
提问于 2021-12-07 20:58:37
回答 1查看 171关注 0票数 0

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

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

代码语言:javascript
复制
#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.
}
EN

回答 1

Stack Overflow用户

发布于 2021-12-08 18:24:59

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

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

代码语言:javascript
复制
double *output;
output[0] = sample1.play();
output[1] = output[0];

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

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

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

代码语言:javascript
复制
auto** bufferPointer = bufferToFill.buffer->getArrayOfWritePointers()

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

代码语言:javascript
复制
MainComponent::~MainComponent()
{
    // This shuts down the audio device and clears the audio source.
    shutdownAudio();
    sample1.load("/Users/(username)/JuceTestPlugins/maxiSample/Source/kick.wav");
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70266855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档