How to read sound files without short interruption ?

Hi,

I try to read a lit of sound files in a continuous way.
When I use movieplayer.play (after a STOP event, I play the next sound file) or sound.play (with a “timer” and “isPlaying” method), I can’t launch the following sound files without hearing a (audible) short interruption. I would like that the sound doesn’t stop and it plays like it was a unique music file.

So my question is :
how to play distinct sound files without interruption, like if it only was a unique music file ?

Thanx for any ideas :wink:

Unless you can find some external thingy that plays from a buffer and let you feed that buffer while it is playing from it, you need to paste the audiofiles together before playing.
If you don’t need perfect gapless playing, maybe you could use two movieplayers and try to keep track of the end of the first track and try to start the second as close to the first ending as possible, maybe by calculating the exact time needed and do timerstuff that times this exactly. That could maybe be more exact than checking for isPlaying(?). I doubt that you can do that perfectly exact without and small errors (a small click or gap), but it may be better than stopping the first and then adding the second.
Maybe there is a short delay before starting playing and maybe that delay is different from time to time without a way to finding out in advance. -Then is may not be possible to do it well…

At the moment I am writing a cd-player with gapless playing and now have everything working audio-wise.
To my basic programming skills it got to be a little more complex than one would think to do this in realtime (and keeping track of everything). As I do not want to wait for slow loading the tracks from the cd and having them pasted together before playing, I grab the audio data from the cd in second long blocks and feed a buffer twice per second (while it is playing) until the buffer is several seconds long (so that it does not stop playing if there are small interruptions in the reading of audio data from the cd).
I am using the MBS audio plugin (Portaudio) to get some “real” access to the sound streaming and buffers. The MBS plugin has some ready to use buffers so you can keep feeding it memoryblocks of audio, more than is consumed, so if you need time to do other things, it will keep playing until the buffers are consumed.

To do gapless playing, it needs some work. That is probably the reason why so many audio players lack that feature.

[quote=148749:@Dominik Fusina]Hi,

I try to read a lit of sound files in a continuous way.
When I use movieplayer.play (after a STOP event, I play the next sound file) or sound.play (with a “timer” and “isPlaying” method), I can’t launch the following sound files without hearing a (audible) short interruption. I would like that the sound doesn’t stop and it plays like it was a unique music file.

So my question is :
how to play distinct sound files without interruption, like if it only was a unique music file ?

Thanx for any ideas ;)[/quote]

From other threads, it seems the player will always mark a pause between songs.

Maybe you could use duration to launch the second song in a new player ahead of time, in order to merge the two. It seems feasible to stack the two players on top of each other and simply switch visibility to the currently playing song, so the user always sees the same UI.

Interesting.

I already use 2 players. When the first STOPs, the second (with “preload” done) plays. And vice-versa. Between musics, I have a very short pause (milliseconds). Strange.

I’m going to take a look into “MBS Audio”…

For the moment, I did not find a correct solution.

I would guess that you don’t have any precision control of the buffers in the movieplayer/sound, so you never know exactly when things will happen. Buffer time left may also vary(?).

[quote=148776:@Dominik Fusina]I already use 2 players. When the first STOPs, the second (with “preload” done) plays. And vice-versa. Between musics, I have a very short pause (milliseconds). Strange.

I’m going to take a look into “MBS Audio”…

For the moment, I did not find a correct solution.[/quote]

The idea was not to wait until the first one stops, but to start the second before it does.

To not get audible clicks you need to be able to do the compensation so that you get the tracks to stop and play exactly right in time (in the order of way less than 1/10.000 of a second or so…). Even one sample (1/44.100 s) overlap may yield a click (worst case). I doubt that you can get that kind of precision with the movie player.

It would maybe be possible to get rid of the clicks by fading the file ends in and out for a ms or so (roughly 50 samples) and let them overlap slightly. It will still not be a perfect transition, but it will at least not make clicks. But before even thinking of such workarounds, I think one should test how stable the start, stop times and estimates really are. I think you need to get the files to start and stop within a few ms, for it to be worth exploring further

Roger is right. The ear can hear clicks in an amazing fashion. The eye is not as sharp. The ear is incredible.

The solution is to setup PostAudioMBS, where you set up a bufferedstream and you keep adding audio to it. You read the audio off the files and and call AddAudio to add audio to it, continuously. You’ll have to educate yourself on audio files and how to grab the audio out of them. If most of the time you are reading 16-bit stereo WAVE files, at least it’s consistent.

Thank you Garth. Use PortAudioMBS seems a very good idea.

Yes. For me it took some time to understand it, but it now does its job fine.

Another way I was thinking of was to make an empty (fake) audiofile of the full cd length, then add portions of the audiodata while playing. If only a small chunk of audio was inserted first, then playing of the audio could start immediately. Then whilie playing, the rest of the data would be added by changing the file data (ahead of what is being played). The movieplayer (or whatever) would think that it was playing a long audiofile, not knowing that the data would be mostly zeros at start.

I didn’t like the idea of unnecessarily writing to disk or using up memory (big memoryblock or ramdisk) for the full hour file. So I went with the MBS Audio Plugin.