TransportAudioSourceMixerAudioSource

So I looked at this error some more - it only occurs when the input source is a pointer, so there probably some wrong with my code, here’s a more basic example

// this works fine
inputReaders.add(new AudioFormatReaderSource(reader, true));

// this fails with same error
std::unique_ptr<AudioFormatReaderSource> newSource(new AudioFormatReaderSource(reader, true));
inputReaders.add(newSource.get());

Any thoughts?

BTW, I cam at this from wondering if there was an approach without TransportAudioSources - and wondering if i can just use the AddInputSource and RemoveInputSource gracefully while the mixer is running as

Input sources can be added and removed while the mixer is running as long as their prepareToPlay() and releaseResources() methods are called before and after adding them to the mixer.

You are adding a raw pointer into your array ( .get() ), but the pointer is already managed by the unique_ptr, so that’s not going to work. When the unique_ptr goes out of scope, it deletes the owned object and the pointer pointing to that in the array is no longer valid. Because the array is an OwnedArray, you can create and assign the newSource instance into a raw pointer instead of the unique_ptr.

AudioFormatReaderSource* newSource=new AudioFormatReaderSource(reader, true); 
inputReaders.add(newSource);
1 Like

Yes, that makes sense. And works.