Author Topic: Clone "mixed" stream to another output device ?  (Read 5279 times)

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #50 on: 13 Jun '24 - 17:08 »
I tried with both , no problem with measurement between MixerSources and MixerMain (excepted that with BASS_ChannelGetLevel the audio plays too fast).

Yes, you should only use BASS_Mixer_ChannelGetLevel on mixer sources, because the data taken by BASS_ChannelGetLevel wouldn't be seen by the mixer (causing skipping/speedy playback).

Measuring MixerMain output receving zeros but sound still ok (no dropouts).

Do you mean BASS_ChannelGetLevel on SplitOutDev? To perhaps narrow it down, does it still happen if you don't set BASS_ATTRIB_BUFFER to 0 on SplitOutDev?

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #51 on: 14 Jun '24 - 22:44 »
Hi Ian

Removing buffer attribute resolves the "missing measures" but makes getposition jerky (resulting to a remaining time slow refresh). Plus, it add delay bewteen hitting play and sound.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #52 on: 25 Jun '24 - 01:34 »
Hi :)

I'm modifying ouput device selection method so now, changing device directly apply, without reloading audio files:
Call BASS_StreamFree(SplitOutDev(outp)) 'where outp is 0 or 1, related with Main or Aux outputs of the schematic here http://www.un4seen.com/forum/?topic=20403.msg143048#msg143048
Changing the device number et recreate the SplitOutDev (split) stream.

Works OK, but just a minor question (for a rare situation):
If Aux is firstly set on "None" device (so 0), if I played some jingle, when I change Aux for an output device, I get the end part of last playback.

I tried to add some BASS_Split_StreamReset calls , for SplitOutDev, MixerMain or MixerAux, but nothing change.
I added BASS_CONFIG_SPLIT_BUFFER, if I set to 0, I get no more part of last playback on device change, but playback is to fast and crappy. If I set to a value like 100, the playback speed is ok but I get a small part of previous playback.

Is there a way to clear buffer to prevent this ?

Thanks :D




Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #53 on: 25 Jun '24 - 14:38 »
Removing buffer attribute resolves the "missing measures" but makes getposition jerky (resulting to a remaining time slow refresh). Plus, it add delay bewteen hitting play and sound.

OK. Here's a modified version of the CONTEST.C example for you to try for comparison, adding a BASS_ATTRIB_BUFFER=0 option and a BASS_DATA_AVAILABLE display:

   www.un4seen.com/stuff/contest-nobuf.exe

Please try that with and without the "-n" option (BASS_ATTRIB_BUFFER=0), and see whether the level display is working and what "data" values (BASS_DATA_AVAILABLE) are shown in each case. If it's working fine even with "-n" then you can also try monitoring the BASS_DATA_AVAILABLE values (with BASS_ChannelGetData) in your app to see if they're different.

I'm modifying ouput device selection method so now, changing device directly apply, without reloading audio files:
Call BASS_StreamFree(SplitOutDev(outp)) 'where outp is 0 or 1, related with Main or Aux outputs of the schematic here http://www.un4seen.com/forum/?topic=20403.msg143048#msg143048
Changing the device number et recreate the SplitOutDev (split) stream.

Works OK, but just a minor question (for a rare situation):
If Aux is firstly set on "None" device (so 0), if I played some jingle, when I change Aux for an output device, I get the end part of last playback.

A new splitter shouldn't play old data from its source, so it seems like the old sound may actually be in new data from the source. How much old sound are you getting? And is this happening on the same WinXP VM and/or on other systems? Does adding the BASS_MIXER_NONSTOP flag to MixerAux make any difference?

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #54 on: 26 Jun '24 - 00:05 »
Hi Ian :)

BASS_MIXER_NONSTOP flag seems resolve the problem :)
(It's not on the XP VM of the level measurement problem, the re-playing was on a non-VM W10, which I use for main developpment).

About contest exe, I will test this afternoon at work (where is the XP VM on which I get some missing level measures), it's my last day before summer hollydays.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #55 on: 26 Jun '24 - 14:45 »
Hi Ian,

I tested the exe with and without -n flag, with a 10 seconds sine of 1 kHz @ max amplitude.

With -n , the VU-meters doesn't fall down. Data value runs around 20000, but sometimes with a near from 0 (too fast to read exactly), no sound problem.

Without -n , VU-meters still OK, Data around 160000 , and I did not saw 0 values.

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #56 on: 26 Jun '24 - 17:26 »
Is that on the same system that you're having the BASS_ChannelGetLevel=0 problem with your app? If so, strange that it isn't happening with the modified example. You could try monitoring the BASS_DATA_AVAILABLE value in your app for comparison.

Code: [Select]
avail = BASS_ChannelGetData(handle, 0, BASS_DATA_AVAILABLE)

Also, if you're changing any config settings via BASS_SetConfig, try removing that to use the defaults (which is what the example does).

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #57 on: 26 Jun '24 - 23:16 »
Yes, I tested your exe on the samed XP VM which makes some missing level measures.
But as I previoulsy wrote, I get missing messures on splitted output of second mixer (Main or Aux), but not if I measure between primary and secondary mixer ( so SplitSources ).

I took the pc where the VM is hosted, for hollydays :P
So I will be able to do tests on it (but not today and friday).

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #58 on: 16 Jul '24 - 03:26 »
Hi :)

Working on ASIO output with a soundcard that has ASIO driver (Rane SL3) so now I understand better, about channels (as well as this soundcard has 3 Stereo outputsso GetInfo returns me "6").

I can setup on which pair of channels to send the splitted stream ( SplitOutDev(0) ), but if I want to change of channel pair, I must BASS_ASIO_Free and BASS_ASIO_Init, BASS_Split_StreamCreate, BASS_ASIO_ChannelEnableBASS etc and it takes a delay to do all these steps.

It's not a big problem, but is there a best way to change channels where to send stream, without free and init the device ?

Thanks :)


Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #59 on: 16 Jul '24 - 17:12 »
You don't actually need to call BASS_ASIO_Free and BASS_ASIO_Init to change the enabled ASIO channels. BASS_ASIO_Stop and BASS_ASIO_Start will suffice, like this:

Code: [Select]
BASS_ASIO_Stop(); // stop ASIO device
BASS_ASIO_ChannelEnable(false, oldoutput, 0, 0); // disable old channels
BASS_ASIO_ChannelEnableBASS(false, newoutput, handle, true); // enable new channels
BASS_ASIO_Start(0, 0); // resume ASIO device

If there are no other ASIO channels being used then you could use BASS_ASIO_ChannelReset instead of BASS_ASIO_ChannelEnable to disable the old channels, which has the advantage of not needing to know the "oldoutput" value.

Code: [Select]
BASS_ASIO_ChannelReset(false, -1, BASS_ASIO_RESET_ENABLE); // disable all output channels

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #60 on: 16 Jul '24 - 23:48 »
Hi Ian :)

I tried these solution, looks OK if changing channels while nothing is playing, but I get bad result is something is playing while I change channels: on the old channels I get stuttering last part of audio. If I come back on old channels, the stuttering diseappear and the sound plays fine.

I attach a zip file including a recording of channels 5+6 ("Right deck" output of Rane SL3).
@10 seconds, I change for channels "1+2" (AUX Output)
@16 seconds, I change back for channels 5+6 (Right Deck)

Of course "1+2" or "5+6" is to match with ASIO panel, but BASS ASIO channels are 0+1 , and 4+5.

The dropdown list (cmbASIOChanOut) allows to choose between these possibilities:
1+2
2+3
3+4
4+5
5+6

Here is the code:
Code: [Select]
Call BASS_ASIO_Stop
Call BASS_ASIO_ChannelEnable(BASSFALSE, ASIOChanOut, 0, 0) 'disable old channels
ASIOChanOut = cmbASIOChanOut.ListIndex
Call BASS_ASIO_ChannelEnableBASS(0, ASIOChanOut, SplitOutDev(0), BASSTRUE)
Call BASS_ASIO_Start(0, 0)

I tried to place BASS_ASIO_ChannelReset but change nothing.

If I remove BASS_ASIO_Stop call, it's ok, but I don't know if it's a clean procedure.



Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #61 on: 17 Jul '24 - 13:53 »
That's strange. Sounds like the ASIO driver isn't clearing and/or ignoring the disabled channel buffers. Here's a BASSASIO update for you to try, which will clear the buffers in BASS_ASIO_Stop.

   www.un4seen.com/stuff/bassasio.zip

Let me know whether it helps.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #62 on: 18 Jul '24 - 00:49 »
Hi Ian,

Thanks for the dll, but it did not changed the behavior.

Objectively, I think that not putting BASS_ASIO_Stop is a real problem, given that we don't change channels regularly but just at the hardware configuration.
Also, knowing that I want to use ASIO inputs, BASS_ASIO_Stop could stop the inputs (?)

But I noticed another problem (I did not saw it before, because I plugged only one stereo cable on 5+6):
If I change the channels, sound stops on old channel, but I get no sound on new selecte channels.

The only way to get sound back is re-selecting initial channels, or restart the software.
« Last Edit: 18 Jul '24 - 01:25 by Couin »

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #63 on: 19 Jul '24 - 01:21 »
Hi,

I read in the documentation that no more channel can be enabled if device has not been stopped before, that should explain why I get no sound on new selected channels.

So must use BASS_ASIO_Stop but I get stuttering , even if I stop all streams before.

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #64 on: 19 Jul '24 - 12:09 »
Yes, the ASIO device does need to be stopped before enabling new ASIO channels (output or input), and BASS_ASIO_ChannelEnable/etc will otherwise fail with BASS_ERROR_START. It is possible to disable and then re-enable the same channels (ie. not new ones) without stopping the device, so if even a slight pause to enable channels would be a problem then you could pre-enable all channels.

But first, I think it would be best to get to the bottom of the stuttering sound issue. To narrow it down, please try using a plain file stream (eg. from BASS_StreamCreateFile) instead of a splitter in the BASS_ASIO_ChannelEnableBASS calls and see if the problem is still present then.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #65 on: 20 Jul '24 - 03:49 »
Hi Ian,

That what I was thinkng  (testing without split) -> Same result

Tested with a minimal project, without mixer -> Same result

Added a button that calls Bass_ASIo_Stop and I notice one repeat of last audio part (around few 200 ms I think).


The code of project (1 button "btStop", 1 button "btExit", 1 dropdown list (Combo) "cmbASIOChanOut", 1 label "lblfeedback"):

Code: [Select]
Option Explicit

Dim AudioStream As Long
Dim ASIODevOut As Integer
Dim ASIOChanOutCount As Integer
Dim ASIOChanOut As Integer

Private Sub btExit_Click()
Unload Me
End Sub

Private Sub btStop_Click()
    Call BASS_ASIO_Stop
End Sub

Public Sub cmbASIOChanOut_Click()
    Dim i As Integer

    Call BASS_ASIO_Stop   'stop ASIO processing
    Call BASS_ASIO_ChannelEnable(0, ASIOChanOut, 0, 0) 'disable old inputs
    ASIOChanOut = cmbASIOChanOut.ListIndex
    Debug.Print ASIOChanOut
    Call BASS_ASIO_ChannelEnableBASS(0, ASIOChanOut, AudioStream, BASSTRUE) 'enable new inputs
    Call BASS_ASIO_Start(0, 0) 'resume ASIO processing
   
End Sub

Private Sub Form_Load()
    ' change and set the current path, to prevent from VB not finding BASS.DLL
    ChDrive App.Path
    ChDir App.Path
   
    Call BASS_Init(0, 44100, 0, 0, 0)
   
    ASIODevOut = 2
    ASIOChanOut = 4
    Call BASS_ASIO_Init(ASIODevOut, 0)
    ListChanOutASIO
   
    AudioStream = BASS_StreamCreateFile(BASSFALSE, StrPtr("track.mp3"), 0, 0, BASS_STREAM_DECODE)
    lblfeedback.Caption = AudioStream
   
    Dim i As BASS_CHANNELINFO
   
    Call BASS_ASIO_ChannelEnableBASS(0, ASIOChanOut, AudioStream, BASSTRUE)
    Call BASS_ASIO_SetRate(i.freq) 'try to set the device rate to avoid resampling

    'start it using default buffer size
    If (BASS_ASIO_Start(0, 0) = 0) Then
        Call BASS_ASIO_Free
        Call BASS_Free
        MsgBox "Can't initialize device " & ASIODevOut
    End If
   
End Sub

Public Sub ListChanOutASIO()

    Dim info As BASS_ASIO_INFO
    Call BASS_ASIO_GetInfo(info)
    ASIOChanOutCount = info.outputs
 
    Dim o As Integer
    cmbASIOChanOut.Clear
    For o = 1 To ASIOChanOutCount - 1
        cmbASIOChanOut.AddItem o & "+" & o + 1
    Next o
    cmbASIOChanOut.ListIndex = ASIOChanOut
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
        Call BASS_ASIO_Free
        Call BASS_Free
End Sub

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #66 on: 22 Jul '24 - 18:04 »
The problem doesn't seem to be happening here (not using your VB code above but something very similar in C), so I suspect it may be driver-specific. To confirm that, does it happen for you when using a different ASIO device/driver? If you don't currently have another one to try, you could try ASIO4ALL.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #67 on: 23 Jul '24 - 13:51 »
Hi,

With ASIO4ALL, I can't reproduce, but perhaps because not a real ASIO device (?).
I have no other ASIO device (hardware) ellse to test for the moment, Rane SL 1 ASIO drivers seems not Win10 compatible :(

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #68 on: 24 Jul '24 - 13:03 »
OK. Just to be sure VB6 isn't interfering somehow, here's a modified version of BASSASIO's CONTEST.C example for you to try. When you press the spacebar, it'll switch to the next stereo output pair. Do you hear the problem when doing that?

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #69 on: 25 Jul '24 - 14:06 »
Hi Ian,

Thanks for test app :)

I had to uninstall ASIO4ALL because it was taking the first device number (perhaps in an eventual next test file, adding a parameter to set the device number in the command line, like "asiotest.exe 0 test.mp3", where 0 is the device number ?).

I get the same result than VB6 app, on channel changing.

I made a small video to show you what I exactly get. At the end, I stop the player with CTRL C in the DOS window.
https://youtu.be/4Tt3nr4MTxc

Thanks :)


« Last Edit: 26 Jul '24 - 13:05 by Couin »

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #70 on: 26 Jul '24 - 18:03 »
That sounds like the ASIO driver is playing/repeating the first channel's most recent data even after it's been disabled. Do you have speakers plugged into the other channels? If not, please try that and see if the proper sound is heard on them or if they're always silent.

Btw, you can use the "-l" option to list available ASIO devices, and "-d <device>" to choose the one to use.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #71 on: 26 Jul '24 - 23:23 »
Hi Ian

The sound you ear is the sound of channel 0 (and 1 of course).
When I hit the spacebar (you can ear the hit too), it switches to 2 (and 3) but the speakers still plugged to 0 + 1, so you can ear that the output repeats the last recent datas in loop.

The sound on 2 + 3 is good (tested by moving Cinch connectors fro 0 +1 to 2 + 3 ).

If I hit again the spacebar, the song plays well on 4 + 5, and I get the same loop problem on 2 + 3 .

Hitting again spacebar, the track goes back to 0 + 1, it plays good, the previous stuttering on 0 +1 gone. 4 + 5 makes the same loop.

In fact, each time I leave from channels, they loop on last datas.
If I send again the song on a stuttering channel, the song plays correctly.

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #72 on: 29 Jul '24 - 13:03 »
Here's an update with a new option that I think should help:

   www.un4seen.com/stuff/bassasio.zip

This is the new option:

Code: [Select]
#define BASS_ASIO_ALLOUTPUTS 16 // pre-enable all output channels

When that's used with BASS_ASIO_Init, the ASIO driver will be told to enable all output channels (including unused ones), so that you can switch them after BASS_ASIO_Start without having to call BASS_ASIO_Stop first. As well as avoiding the repeating sound problem with your device (hopefully), it'll also avoid any gap when switching outputs. An updated ASIOTEST.EXE is included for you to try.

For completeness, there's also an option to do the same for input channels:

Code: [Select]
#define BASS_ASIO_ALLINPUTS 8 // pre-enable all input channels

Note these options can't be used together with the BASS_ASIO_JOINORDER option.

Couin

  • Posts: 124
Re: Clone "mixed" stream to another output device ?
« Reply #73 on: 1 Aug '24 - 15:45 »
Hi Ian ,

Thanks for help :)

It looks running as expected, changing channel (with spacebar) no longer makes stuttering sound of last used channels :=)

I will try to adapt to the project, but before, 2 minor questions about the exe you made:
- I get stuttering sound on breaking program (with CTRL C in the DOS window), I think it it because of breaking program without stopping stream and freeing cleanly the device, can you confirm?
- On channel change, the VU meters does not measure the audio output sif channel is not 0 (see below), is it due to VU meter still "connected" to channel 0(+1)?

Quote
C:\c>asiotest.exe test.mp3
BASS+ASIO simple console player
-------------------------------
ctype: 10005
format: 44100 Hz, 2 chan
length: 3:50 (10147439 samples)
 0:16 (00731144) | L -************ ************- R - cpu 0.20%
output 2
 0:24 (01063708) | L ------------- ------------- R - cpu 0.19%
output 4
 0:25 (01133429) | L ------------- ------------- R - cpu 0.19%
output 0
 0:26 (01187108) | L -************ ************- R - cpu 0.19%
output 2
 0:27 (01219809) | L ------------- ------------- R - cpu 0.19%
output 4
 0:28 (01242638) | L ------------- ------------- R - cpu 0.19%

About inputs, not tested anything yet, as well as I'm searching how to catch ASIO input and send it to a splitter (to send splitted streams to each mixers). ASIO input is a little confusing for me.

Thanks :)

Ian @ un4seen

  • Administrator
  • Posts: 26157
Re: Clone "mixed" stream to another output device ?
« Reply #74 on: 2 Aug '24 - 16:22 »
Yeah, the example's VU will still be showing channel 0+1 levels, because I didn't bother to update the BASS_ASIO_ChannelGetLevel calls :)

The stuttering sound upon Ctrl+C sounds like it could be the same issue that you had when disabling channels. Perhaps that device doesn't get reset properly unless its ASIO driver is unloaded properly, eg. BASS_ASIO_Free called. Do you have the problem if you try another ASIO driver, eg. ASIO4ALL? By the way, you can quit the example gracefully by pressing any other key (not spacebar).