Author Topic: Same Reverb for many streams  (Read 3133 times)

rv

  • Posts: 249
Same Reverb for many streams
« on: 15 Oct '16 - 21:10 »
Hello, I am using a vst reverb on bassmidi synth and tune the reverb of each midi channel
I am also using some vst instruments that are mixed together with a bassmixer

I would like to use the same vst reverb used by the bassmidi synth for the vst synths.

Is it possible to send an amount of the vst audio stream out to the bassmidi reverb?


I am using high quality reverb with high CPU need, and I like to have only ONE reverb for all the instruments, and only send more or less to the reverb

Maybe with some splitters , mixers and be able to mix some sound with the actual bassmidi reverb handle... ???

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #1 on: 17 Oct '16 - 17:20 »
It sounds like you're using BASS_MIDI_StreamGetChannel with BASS_MIDI_CHAN_REVERB and applying a VST effect to the returned channel, and now you want to apply the same effect instance to some VST instruments? I haven't tried it myself, but that may be possible by using a DSP function to mix the VST instruments with the data from BASSMIDI before applying the VST effect, ie. the DSP would have a higher "priority" setting than the VST effect. You could use a "push" stream and a BASSmix mixer to do the mixing, something like this:

Code: [Select]
reverbchan=BASS_MIDI_StreamGetChannel(midi, BASS_MIDI_CHAN_REVERB); // get MIDI stream's reverb channel
reverbmixer=BASS_Mixer_StreamCreate(freq, chans, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE); // create mixer with same format as reverb channel (always floating-point)
pushstream=BASS_StreamCreate(freq, chans, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, STREAMPROC_PUSH, NULL); // create push stream with same format
BASS_Mixer_StreamAddChannel(reverbmixer, pushstream, 0); // plug it into the mixer
// plug VST instruments into the mixer here

BASS_ChannelSetDSP(reverbchan, MixDSP, NULL, 2); // set DSP on reverb handle
// set VST effect on reverbchan with lower "priority" value here

...

void CALLBACK MixDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user)
{
BASS_StreamPutData(pushstream, buffer, length); // pass data to push stream
BASS_ChannelGetData(reverbmixer, buffer, length); // get data back from mixer
}

Note that the VST instrument's level will be affected by the MIDI_EVENT_REVERB_LEVEL setting then, as it's going through the MIDI's reverb channel.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #2 on: 5 Sep '17 - 01:04 »
Hello Ian...
Thank you for this code...  I finally tried it.  It works, but some crakles ... Need to understand more

What I need is that I can decide the amount of the VSTi sound to go to the reverb
So I think I need to add a splitter on the VSTi stream that goes to the reverb mixer, with a volume parameter

Not sure if I need 2 splitters. One for DRY and one for WET, or if I can use the source as DRY (as before) and the splitter as WET
Also I don't know why I have crackles. Is it possible that the splitter is adding some latency, and that VSTi can't be played in realtime anymore

Or maybe the bassmidi reverb DSP is asking data to the VSTi through the reverbmixer, but the VSTi is always a bit late after the bassmidi stream ?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #3 on: 5 Sep '17 - 15:59 »
What I need is that I can decide the amount of the VSTi sound to go to the reverb
So I think I need to add a splitter on the VSTi stream that goes to the reverb mixer, with a volume parameter

Not sure if I need 2 splitters. One for DRY and one for WET, or if I can use the source as DRY (as before) and the splitter as WET

You would need 2 splitters in that case. When using splitters, all access to the source data should be through a splitter, ie. you shouldn't get data from the source directly. Any data that is taken directly from the source won't be available to the splitter(s).

Also I don't know why I have crackles. Is it possible that the splitter is adding some latency, and that VSTi can't be played in realtime anymore

A splitter won't add any latency unless you have multiple splitters on the same source and they are drifting apart; those left behind will need to get the buffered data before they get fresh data. You can use BASS_Split_StreamGetAvailable to check how much buffered data there is.

What output buffer size are you using and does increasing that help?

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #4 on: 5 Sep '17 - 16:25 »
Yes they drift appart.
I am using a buffer of 256 samples with WASAPI Exclusive Event
Is it possible for the splitter to not buffer anything.
It just copy what is ACTUALLY inside the source buffer for the 2 splits

Maybe I need to reset the splitter every time I can't provide enough data, so the splitter will not always be late as it is always trying to run after the bass midi synth

Do I need to set the SLAVE flag on the 2nd split?

Any other ideas?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #5 on: 5 Sep '17 - 18:02 »
When multiple splitters have the same source, buffering is needed to allow all of the splitters to receive the data. The buffering doesn't add any latency so long as none of the splitters drift behind. You probably don't want to reset a splitter during playback, as that will result in data being skipped, resulting in an audible glitch.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #6 on: 5 Sep '17 - 18:08 »
And how to avoid the first DRY stream and the second WET stream to drift appart?
Maybe one glitch is better than infinite drifting?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #7 on: 5 Sep '17 - 18:14 »
You can avoid drifting by making sure that both splitters take data at exactly the same rate.

If there is drifting and you decide to use resetting to cancel it, you would presumably need to do that repeatedly; if they drift once, they will probably drift again. Which means there would be multiple audible glitches, not just one. A better way to correct drifting is to adjust the playback rate, eg. slightly speed up a splitter that is getting left behind.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #8 on: 6 Sep '18 - 21:20 »
Ok it's a late topic, but sometimes when something goes wrong I forget the idea, then later I come back to it...

The goal is to use only ONE VST REVERB shared by many VST instruments streams + the bass midi reverb stream

In your code, of 17 Oct '16 - 17:20 , you had the idea to join the other VST instruments streams to the actual bass midi reverb, so when the reverb is applied to the bass midi , it is also applied to the VSTi

This was too much tricky and I don't know why it did not worked efficiently on my code.

What about the opposite idea :

take the bass midi reverb dry stream into a push stream and put it into a reverbmixer,

we put other VSTi streams (with splitters) into this reverbmixer (we can adjust the amount of reverb)

and then apply the VST reverb on the full reverbmixer?


To do that we have to transform a DSP handle into a stream handle

I can probably do it , but with vb.net , from my past experience, DSP callbacks are not fast enough for realtime playing (128 bytes buffer)



What about adding a new function to BASS, that feed a push stream handle from a DSP handle ??? this will be very useful for the vb.net users
(this is the same as applying a DSP that return the same identical buffer, but copy the data to the provided push stream handle)


I find my idea is genius  8) :P ;D ;D :P

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #9 on: 12 Sep '18 - 14:28 »
What about adding a new function to BASS, that feed a push stream handle from a DSP handle ??? this will be very useful for the vb.net users
(this is the same as applying a DSP that return the same identical buffer, but copy the data to the provided push stream handle)

I'm not sure about a BASS option, but it might be possible to add support for something like that in BASS_Split_StreamCreate. I will have to think about it. If it is specifically of interest to VB.Net users, I guess a BASS.Net-specific solution would also work?

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #10 on: 12 Sep '18 - 18:43 »
I don't use bass.net and prefer a direct call to native code.
Yes, BASS_Split_StreamCreate from a dsp handle would be a good option !

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #11 on: 14 Sep '18 - 16:08 »
Here's something for you to try:

   www.un4seen.com/stuff/bassmix.zip

It adds support for "dummy" streams (STREAMPROC_DUMMY/DEVICE) in BASS_Split_StreamCreate by internally setting a DSP function to buffer data from them. BASS_MIDI_StreamGetChannel gives you a dummy stream, so you should be able to use that in a BASS_Split_StreamCreate call to get a stream with the same data. The splitter's DSP function has the lowest possible "priority" setting, so the data will include the effect of any other DSP/FX that are set on the source. Note the splitter has no control over the source's data rate, so you need to make sure that you don't process the splitter too slowly to avoid buffer overflows (which would result in data being skipped). If needed, you can adjust the buffer length via the BASS_CONFIG_SPLIT_BUFFER option.

This stuff hasn't really been tested yet, so please report how you get on with it. In particular, I think setting syncs could use some testing.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #12 on: 17 Sep '18 - 00:32 »
Wow it start to work !
The reverb seems to have a bit more volume when applied directly on the BASS_MIDI_StreamGetChannel , rather than on the the FX mixer (BASS_MIDI_StreamGetChannel >BASS_Split_StreamCreate>Fx mixer>Main mixer )  Not sure if it is true
Do you send 100% of the volume in the 2 cases? The Volume of the soundfont of +6db can be the difference?

I have however strange results when I plug in my main output mixer the input push stream (that is splited to go to the reverb too)

I don't know why with ASIO (ASIO4ALL) it is working great, but with WASAPI (exclusive)  the input is heard delayed few seconds !
Maybe while the software is busy to load VST instruments, etc... the input is not getting enough data, and become late

While with ASIO , input and output are staying in sync

By the way really great work !

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #13 on: 17 Sep '18 - 16:34 »
The reverb seems to have a bit more volume when applied directly on the BASS_MIDI_StreamGetChannel , rather than on the the FX mixer (BASS_MIDI_StreamGetChannel >BASS_Split_StreamCreate>Fx mixer>Main mixer )  Not sure if it is true
Do you send 100% of the volume in the 2 cases? The Volume of the soundfont of +6db can be the difference?

I suspect what you're seeing there is that the dry/original level is higher, so it sounds like the wet/reverb level is lower. BASSMIDI will add the reverb channel to the MIDI stream's final output. If you're playing the reverb channel data yourself, you would want to prevent BASSMIDI playing it too. You could do that by using the BASS_FX_VOLUME effect (with fTarget/fCurrent=0) to mute it. That effect would need to have a lower "priority" value in its BASS_ChannelSetFX call than the splitter is using, so that the splitter gets the data before the muting. The BASSmix update is using the lowest possible "priority" value, but here's another BASSmix update that will use -1000 instead (you would use a lower value than that on the BASS_FX_VOLUME effect):

   www.un4seen.com/stuff/bassmix.zip

I have however strange results when I plug in my main output mixer the input push stream (that is splited to go to the reverb too)

I don't know why with ASIO (ASIO4ALL) it is working great, but with WASAPI (exclusive)  the input is heard delayed few seconds !
Maybe while the software is busy to load VST instruments, etc... the input is not getting enough data, and become late

While with ASIO , input and output are staying in sync

ASIO is indeed better for keeping input and output in sync because all input and output ASIO channels (on the same device) are processed in sync by the ASIO driver. If you're getting a large delay when using WASAPI that probably means the input was started some time before the output was, resulting in too much buffered data. Try starting the output first. Another thing you can try is BASS_Split_StreamReset, to clear the splitter's buffer.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #14 on: 17 Sep '18 - 17:01 »
I forgot to tell you...
I am using the BASS_MIDI_StreamGetChannel   BASS_MIDI_CHAN_REVERB   and not on every midi channel
This already prevent BASSMIDI reverb to sound. Right?
Is this BASS_MIDI_StreamGetChannel / BASS_MIDI_CHAN_REVERB volume received by the BASS_Split_StreamCreate is different than the one we receive directly in the DSP Proc , in case of Soundfont volume +6db?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #15 on: 17 Sep '18 - 17:57 »
I am using the BASS_MIDI_StreamGetChannel   BASS_MIDI_CHAN_REVERB   and not on every midi channel
This already prevent BASSMIDI reverb to sound. Right?

That will prevent BASSMIDI's built-in reverb effect being applied but BASSMIDI expects that a custom reverb effect will be applied to the reverb channel, so it will still be included in the MIDI stream's final output (so that the custom reverb is heard). If you don't want BASSMIDI to play the reverb channel, you will need to mute it. Actually, instead of using the BASS_FX_VOLUME effect to do that, a better way would be to set the MIDI_EVENT_REVERB_LEVEL event to 0.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #16 on: 17 Sep '18 - 18:10 »
As the reverb is " auxiliary " , I set always DRY = 0%  WET= X%  on the VST plugin itself
Is it what you mean ?

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #17 on: 17 Sep '18 - 23:41 »
BASS_Split_StreamReset on the input push stream handle (from wasapi proc provided by bass then splitted)  does not change anything
still 5 seconds of delay between input and output

I suspect some operations like charging huge vst causing the output to slow down while input is still buffering

Is there anything that we can do to let the input and output in sync together ?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #18 on: 18 Sep '18 - 13:11 »
As the reverb is " auxiliary " , I set always DRY = 0%  WET= X%  on the VST plugin itself
Is it what you mean ?

No, that isn't what I meant, but you would indeed set your reverb effect's "dry" level to 0.

What I was talking about is preventing BASSMIDI playing the reverb channel (because you're playing it separately via the splitter) by muting it. The MIDI_EVENT_REVERB_LEVEL event determines the level of the reverb channel in the MIDI stream's output, so setting that to 0 will mute it.

BASS_Split_StreamReset on the input push stream handle (from wasapi proc provided by bass then splitted)  does not change anything
still 5 seconds of delay between input and output

Oops, I got the input stream and MIDI reverb splitter mixed up in the BASS_Split_StreamReset suggestion. BASS_Split_StreamReset indeed won't have any effect on a push stream. To clear a push stream, you can use BASS_ChannelSetPosition with pos=0 instead. If you would like to monitor how much data the push stream has buffered, you can use BASS_StreamPutData with length=0 to check that.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #19 on: 18 Sep '18 - 13:17 »
Right !

BASS_Split_StreamReset(_InputStream)  does nothing but
BASS_ChannelSetPosition(_InputStream, 0, 0)  is OK to resync the input and the output

unfortunately, when I reload some VST saving including samples, the output sound is a bit interrupted, and then the input is delayed

So the main reason is that if one of the mixer stream is not fast enough , the ouput is cutted few milliseconds , but the input stream continue buffering, and then become delayed from the same amout

what is the cleanest way to handle such problems

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #20 on: 18 Sep '18 - 14:59 »
There are a couple of things you could try when you detect that the push stream has too much buffered data (via BASS_StreamPutData with length=0). You could remove data from the push stream via BASS_ChannelGetData. Another (perhaps less noticeable) solution could be to temporarily raise the push stream's sample rate (via BASS_ATTRIB_FREQ setting) slightly until it catches up. You could perhaps use a mix of the two: remove data when there is a lot of buffered data and adjust the rate for smaller amounts.

rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #21 on: 30 Sep '18 - 16:29 »
Hello Ian,

Do you see any reasons why my program has now audio cracks and pops when using the new splitter on the bass midi reverb wet stream
I plug this splitter to an intermediate FX MIXER, and then plug this FX MIXER to my main audio mixer that go to the wasapi output

This happens when I also have some VST instruments plugged in the main audio mixer too

And this happen only when the computer is on BATTERY. If I plug the power, it is OK

Why adding this intermediate FX mixer is degrading the speed of the audio stream


rv

  • Posts: 249
Re: Same Reverb for many streams
« Reply #22 on: 30 Sep '18 - 18:11 »
ChlMidiReverbHandle = BASS_MIDI_StreamGetChannel(_midiStream, -2)
TheMidiRev = BASS_Split_StreamCreate(ChlMidiReverbHandle, BASS_STREAM_DECODE Or BASS_SAMPLE_FLOAT, 0)

The new dsp handle to splitter seems to cause the slow down of the whole mixer when I add some VST instruments too and the computer is powered on Battery

It is strange...

MIDAPMI

  • Posts: 22
Re: Same Reverb for many streams
« Reply #23 on: 30 Sep '18 - 21:31 »
rv are you online?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Same Reverb for many streams
« Reply #24 on: 1 Oct '18 - 15:45 »
Do you see any reasons why my program has now audio cracks and pops when using the new splitter on the bass midi reverb wet stream
I plug this splitter to an intermediate FX MIXER, and then plug this FX MIXER to my main audio mixer that go to the wasapi output

Are you plugging the MIDI stream and reverb splitter into the same mixer? You will need the MIDI stream to be processed first, so that the splitter has data when it's its turn to get processed by the mixer. You can ensure that by plugging the MIDI stream into the mixer first (via BASS_Mixer_StreamAddChannel), before the splitter. You can also use the BASS_MIXER_LIMIT flag to ensure that a source is processed first by the mixer, even if it was added later.

This happens when I also have some VST instruments plugged in the main audio mixer too

And this happen only when the computer is on BATTERY. If I plug the power, it is OK

If the problem is only happening on battery power, perhaps the CPU speed is being throttled then to extend battery life? That might result in the time taken by all of the processing being too long to sustain playback, resulting in breaks in the sound.