Author Topic: [SOLVED] Multi-channel OGG mixing  (Read 58 times)


  • Posts: 2
[SOLVED] Multi-channel OGG mixing
« on: 16 May '18 - 10:25 »
I picked up BASS today and first off, I'd like to thank you for making such a well-made audio library. Over the past few days I have tried several audio libaries and they were either too complex, failed to compile, lacked features or weren't in C. In a day I've nearly finished the audio part of my engine, minus multi-channel OGG support.

I want to play dynamic music using the same method explained here and here. I've split up a song into 4 channels: mainL, mainR, drumsL, drumsR. When I load this into BASS, it only plays mainL and mainR. If I move drumsL and drumsR to the top, those are played instead. I thought BASS_ATTRIB_MUSIC_VOL_CHAN would let me change channel volume, but that only works for MOD files. Could you please show me an example of panning individual OGG channels? The code I currently use for loading music is:

Code: [Select]
void sfx_song(char *name) {
const char *tags;
char file[64];
float loop_start;
sprintf(file, "music/%s.ogg", name);

/* Stop current song if playing. */
if (BASS_ChannelIsActive(song) == BASS_ACTIVE_PLAYING) {

/* Initialize song, get loop information from comments. */
song = BASS_StreamCreateFile(FALSE, file, 0, 0, 0);
tags = BASS_ChannelGetTags(song, BASS_TAG_OGG);
loop_start = atof(tags + strlen("COMMENTS="));

/* Set loop callback and play. */
sync = BASS_ChannelSetSync(song, BASS_SYNC_END | BASS_SYNC_MIXTIME, 0, end_callback, 0);
loop = BASS_ChannelSeconds2Bytes(song, loop_start);
BASS_ChannelPlay(song, FALSE);
« Last Edit: 18 May '18 - 11:18 by DragonDePlatino »

Ian @ un4seen

  • Administrator
  • Posts: 20764
Re: Multi-channel OGG mixing
« Reply #1 on: 16 May '18 - 17:27 »
That looks like the BASSmix add-on's matrix mixing option would be what you want. It allows you to downmix the source to stereo, with any combination of channels and levels. You could set it up something like this:

Code: [Select]
song = BASS_StreamCreateFile(FALSE, file, 0, 0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT); // create a decoder for the file
mixer = BASS_Mixer_StreamCreate(freq, 2, BASS_MIXER_END); // create a stereo mixer with the same sample rate as the file
BASS_Mixer_StreamAddChannel(mixer, song, BASS_MIXER_MATRIX); // plug the decoder into the mixer with matrix mixing enabled

float matrix[2][4]; // matrix for 2 outputs and 4 inputs
// set the matrix values here
BASS_Mixer_ChannelSetMatrix(song, matrix); // apply it

BASS_ChannelPlay(mixer, FALSE); // start the mixer

Please see the BASSmix documentation for details on the mentioned functions. Also see the "Matrix mixing" section.

If you will need to be able to change the matrix mid-playback and have the change heard immediately, you may also want to disable playback buffering via the BASS_ATTRIB_BUFFER option:

Code: [Select]
BASS_ChannelSetAttribute(mixer, BASS_ATTRIB_BUFFER, 0); // disable playback buffering on the mixer


  • Posts: 2
Re: Multi-channel OGG mixing
« Reply #2 on: 18 May '18 - 11:18 »
Thank you for explaining this! I never would've figured to check out the different BASS add-ons. My audio system works like a charm now.