Too much microphone latency

Started by kafffee,

kafffee

Okay great, that BASS_Split_StreamReset totally does its job :-) Now I can't actually hear two taps any more, when I use the VST version of my code.

The BASS_BFX_PITCHSHIFT version still fails though in the Bass.BASS_FXSetParameters call: BASS_ERROR_ILLPARAM...

I fixed the failing in Bass.BASS_ChannelSetFX with a call of GetVersion before.

Can you see any wrong fx parameters (variable: PitchEffect) in my code in post #54 or is it something else?

_______________________


Just for the right understanding: Is it right that I need the two split streams (SplitOriginal and SplitForParBus) with my current setup, when I want to:

1. Play the original stream over the mixer
2. Add fx on the original stream then play the stream thereof as well over the mixer (simultaneously)

Or did we only do that because I used to have a ChannelGetData call somewhere (which is not the case any longer). Did StreamPutData have the same effect ("stealing data") because I will need that.:

Recording.PushStreamHandleDry = Bass.BASS_StreamCreatePush(MainModule.Song.SampleRate, 1, BASSFlag.BASS_STREAM_DECODE, IntPtr.Zero)

Recording.SplitOriginal = BassMix.BASS_Split_StreamCreate(Recording.PushStreamHandleDry, BASSFlag.BASS_STREAM_DECODE, Nothing)

BassAsio.BASS_ASIO_ChannelEnableBASS(True, 0, Recording.PushStreamHandleDry, True)
BassMix.BASS_Mixer_StreamAddChannel(MainModule.Mixer, Recording.SplitOriginal, BASSFlag.BASS_DEFAULT)

' (Adding the FX with the code from my last post.)

Ian @ un4seen

Quote from: kafffeeThe BASS_BFX_PITCHSHIFT version still fails though in the Bass.BASS_FXSetParameters call: BASS_ERROR_ILLPARAM...

I fixed the failing in Bass.BASS_ChannelSetFX with a call of GetVersion before.

Can you see any wrong fx parameters (variable: PitchEffect) in my code in post #54 or is it something else?

Your parameters look fine. I suspect you may be using an old BASS.Net version? There was a problem caused by BASS_BFX_PITCHSHIFT having "long" parameters, which can be 32-bit or 64-bit depending on the architecture and language. They have since been changed to "int" (always 32-bit) in BASS_FX and BASS.Net:

    www.un4seen.com/forum/?msg=144805
    www.un4seen.com/forum/?msg=144812

On Windows, the BASS.Net update is needed even if using an older (not updated) BASS_FX version.

Quote from: kafffeeJust for the right understanding: Is it right that I need the two split streams (SplitOriginal and SplitForParBus) with my current setup, when I want to:

1. Play the original stream over the mixer
2. Add fx on the original stream then play the stream thereof as well over the mixer (simultaneously)

Yes, if you want to play the original sound and the pitch-shifted sound, then you will need a splitter for each one.

kafffee

#62
QuoteYour parameters look fine. I suspect you may be using an old BASS.Net version?

Yes I was :-), using the current one fixed it. Luckily, the delay is much better here as well.

In the waveform I attached there is something wrong though: the mixer signal sets in even before the original pulse (which is orange). How can that be?:

BassMix.BASS_Split_StreamReset(SplitForParBus)
BassMix.BASS_Mixer_StreamAddChannel(MainModule.Mixer, NewWetHandle.WetPushHandle, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_MIXER_CHAN_NORAMPIN)
BassEnc.BASS_Encode_Start(MainModule.Mixer, "C:\Test\output.wav", BASSEncode.BASS_ENCODE_QUEUE Or BASSEncode.BASS_ENCODE_AUTOFREE Or BASSEncode.BASS_ENCODE_PCM, Nothing, IntPtr.Zero)
BassAsio.BASS_ASIO_Start(512)

Yet I have one another remaining question, then I think we can wrap up this topic:

I am using these parameters:

Dim PitchEffect As New BASS_BFX_PITCHSHIFT With {
.fPitchShift = 1,
.fSemitones = argVal,
.lChannel = BASSFXChan.BASS_BFX_CHANALL,
.lFFTsize = 2048,
.lOsamp = 8}

If Not Bass.BASS_FXSetParameters(HandleModel.WetTempoFXHandle, PitchEffect) Then MessageBox.Show("setparams: " & Bass.BASS_ErrorGetCode.ToString)

However, I cannot hear an audible change in pitch shift when argVal changes. The FXSetParameters call does not fail and gets executed every time.

When I change fPitchShift to 2 I can definitely hear a change.

Are either of the properties affecting each other, i.e. when I set fPitchShift then fSemiTones will be ignored? So I should only change one parameter at a time and not use PitchShift locally? Or is it something else?

Ian @ un4seen

Quote from: kafffeeIn the waveform I attached there is something wrong though: the mixer signal sets in even before the original pulse (which is orange). How can that be?:

Are you sure it isn't just that the mixer's louder signal is making it visible sooner? Try reducing its level to match the original, and see what it looks like then.

Quote from: kafffeeYet I have one another remaining question, then I think we can wrap up this topic:

I am using these parameters:

Dim PitchEffect As New BASS_BFX_PITCHSHIFT With {
.fPitchShift = 1,
.fSemitones = argVal,
.lChannel = BASSFXChan.BASS_BFX_CHANALL,
.lFFTsize = 2048,
.lOsamp = 8}

If Not Bass.BASS_FXSetParameters(HandleModel.WetTempoFXHandle, PitchEffect) Then MessageBox.Show("setparams: " & Bass.BASS_ErrorGetCode.ToString)

However, I cannot hear an audible change in pitch shift when argVal changes. The FXSetParameters call does not fail and gets executed every time.

When I change fPitchShift to 2 I can definitely hear a change.

Are either of the properties affecting each other, i.e. when I set fPitchShift then fSemiTones will be ignored? So I should only change one parameter at a time and not use PitchShift locally? Or is it something else?

Yes, currently only one of the fPitchShift and fSemiTones parameters can be used, and fPitchShift has priority if both are. If you want to use fSemiTones instead, leave fPitchShift at 1 (the default).

kafffee

QuoteAre you sure it isn't just that the mixer's louder signal is making it visible sooner? Try reducing its level to match the original, and see what it looks like then.

I tried this to get the sample data louder:

BassMix.BASS_Split_StreamReset(SplitForParBus)
BassMix.BASS_Mixer_StreamAddChannel(MainModule.Mixer, NewWetHandle.WetPushHandle, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_MIXER_CHAN_NORAMPIN)
Dim fx = Bass.BASS_ChannelSetFX(MainModule.Mixer, BASSFXType.BASS_FX_VOLUME, 0)
If Not Bass.BASS_FXSetParameters(fx, New BASS_FX_VOLUME_PARAM With {.fCurrent = -1, .fTarget = 1.5}) Then MessageBox.Show("setparams: " & Bass.BASS_ErrorGetCode.ToString)

BassEnc.BASS_Encode_Start(MainModule.Mixer, "C:\Test\output.wav", BASSEncode.BASS_ENCODE_QUEUE Or BASSEncode.BASS_ENCODE_AUTOFREE Or BASSEncode.BASS_ENCODE_PCM, Nothing, IntPtr.Zero)
BassAsio.BASS_ASIO_Start(512)

But it looks completely the same in my DAW, no matter which values I use for fTarget...

Why is that? The BASS_FXSetParameters call does not fail.

____________________________


QuoteYes, currently only one of the fPitchShift and fSemiTones parameters can be used, and fPitchShift has priority if both are. If you want to use fSemiTones instead, leave fPitchShift at 1 (the default).

Okay, I changed PitchEffect to be a public variable, so it won't "get caught" by the Garbage Collector, did not touch .fPitchShift and only changed .fSemiTones but I still can't hear a change. Still the BASS_FXSetParameters call does not fail. HandleModel.WetTempoFXHandle is being played though, I can hear it getting louder when I add it to the mixer...

Ian @ un4seen

Quote from: kafffeeI tried this to get the sample data louder:

BassMix.BASS_Split_StreamReset(SplitForParBus)
BassMix.BASS_Mixer_StreamAddChannel(MainModule.Mixer, NewWetHandle.WetPushHandle, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_MIXER_CHAN_NORAMPIN)
Dim fx = Bass.BASS_ChannelSetFX(MainModule.Mixer, BASSFXType.BASS_FX_VOLUME, 0)
If Not Bass.BASS_FXSetParameters(fx, New BASS_FX_VOLUME_PARAM With {.fCurrent = -1, .fTarget = 1.5}) Then MessageBox.Show("setparams: " & Bass.BASS_ErrorGetCode.ToString)

BassEnc.BASS_Encode_Start(MainModule.Mixer, "C:\Test\output.wav", BASSEncode.BASS_ENCODE_QUEUE Or BASSEncode.BASS_ENCODE_AUTOFREE Or BASSEncode.BASS_ENCODE_PCM, Nothing, IntPtr.Zero)
BassAsio.BASS_ASIO_Start(512)

But it looks completely the same in my DAW, no matter which values I use for fTarget...

fTarget=1.5 would actually make it even louder by 50%. Instead of using a BASS_FX_VOLUME effect, you could use the BASS_ATTRIB_VOLDSP attribute. For example:

Bass.BASS_ChannelSetAttribute(MainModule.Mixer, BASSAttribute.BASS_ATTRIB_VOLDSP, 0.5f);

Btw, how are you comparing when the mixer starts compared to the original sound, as I thought the mixer was playing the original sound too? Perhaps when you wrote "mixer signal", you meant only the pitch-shifted sound?

Quote from: kafffeedid not touch .fPitchShift and only changed .fSemiTones but I still can't hear a change.

Oops! I was wrong about setting fPitchShift=1 when using fSemiTones. It should actually be fPitchShift=0 instead.

kafffee

QuotefTarget=1.5 would actually make it even louder by 50%. Instead of using a BASS_FX_VOLUME effect, you could use the BASS_ATTRIB_VOLDSP attribute

Okay, tried that, but I guess the problem is/was something else. You wrote:

QuoteBtw, how are you comparing when the mixer starts compared to the original sound, as I thought the mixer was playing the original sound too? Perhaps when you wrote "mixer signal", you meant only the pitch-shifted sound?

When I wrote mixer signal, I meant SplitOriginal and SplitForParBus were plugged into the mixer. That was my fault, sry, that did not make sense. Now I removed SplitOriginal from the mixer in order to really see how much latency there is: I tried with the pulse.wav file that you uploaded and now I can't see anything in the waveform neither can I hear a click, when playing it back.  I tried another (mp3) song for comparison with the same code and it worked. Can you tell what that is all about?

I was also wondering why, when I plug a channel into the mixer, the mixer signal is louder than the original pulse.wav file at all (when I do add SplitOriginal), as you see in the "playback stream latency.PNG" file I uploaded.

_________________________________


QuoteIt should actually be fPitchShift=0 instead

I can confirm that. At least when I apply it on a  stream that's coming from an mp3 song. When I apply it to the.wav file, as mentioned above, there is no audible click or anything in the waveform.

You might want to tell radio42 to add this information to his docs though :-)

Ian @ un4seen

Quote from: kafffeeNow I removed SplitOriginal from the mixer in order to really see how much latency there is: I tried with the pulse.wav file that you uploaded and now I can't see anything in the waveform neither can I hear a click, when playing it back.  I tried another (mp3) song for comparison with the same code and it worked. Can you tell what that is all about?

I'm not sure, but I guess the pulse may be too short for the pitch-shifting algorithm to detect. Does it disappear even when fPitchShift=1?

Quote from: kafffeeI was also wondering why, when I plug a channel into the mixer, the mixer signal is louder than the original pulse.wav file at all (when I do add SplitOriginal), as you see in the "playback stream latency.PNG" file I uploaded.

The mixer will be louder because it's playing 2 copies of the original sound (one of them pitch-shifted). To compensate, you could reduce the mixer's level with BASS_ATTRIB_VOLDSP, or reduce the source BASS_ATTRIB_VOL levels (this way will be slightly more efficient).

kafffee

QuoteI'm not sure, but I guess the pulse may be too short for the pitch-shifting algorithm to detect.

That was my first guess, too :-)

QuoteDoes it disappear even when fPitchShift=1?

Yes.

QuoteThe mixer will be louder because it's playing 2 copies of the original sound (one of them pitch-shifted).

Okay, but we just found out that it won't play anything of the pitch-shifted sound when trying it with the pulse.wav. You think it appears when in addition w/ the original stream?

Ian @ un4seen

No, the mixer shouldn't affect the pitch-shift processing. Is the mixer still louder when only the original sound (SplitOriginal) is put in it?

kafffee

QuoteIs the mixer still louder when only the original sound (SplitOriginal) is put in it?

No it's quieter than pulse.wav. Isn't that just as strange? See attached waveform (the mixer is the orange one).

This happens with and without these lines:

Dim fx = Bass.BASS_ChannelSetFX(MainModule.Mixer, BASSFXType.BASS_FX_VOLUME, 0)
If Not Bass.BASS_FXSetParameters(fx, New BASS_FX_VOLUME_PARAM With {.fCurrent = -1, .fTarget = 1.5}) Then MessageBox.Show("setparams mixer: " & Bass.BASS_ErrorGetCode.ToString)

FXSetParameters again does not fail.

Ian @ un4seen

In your previous post, you said the original sound is the orange one. Was that wrong and the mixer output was actually lower then too?

So the top waveform is the original pulse.wav file, and the bottom one (orange) is the output.wav file from BASS_Encode_Start? What software are you using to display those waveforms, and is it definitely using the same scale in both cases? It looks like the pulse.wav waveform has been zoomed-in (it's clipped). You could try loading both files in Audacity for another comparison.

kafffee

QuoteIn your previous post, you said the original sound is the orange one.

It happened to be the orange one in that post, but there is no consistency in the color I picked, that's why I  mentioned it every time explicitely which one is the orange one.

QuoteWas that wrong and the mixer output was actually lower then too?

I took a look at the waveform in that post again and the fact that it says 2026-07-08 at the bottom of the waveform tells me that I exported the whole song in  my DAW for some reason, so it's very quite possible that it shows not only the mixer channel but the mixer channel plus the pulse.wav. So sry that was my fault :-)

QuoteWhat software are you using to display those waveforms?

It's a dinosaur :-): MAGIX Samplitude Music Studio 2016 version 22.0.0.16 (DP3)

QuoteIs it definitely using the same scale in both cases?

I think so: I created a new project and when I zoomed in vertically both tracks changed. I'm not sure though whether the DAW scales the single tracks automatically when I first import the wav files.


QuoteIt looks like the pulse.wav waveform has been zoomed-in (it's clipped)

Yes, either track is definitely zoomed in, because If I didn't, the qieter one (the mixer) is so soft that it didn't show up at all.


QuoteYou could try loading both files in Audacity for another comparison.

Did not really wanna download another DAW to my computer as I already have two. So I tried MPC Beats by AKAI. See the two attached screenshots. Unfortuntaly I did not manage to zoom in horizontally any more, but you can still see the amplitude (the bottom one is always the mixer channel):

"wf_OnlySplitOriginal_MPC_Vol1.5.PNG":
Changed to volume to fTarget to 1.5

"wf_OnlySplitOriginal_MPC_VolUnchanged.PNG":
Did not touch the volume here.

You can see, the volume change seems to apply, and when I don't touch volume, pulse.wav seems to be just as loud as the mixer. Did not really find a way to measure extacly though. This is not a feature of my version of MPC Beats.

So I think that Samplitude Music Studio actually does adjust the scale automatically when importing an audio file, I cannot think of anything else why in MPC Beats it seems to be correct.