I am trying to develop a way to play multiples audio files at the same time, with no limit of audio files. I am facing an error of Built-in Output (8): EXC_BAD_ACCESS (code=1, address=0x68fa597cba70), with the following code:
MainComponent.cpp
//======================================== //Section [2] -- Playing Audio Helper Methods void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override { for(int i = 0; i < inputs.size(); i++) if(inputs[i] != NULL) inputs[i]->prepareToPlay (samplesPerBlockExpected, sampleRate); } void releaseResources() override { for(int i = 0; i < inputs.size(); i++) if(inputs[i] != NULL) inputs[i]->releaseResources(); } void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override { if(rowNumSelected != 0){ if (readerSource.get() == nullptr){ bufferToFill.clearActiveBufferRegion(); return; } for(int i = 0; i < inputs.size(); i++) if(inputs[i] != NULL) if(bufferToFill.buffer != NULL) inputs[i]->getNextAudioBlock(bufferToFill); //^^^Error^^^ -> Built-in Output (8): EXC_BAD_ACCESS (code=1, address=0x68fa597cba70) } } //======================================== bool keyPressed(const KeyPress &k, Component *c) override { //Subsection [g] -- Method Part (a) to Play Cue when selected and pressed if( k.getKeyCode() == juce::KeyPress::spaceKey ) { auto file = getAttributeFileForRowId(rowNumSelected-1); auto* reader = formatManager.createReaderFor (file); if (reader != nullptr) { std::unique_ptr<juce::AudioFormatReaderSource> newSource (new juce::AudioFormatReaderSource (reader, true)); newCue.setSource(newSource.get(), 0, nullptr, reader->sampleRate); inputs.add(newSource.get()); inputs.getLast()->prepareToPlay(1000, reader->sampleRate); newCue.start(); readerSource.reset (newSource.release()); } table.selectRow(rowNumSelected, false, true); return true; } //Subsection [h] -- Method Part (b) to Stop Cue when selected and pressed if( k.getKeyCode() == juce::KeyPress::escapeKey ) { newCue.stop(); return true; } return false; } juce::AudioFormatManager formatManager; std::unique_ptr<juce::AudioFormatReaderSource> readerSource; InputCachingMixerAudioSource mixer; AudioTransportSource newCue; Array<AudioSource*> inputs; https://stackoverflow.com/questions/65866958/how-to-play-multiple-audio-files-at-the-same-time-in-juce January 24, 2021 at 11:47AM
没有评论:
发表评论