A "fake" device?

Started by Couin,

Couin

Hi :D

Related with this thread, is it possible to create a "fake" device?

I mean, I would catch the MixerAux output, to send to oscilloscope (BASS_ChannelGetData), wavwriter (with BASS_Encode_StartPCMFile) and MP3 stream (with BASS_Encode_MP3_Start and BASS_Encode_CastInit), but without send the audio to any audio device.
fakedev.jpg

Is it possible (especially without the latency we have when audio is not played)?

Thanks :)

Ian @ un4seen

You could use the "No Sound" device. That's always device number 0, ie. you use would device=0 in the BASS_Init call.

Couin

#2
Hi Ian :)

I though about Device 0, it is already initialized before BASS_Mixer_StreamCreate (if I understood well, it is required):
Call BASS_SetConfig(BASS_CONFIG_DEV_NONSTOP, 1)
Call BASS_Init(0, MixerFreq, 0, 0, 0)
...
MixerAux = BASS_Mixer_StreamCreate(MixerFreq, 2, BASS_SAMPLE_FLOAT Or BASS_STREAM_DECODE Or BASS_MIXER_NONSTOP)
Sending the MixerAux output to Device 0 won't interact with mixers?

Also, how can I tell to the MixerAux to send its output to Device 0 in this case?

Edit: I tried with this code:
Call BASS_SetDevice(0)
SplitOutDevScope = BASS_Split_StreamCreate(MixerAux, 0, ByVal 0)
Call BASS_ChannelSetAttribute(SplitOutDevScope, BASS_ATTRIB_BUFFER, 0)
Call BASS_ChannelStart(SplitOutDevScope)
I get some result but not as expected.
nDataSize = 4000
Debug.Print BASS_ChannelGetData(SplitOutDevScope, SampleData(0), nDataSize)
returns random values between 100 to 3800, so the scopes looks crap :(
If I set BASS_ATTRIB_BUFFER for example to 0.05, I get randomly 0 or 4000 and the scopes are delay of around 1 second from the sound.
Setting BASS_ATTRIB_BUFFER to 0.5, the scope acts sync whit the sound, but the sound is delayed from hitting the play button, so unusable :(
Is there a way to get good result (so no perceptible latency and unmissing datas)?

Thanks :)

Ian @ un4seen

Do you have other splitters on MixerAux, and if so, what are they used for? Is one of them what you're hearing, or if not, where is the sound that you're hearing (and comparing latency with) coming from? Is the scope ahead or behind the sound you're hearing?

Couin

The sound is played by MixerMain/SplitOutDev(0)/Output (Sound card) of the schematics of post #2 here https://www.un4seen.com/forum/?topic=20884.msg146285#msg146285

MixerAux is initially dedicated to send to another sound card or a virtual cable (for example, to send the audio to BUTT or any other software to stream/record).
In the software, I can choose the device (physical sound card or virtual cable if installed) for the auxilliary output (MixerAux), or "None".
In the case of "None", SplitOutDev(1) is freed by BASS_StreamFree (SplitOutDev(1)) call. In other case, I init the output and attach it to MixerAux:
Call BASS_SetConfig(BASS_CONFIG_DEV_NONSTOP, 1)
Call BASS_Init(OutDev(1), MixerFreq, 0, frmMain.hwnd, 0)
Call BASS_SetDevice(OutDev(1))
SplitOutDev(1) = BASS_Split_StreamCreate(MixerAux, 0, ByVal 0)
Call BASS_ChannelSetAttribute(SplitOutDev(1), BASS_ATTRIB_BUFFER, 0)
Call BASS_ChannelStart(SplitOutDev(1))

I would purpose, in the devices list, a new internal Caster/Recorder (which has the oscilloscopes), so not a physical device or virtucal cable (so no SplitOutDev(1) set), that's why I need to get the MixerAux output without playing it onto a device or virtual cable, and without (perceptible) latency.

About my previous tests, I'l try to explain better what I get:
With BASS_ATTRIB_BUFFER at 0:
- The sound (of MixerMain) plays directly when I hit the play (jingle) button
- The scopes acts sync with the sound, but I don't get 4000 datas returned, but randomly between 100 to 3800. So the traces are not complete.
incomplete scopes.jpg

With BASS_ATTRIB_BUFFER at 0.05:
- The sound (of MixerMain) plays near directly (I can feel a very small lantecy if I quickly repeat the playback) when I hit the play (jingle) button
- The scopes acts 1 second after the sound, and I randomly get 4000 or 0 data returned (so the traces are flat each times no data are returned).

With BASS_ATTRIB_BUFFER at 0.5:

- The sound (of MixerMain) plays around 0.5 secs after I hit the play (jingle) button
- The scopes acts sync with the sound, and I get 4000 datas (so the traces are complete).

I also precise that even if I set a device as Aux (so SplitOutDev(1) is set), it does not change these results.

I hope it will help you to see better my problem :)

Ian @ un4seen

Quote from: CouinAbout my previous tests, I'l try to explain better what I get:
With BASS_ATTRIB_BUFFER at 0:
- The sound (of MixerMain) plays directly when I hit the play (jingle) button
- The scopes acts sync with the sound, but I don't get 4000 datas returned, but randomly between 100 to 3800. So the traces are not complete.

Ah yes, I think I see that problem now when BASS_ATTRIB_BUFFER=0. Here's an update for you to try:

    www.un4seen.com/stuff/bass.zip

Let me know if you still see the problem happening with it.

Couin

Hi Ian,
I quickly tried before going to work and it looks OK : I get the 4000 requested datas on each cycles, oscilloscopes traces ar complète and no playback/scope latency.
Well spotted !
What was the problem?

Ian @ un4seen

Good to hear it's all good now. The issue was that BASS_ChannelGetData would only return data that hasn't been heard from the output device yet, and there isn't much of that when playback buffering is disabled (BASS_ATTRIB_BUFFER=0), especially on the "No Sound" device because it has almost no buffer/latency. The update dips into the data that has been heard if necessary to deliver the requested amount.

There was actually a small bug in the change (it allowed requesting the full buffer amount before the buffer had been filled), so here's another update :)

    www.un4seen.com/stuff/bass.zip

Couin

Hi Ian,

Thanks for feedback and fix :)