How to overwrite sourcebuffer for switching play mp3 files?


#1

Hi. guys
How are you?
I plan to do the following application for playback and use the same audioTransportSource.

first playing a wav file A for 20 secs, I choose wav file B to continue play starting from that moment. Continue to play until 40secs, choose file C to play from that moment.

I try to make use of single AudioTransportSource to do it, and overwrite the source buffer of A .

for example, AudioTransportSource get data from source buffer A for 20secs. after switch,it starts to overwrite A’s buffer with file B’s data from 20secs to 40secs, then overwrite A’s buffer with C’s data from 40 secs… like this way.
we may has some delay for overiting the buffer.
we also can use it for mp3 file, since I use MP3audioFormatReader .cpp file searched on juce forum to deal with mp3 decoding job.

In this way, we do not need to initialize the audioTransportSource for each mp3 files, and the switch process will be under control and just read the data from the same buffer.

any ideas?
Thanks!
Leon


#2

btw, I may create some buffer by using memoryblock class. I send the source data to that buffer , when switch the source files, just write the new data from the new file to the right position of the same buffer.
I also plan to use audioTransportSource ::getNextAudioBlock() to get the source data from that buffer.

Is that flexible to do this?

Thanks!
Leon


#3

Hi, jules
How are you?
any suggestions? or my question is not clear enough?

Thanks!
Leon


#4

I don’t really understand the question, but if it was me, I’d just write a custom audiosource that streams from two input sources and swaps between them at the right moment.


#5

Hi, jule
Thanks!
I also perfer to switching sources at the right moment rather than what I said before. I use setSource() function to change the audioFormatReaderSource while the audioTransportSource is running. And I get the time instant for the switching moment by using getCurrentPosition() and setPosition().The switching process seems smooth without noise.

however, I am not sure whether source switching has significant overhead(several milli seconds or several blocks of data ). for example, how much time does the execution of the switching code spend? we may not switch at the exactly right time due to the overhead. After many switchings, we may see the big difference compared with the global time it should be.

what’s your ideas?

Cheers!
Leon


#6

If you need something really high-performance or which needs to be absolutely click-free, you might need to actually do a proper class for this, with its own background thread that manages the upcoming material and reads-ahead intelligently, etc. The audio source classes work fine, but they’re not designed to cope with low-latency switching.