Author Topic: Mix audio files  (Read 204 times)

nudrick

  • Posts: 8
Mix audio files
« on: 7 May '18 - 18:36 »
Hello everybody

I have created a .net application that is able to mix multiple files and to low up/down the volume of each file when I need to change the song. I would like to know if the following is possible:
1. I have 2 audio files, each of them of 30 seconds
2. When the first audio will be in the second 20, I will low down the volume
3. Exactly when the first audio is fading out, the second audio will start playing with a fade in effect.

In certain moment, both files will be playing at the same time.

Is that possible to be done?

Thanks!

Ian @ un4seen

  • Administrator
  • Posts: 21136
Re: Mix audio files
« Reply #1 on: 8 May '18 - 13:28 »
Yes, that is possible. You can use BASS_ChannelSlideAttribute with BASS_ATTRIB_VOL to do the fading-in/out, and you can use a BASS_SYNC_POS sync to trigger it after 20 seconds. Perhaps something like this:

Code: [Select]
BASS_ChannelSetSync(channel1, BASS_SYNC_POS, BASS_ChannelSeconds2Bytes(channel1, 20), CrossfadeSyncProc, 0); // set a POS sync at 20s

...

void CALLBACK CrossfadeSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_ChannelSlideAttribute(channel, BASS_ATTRIB_VOL, 0, 10000); // fade-out this channel over 10s
BASS_ChannelSetAttribute(channel2, BASS_ATTRIB_VOL, 0); // mute the other channel
BASS_ChannelSlideAttribute(channel2, BASS_ATTRIB_VOL, 1, 10000); // fade-in over 10s
BASS_ChannelPlay(channel2, 0); // start it
}

Please see the documentation for details on the mentioned functions.