Author Topic: Streaming large audio files from disk in sync  (Read 578 times)

_chris

  • Posts: 3
Hi all,

I have been asked to build some software that plays back a piece of music that has been split into 24 mono wav files (each 96kHz, 24bit). The tracks make up one piece so they have to play in sync. The tracks can also be very long (over a hour).

After doing some research I came across BASS which looks like it might do the job nicely. Currently I am looking into BASS.NET but may switch to C++ later as the project has some other C++ bits.

I have managed to get the 24 tracks to play back simply by calling the BASS_StreamCreateFile method 24 times and then calling the BASS_ChannelPlay method on each stream however, as expected, the sounds are not in sync.

Can anyone point me in the right direction for playing back the sound in sync? If possible I rather not use a multi-channel audio file but if that is the only way then I will. Below is my current code.

Thanks!


Code: [Select]
int numStreams = 24;
int[] streams = new int[24];

// init BASS using the default output device
if ( Bass.BASS_Init(-1, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) )
{
    for (int i = 0; i < numStreams; i++)
    {
        streams[i] = Bass.BASS_StreamCreateFile("testbeat.wav", 0L, 0L, BASSFlag.BASS_DEFAULT);
    }

    // wait for a key
    Console.WriteLine("Press any key to play");
    Console.ReadKey(false);

    for (int i = 0; i < numStreams; i++)
    {
        Bass.BASS_ChannelPlay(streams[i], false);
    }

    // wait for a key
    Console.WriteLine("Press any key to exit");
    Console.ReadKey(false);

    // free the stream
    for (int i = 0; i < numStreams; i++)
    {
        Bass.BASS_StreamFree(streams[i]);
    }

    // free BASS
    Bass.BASS_Free();
}

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Streaming large audio files from disk in sync
« Reply #1 on: 13 Nov '14 - 15:54 »
You could use the BASSmix add-on to achieve that, ie. create a mixer and plug all of the files into it. The code could look something like this...

Code: [Select]
    mixer = BASS_Mixer_StreamCreate(96000, 1, BASS_MIXER_END|BASS_SAMPLE_FLOAT); // create a 96khz mono mixer
    for (int i = 0; i < numStreams; i++)
    {
        streams[i] = BASS_StreamCreateFile(filename[i], 0L, 0L, BASS_STREAM_DECODE|BASS_SAMPLE_FLOAT); // create a decoder for the file
        BASS_Mixer_StreamAddChannel(mixer, streams[i], 0); // plug it into the mixer
    }
    BASS_ChannelPlay(mixer, FALSE); // start the mixer

Please see the documentation for details on the aforementioned functions.

_chris

  • Posts: 3
Re: Streaming large audio files from disk in sync
« Reply #2 on: 13 Nov '14 - 16:36 »
Great, thanks for the quick reply - that seems to work nicely.