Author Topic: Using a device for recording more than once  (Read 110 times)

Chris Oakley

  • Posts: 145
Using a device for recording more than once
« on: 26 May '21 - 10:34 »
Is it possible to record from the same device with more than one instance? For example if I do this:

Code: [Select]
_wasapi = New BassWasapiHandler(1, False, 44100, 2, 5, 0F)
_wasapi.Init()
_wasapi.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, True)
If _wasapi.DeviceMute Then
    _wasapi.DeviceMute = False
End If
_wasapi.Start()
_RChan = _wasapi.OutputChannel

This bit of code is in a class, so when I instance another class it stops the first instance working. It's always the latest instance of the class which gets the data.

The only way I can get round this is to maintain a list of objects for the devices and simply attach to the handle and split off it which seems a bit cumbersome so I assume I'm missing something.

Ian @ un4seen

  • Administrator
  • Posts: 23743
Re: Using a device for recording more than once
« Reply #1 on: 26 May '21 - 15:17 »
That looks like you're currently using BASSWASAPI (via BASS.Net's BassWasapiHandler class) for recording. It is possible to have multiple simultaneous recordings from a single device when using BASS but not when using BASSWASAPI, so you could switch to using BASS instead. BASS does actually also support recording via WASAPI itself - loopback recording is always via WASAPI and other recording can be enabled too via the BASS_CONFIG_REC_WASAPI config option:

Code: [Select]
BASS_SetConfig(BASS_CONFIG_REC_WASAPI, 1); // enable WASAPI recording

Chris Oakley

  • Posts: 145
Re: Using a device for recording more than once
« Reply #2 on: 26 May '21 - 15:41 »
Thanks Ian. This actually poses another question which I've been trying to get straight in my head. If I do this:

Code: [Select]
Bass.BASS_RecordInit(1)
Bass.BASS_RecordSetDevice(1)
Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_ON, -1.0F)
_RChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, Nothing, IntPtr.Zero)

This is WASAPI right out of the box, but if I add:

Code: [Select]
BASS_SetConfig(BASS_CONFIG_REC_WASAPI, 0)

Does this mean that anything I now do, like getting device info etc, will use DirectSound? Is DirectSound even worth it these days?

Ian @ un4seen

  • Administrator
  • Posts: 23743
Re: Using a device for recording more than once
« Reply #3 on: 26 May '21 - 16:44 »
Thanks Ian. This actually poses another question which I've been trying to get straight in my head. If I do this:

Code: [Select]
Bass.BASS_RecordInit(1)
Bass.BASS_RecordSetDevice(1)
Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_ON, -1.0F)
_RChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, Nothing, IntPtr.Zero)

This is WASAPI right out of the box...

Unless BASS_CONFIG_REC_WASAPI has been set to 1 (or device #1 happens to be a loopback device), that code should actually end up recording via DirectSound currently.

if I add:

Code: [Select]
BASS_SetConfig(BASS_CONFIG_REC_WASAPI, 0)

Does this mean that anything I now do, like getting device info etc, will use DirectSound? Is DirectSound even worth it these days?

When WASAPI is available (on Vista and above), BASS will always get device info via WASAPI regardless of the BASS_CONFIG_REC_WASAPI setting. The BASS_CONFIG_REC_WASAPI setting only determines whether WASAPI or DirectSound is used for the actual data capture.

It hasn't been decided yet but it may be that BASS_CONFIG_REC_WASAPI defaults to 1 in the next BASS release. The main advantage of WASAPI is that it generally has a more consistent data delivery (less fluctuation), which is good for maintaining a lower latency.

Chris Oakley

  • Posts: 145
Re: Using a device for recording more than once
« Reply #4 on: 26 May '21 - 16:53 »
Okay cool. I presume the flag

Code: [Select]
BASS_SetConfig(BASS_CONFIG_REC_WASAPI, 0)

can be set to a value at any time and the following operations will respect that so you can switch in an out at a users request?

Personally I'm not bothered about DirectSound anymore, but you know what users are like. You get a dodgy sound card and all you get is "Direct Sound might work".

Ian @ un4seen

  • Administrator
  • Posts: 23743
Re: Using a device for recording more than once
« Reply #5 on: 26 May '21 - 17:21 »
BASS_CONFIG_REC_WASAPI changes will take effect from the next BASS_RecordInit call, ie. any currently initialized devices will be unaffected until reinitialized.

Chris Oakley

  • Posts: 145
Re: Using a device for recording more than once
« Reply #6 on: 26 May '21 - 17:26 »
That's excellent. Thanks again Ian.