Author Topic: [VB.NET] Split-Streams not starting synchron  (Read 4634 times)

Scarala

  • Posts: 11
Hello guys,

i have a new problem with my program.

i am Splitting a channel into 3 channels with
Code: [Select]
deckA = Bass.BASS_StreamCreateFile(ListView1.Items.Item(0).Text, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_DECODE)
deckA1 = BassMix.BASS_Split_StreamCreate(deckA, BASSFlag.BASS_STREAM_DECODE, Nothing)
deckA2 = BassMix.BASS_Split_StreamCreate(deckA, BASSFlag.BASS_STREAM_DECODE, Nothing)
deckA3 = BassMix.BASS_Split_StreamCreate(deckA, BASSFlag.BASS_STREAM_DECODE, Nothing)
but when i start the three channels with
Code: [Select]
BassMix.BASS_Mixer_StreamAddChannel(mixer, deckA1, BASSFlag.BASS_DEFAULT)
BassMix.BASS_Mixer_StreamAddChannel(mixerEncoder, deckA2, BASSFlag.BASS_DEFAULT)
BassMix.BASS_Mixer_StreamAddChannel(mixerPeak, deckA3, BASSFlag.BASS_DEFAULT)
there is a delay of up to 500ms between deckA1 and deckA3.

I need the three channels becase deckA1 is the local played channel, deckA2 is locally muted and send to a shoutcast-stream (i don´t want to hear my Microphone locally, so i made a locally muted mixer for encoding to shoutcast-server) and deckA3 is needed for Visualisation an Peak.

But the channles are not synchron.

I hope anyone can help me.

Here is the actuall full-code of my Project:
http://de.sourcepod.com/ijmghr81-17361

Greetings from Germany

Scarala
« Last Edit: 20 Mar '13 - 10:07 by Scarala »

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: [VB.NET] Split-Streams not starting synchron
« Reply #1 on: 20 Mar '13 - 13:43 »
The problem you're having could be due to the 3 mixers having different amounts of data already buffered when you add the splitters to them. Note a new mixer source won't be heard from the mixer output until after the buffered data is played. It should be possible to compensate for that by delaying the splitters according to the amount of data that the mixers have buffered, eg. if mixer A has 500ms of data buffered and mixer B has 300ms of data buffered, then the new source should be delayed by 200ms in mixer B, so that the source ends up delayed by 500ms in both mixers. The amount of buffered data is available from BASS_ChannelGetData with BASS_DATA_AVAILABLE, and you could do something like this...

Code: [Select]
// lock the mixers to block processing in the middle of this
BASS_ChannelLock(mixer1, TRUE);
BASS_ChannelLock(mixer2, TRUE);
// get amount of data in mixer playback buffers
DWORD buffered1=BASS_ChannelGetData(mixer1, 0, BASS_DATA_AVAILABLE),
buffered2=BASS_ChannelGetData(mixer2, 0, BASS_DATA_AVAILABLE);
if (buffered1>buffered2) { // mixer1 has more buffered data than mixer2, so delay mixer2...
BASS_Mixer_StreamAddChannel(mixer1, splitter1, flags); // add source to mixer1
BASS_Mixer_StreamAddChannelEx(mixer2, splitter2, flags, buffered1-buffered2, 0); // add source to mixer2 with delay
} else {
BASS_Mixer_StreamAddChannelEx(mixer1, splitter1, flags, buffered2-buffered1, 0); // add source to mixer1 with delay
BASS_Mixer_StreamAddChannel(mixer2, splitter2, flags); // add source to mixer2
}
// unlock the mixers
BASS_ChannelLock(mixer1, FALSE);
BASS_ChannelLock(mixer2, FALSE);

Please see the documentation for details on the aforementioned functions. By the way, are you sure you really need the "mixerPeak" mixer? Couldn't you just get the level from one of the other 2 mixers?

Scarala

  • Posts: 11
Re: [VB.NET] Split-Streams not starting synchron
« Reply #2 on: 20 Mar '13 - 13:55 »
I will test that.

With the mixerPeak... If i get the Level from deckA1 or deckA2 it runs nearly with double speed...

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: [VB.NET] Split-Streams not starting synchron
« Reply #3 on: 20 Mar '13 - 16:02 »
Yes, getting the level directly from the sources would cause problems (missing data in the mixer output), but getting the level from the other mixers (ie. "mixer" and "mixerEncoder") shouldn't cause any such problems.

Scarala

  • Posts: 11
Re: [VB.NET] Split-Streams not starting synchron
« Reply #4 on: 20 Mar '13 - 17:27 »
I will test that tomorrow.

Scarala

  • Posts: 11
Re: [VB.NET] Split-Streams not starting synchron
« Reply #5 on: 21 Mar '13 - 06:05 »
Edit:
Now everything runs perfectly, i made a mistake, i´ve forgotten to initialize the mixerPeak before adding the stream to it, because of this, the delay was such big.
« Last Edit: 21 Mar '13 - 09:48 by Scarala »