Start and mix AudioTransportSource

Hi everybody,

I try to figure a design for a simple DAW project. I need to start audio snippets and mix them to the AudioSourcePlayer. So I will need to ask a bunch of question, sorry for that:

a) To play various AudioSources, I will need to use a MixerAudioSource and set is as source to AudioSourcePlayer, right?

b) There is no "global" position, not even in AudioTransportSource, right? Is it my responsibility to start all scheduled AudioTransportSources at the correct time? Or is there a concept I've missed?

c) Can AudioTransportSources (i.e. PositionableAudioSources) have negative values for "setPosition", so that they get scheduled in the future?

Or maybe I think too complicated? Thanks for hints, there is always a lot to learn...

Hi daniel, I think you are on the right track. Let me answer in more details to your points:

a) To play various AudioSources, I will need to use a MixerAudioSource and set is as source to AudioSourcePlayer, right?

Yes exactly!

b) There is no "global" position, not even in AudioTransportSource, right? Is it my responsibility to start all scheduled AudioTransportSources at the correct time? Or is there a concept I've missed?

Yes. I think you are right. It would be an interesting addition to JUCE to have something like a PositionableMixerAudioSource which not only mixes several PositionableAudioSources but also synchronises a setPosition call to all of the sources. This audio source could then be added to the AudioTransportSource. Maybe there are better ways of doing this though...

c) Can AudioTransportSources (i.e. PositionableAudioSources) have negative values for "setPosition", so that they get scheduled in the future?

setPosition can be negative. However, the AudioTransportSource doesn't do any "scheduling" itself. It just passes the call to the PositionableAudioSource (see the implementation here). So it will ultimately depend on what the underlying source will do with negative values.

 

Does this answer your questions?

 

 

Great, thanks for your reply. I think I get a more and more better understanding of how things are done.

For b) it can be solved by myself easily, I simply need to keep a list of all sources to the mixer and propagate a start to all of them, same as the stop. Would be nice to use the mixer's list, but as far as I can see it's no longer accessible after addInputSource.

For c) I lose track in the inheritance tree. I can't find the spot in the source where the actual filling of the buffer is done. The getNextReadPosition has my attention, I would expect the obvious that if getNextReadPosition is negative, that the buffer is filled with silence in the getNextAudioBlock method and the buffersize is simply consumed until the next return of the thread. This is implicitly what I want, so the play is like scheduled until the negative time period of setPosition is over.

I will try that as soon as my MixerAudioSource is playing.

On point c):

The actual filling of the buffer is not done by the AudioTransportSource, it just passes the readNextAudioBuffer to the source. Therefore, the positionable audio source will need to deal with negative offset.

Yes I saw that, and that's the point where my head started smoking: the AudioTransportSource IS as PositionableAudioSource by inheritance, but also aggregates an AudioSource as masterSource. But either way, the filling can be done by ANY AudioSource heir as you pointed out. Oh no wait, it's created internally by AudioTransportSource and it's always a ResamplingAudioSource. And now again, this ResamplingAudioSource holds a OptionalScopedPointer called input to an AudioSource, and I am back where I started...

This is either crazy or brilliant, at least it's too much for my head... ;-)

...and it works as expected. I just verified it in a playground project, at least for AudioTransportSource holding an AudioFormatReaderSource. But I think it's safe to use this. If it is a clever idea to have all clips started simultanously can be discussed, it gives additional load on the mixing thread but saves the programming task to have a global sample accurate timer to start and stop the future clips at the right time.

Thanks for the great work and for the help on the forum.

1 Like