Author Topic: Input channel big latency  (Read 247 times)

smooodilo

  • Guest
Input channel big latency
« on: 21 Oct '24 - 15:51 »
I have an input of my soundcarp plugged in to a matrix mixer. This works fantastic for music. But if I plug in a microphone the latency/delay is enormous. Up to a second. I am guessing this is buffer related? Which buffer setting can reduce this latency to a minimum?

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: Input channel big latency
« Reply #1 on: 21 Oct '24 - 16:52 »
If the recording's mixer is being played by BASS (ie. with BASS_ChannelPlay) then you can minimize latency by disabling playback buffering on it, which you can do by setting BASS_ATTRIB_BUFFER to 0:

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

Also make sure you don't start the recording much before the mixer playback, to avoid a build up of data in the recording's buffer. You can check that with BASS_ChannelGetData (BASS_DATA_AVAILABLE).

smooodilo

  • Guest
Re: Input channel big latency
« Reply #2 on: 21 Oct '24 - 20:06 »
Hmm it is not totally clear to me what you mean. I do the following (vb.net):

Code: [Select]
       If CStr(MyAppSettings.Item("AudioDevice1")) <> "" Then
           Bass.BASS_RecordInit(CInt(MyAppSettings.Item("AudioDevice1")))
           STREAM_INPUT1 = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT, Nothing, IntPtr.Zero)
           BassMix.BASS_Mixer_StreamAddChannel(STREAM_MATRIX, STREAM_INPUT1, BASSFlag.BASS_MIXER_MATRIX)
           SetMatrixChannel(STREAM_INPUT1, CBool(MyAppSettings.Item("Audio.Matrix.I1")), CBool(MyAppSettings.Item("Audio.Matrix.I2")),          CBool(MyAppSettings.Item("Audio.Matrix.I3")), CBool(MyAppSettings.Item("Audio.Matrix.I4")))
           Bass.BASS_ChannelSetAttribute(STREAM_INPUT1, BASSAttribute.BASS_ATTRIB_VOL, CSng(MyAppSettings.Item("Input1VolSlider", "1")))
       End If

It is a live setup. I have a matrix, attach the input, and want to listen to the output live. Especially when talking into a microphone, I hear myself a second later. I am not sure if the matrix adds the latency, or the input channel.

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: Input channel big latency
« Reply #3 on: 22 Oct '24 - 13:44 »
You would apply the mentioned BASS_ATTRIB_BUFFER=0 setting after your BASS_Mixer_StreamCreate call creating the mixer. If you would like to only disable playback buffering while the mic is active, that is also possible by applying BASS_ATTRIB_BUFFER=0 when you add the mic to the mixer, and then BASS_ATTRIB_BUFFER=1 after removing the mic to re-enable playback buffering. Please see the BASS_ATTRIB_BUFFER documentation for details.

smooodli

  • Guest
Re: Input channel big latency
« Reply #4 on: 21 Nov '24 - 15:01 »
Thanks Ian, this helps to reduce the latency to a few ms which is doable. Two questions:

- Does this mean the input streams (streamcreate) are also not buffered anymore, or is this separate? Especially network buffering.
-Would ASIO reduce the latency even further? And is it hard to implement using my current code keeping the mixer intact? Or would it mean rebuilding from scratch?

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: Input channel big latency
« Reply #5 on: 22 Nov '24 - 16:05 »
- Does this mean the input streams (streamcreate) are also not buffered anymore, or is this separate? Especially network buffering.

Decoding channels (with BASS_STREAM_DECODE set), such as mixer sources, don't have playback buffers but may still have other buffers. So an internet stream would still have a download buffer.

-Would ASIO reduce the latency even further? And is it hard to implement using my current code keeping the mixer intact? Or would it mean rebuilding from scratch?

Yes, it may be possible to get even lower latency with ASIO or exclusive mode WASAPI. If you're already playing everything through a mixer then switching to either of them should be quite simple. You can use the mixer handle in a BASS_ASIO_ChannelEnableBASS or BASS_WASAPI_Init (with WASAPIPROC_BASS) call. Please see their documentation for details, if interested.