Bass Mixer Example

Started by David_AVD,

David_AVD

Can someone please show an example for playing multiple audio streams via a mixer?

What I want to do is create the mixer and apply volume, pan and perhaps VST effects to the combined output.

The audio streams going into the mixer would be created and started some time after the mixer is created.

I'm using Delphi, but should be able to work out any example shown in C, basic, etc. Thank you.

Ian @ un4seen

The code for that would basically look something like this:

// setup mixer
mixer = BASS_Mixer_StreamCreate(freq, chans, BASS_SAMPLE_FLOAT); // create mixer with wanted format
BASS_ChannelSetAttribute(mixer, BASS_ATTRIB_BUFFER, 0); // disable playback buffering (optional for lower latency)
BASS_ChannelStart(mixer); // start it

...

// start playing source through mixer
BASS_Mixer_StreamAddChannel(mixer, source, 0);

...

// stop playing source through mixer
BASS_Mixer_ChannelRemove(source);

Note the sources must be decoding channels, created with BASS_STREAM_DECODE set. To avoid unnecessary resampling, the mixer's sample format should match the sources' format (if they're all the same) or the output device's format (available from BASS_GetInfo). You would use the mixer handle in BASS_ChannelSetAttribute and BASS_VST_ChannelSetDSP calls to apply volume/pan changes and VST effects to the mix. Please see the documentation for details on the mentioned functions.

David_AVD

Thanks for that. I have a simple example working, but still need to work out how to create and remove sources on the fly. Some of my code (to do with freeing sources) is causing an issue and locking up my application. I'll come back with more questions once I get my head around it some more.

David_AVD

My existing code (with no mixer) uses BASS_ChannelSetSync a lot.

If I'm using SyncProc on the sources feeding a mixer could this be an issue?

Ian @ un4seen

It will depend on the type of sync. A mixer source is a decoding channel, which means all syncs on it are "mixtime". If a sync was already mixtime then nothing has changed, but otherwise the sync would be called earlier than expected (ie. before it's heard). You can prevent that by using BASS_Mixer_ChannelSetSync instead of BASS_ChannelSetSync. Please see the BASS_Mixer_ChannelSetSync documentation for details.