Author Topic: BASSASIO Play Problems  (Read 222 times)

MrBlister

  • Posts: 13
BASSASIO Play Problems
« on: 1 Feb '23 - 20:35 »
Hi,
I've been working on making my four*stereo player app ASIO compatible. I think I'm just about there except for three (related?) things re hitting the play button:
* Approx 650ms delay in a track starting;
* No sample-rate conversion which seemed to be inherent previously i.e. 44.1 plays fast on my 48 desk;
* Playing another channel causes others to pause until they all run together - channels generally interfere with each other.

Any ideas gratefully received.
Thanks in advance,
MrB

Ian @ un4seen

  • Administrator
  • Posts: 25446
Re: BASSASIO Play Problems
« Reply #1 on: 2 Feb '23 - 13:07 »
Please show how you're setting up the ASIO output, ie. what BASSASIO calls you're making.

Latency is primarily determined by the ASIO buffer length, which is set in the BASS_ASIO_Start call. If you're using BASS_ASIO_ChannelEnableBASS then that should take care of sample-rate conversion, but if you're using BASS_ASIO_ChannelEnable then you can set it up yourself with BASS_ASIO_ChannelSetRate. Also confirm whether you want to play single or multiple BASS channels on each ASIO channel. If it's the latter then a mixer (BASSmix add-on) will be needed, ie. the BASS channels are plugged into a mixer, which feeds the ASIO channel.

MrBlister

  • Posts: 13
Re: BASSASIO Play Problems
« Reply #2 on: 2 Feb '23 - 14:40 »
Thanks a lot Ian, I've put an abridged version of the code I'm using below. I hope it makes sense - shoud be enough to show my methodology. The program would mostly use four separate stereo hardware channels i.e. into four pairs of faders for radio-type use. However, it would be useful for the software channels to share hardware channels when there aren't enough (I also have a small USB soundcard), so the BASSmix option could solve some potential problems.

 If BassAsio.BASS_ASIO_GetDevice = n OrElse BassAsio.BASS_ASIO_SetDevice(n) Then
            Dim info As BASS_ASIO_INFO = BassAsio.BASS_ASIO_GetInfo()
         
        If info IsNot Nothing Then
                'assuming stereo
                For i As Integer = 0 To info.outputs - 1 Step 2
                    Dim chaninfo As BASS_ASIO_CHANNELINFO = BassAsio.BASS_ASIO_ChannelGetInfo(False, i)
                    If chaninfo IsNot Nothing Then
                        CB2.Items.Add(chaninfo)
                        CB3.Items.Add(chaninfo)
                    End If
                Next
               
           End If
        End If
   
    Dim p As Integer = 0

        For Each info As BASS_DEVICEINFO In Bass.BASS_GetDeviceInfos()
            Bass.BASS_Init(p, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
            BassAsio.BASS_ASIO_Init(p, BASSASIOInit.BASS_ASIO_THREAD)
            p += 1
        Next
      
       Ldd_Trk01 = "D:\Temp\Deleme\4th July#Amy MacDonald.mp3"
      
      
   
            If asioOut IsNot Nothing Then
                asioOut.Dispose()
            End If
      
      
      If Ldd_Trk01.EndsWith("flac") Then
                strm01 = BASS_FLAC_StreamCreateFile(Ldd_Trk01, 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
            Else
                strm01 = Bass.BASS_StreamCreateFile(Ldd_Trk01, 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
            End If


            If strm01 <> 0 Then
                'set the asio handler
                asioOut = New BassAsioHandler(asio_dev, asio_ch * 2, strm01)
            End If

            asioOut.Start(0, 0)

Ian @ un4seen

  • Administrator
  • Posts: 25446
Re: BASSASIO Play Problems
« Reply #3 on: 2 Feb '23 - 17:26 »
OK. I would suggest trying BASSASIO directly rather than via the BassAsioHandler class, for possibly more control. For example, if you want to have 8 outputs with a mixer then you could set that up something like this:

Code: [Select]
BASS_ASIO_Init(device, 0); // initialize ASIO device
double rate = BASS_ASIO_GetRate(); // get the device's sample rate
mixer = BASS_Mixer_StreamCreate(rate, 8, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT); // create an 8 channel mixer with same rate
BASS_ASIO_ChannelEnableBASS(false, 0, mixer, true); // set the ASIO device to use the mixer
BASS_ASIO_Start(0, 0); // start it

Then when you want to play a BASS channel/stream, you would use BASS_Mixer_StreamAddChannel to add it to the mixer, with the BASS_SPEAKER_PAIR1/2/3/4 flag to set which ASIO outputs you want it on. And then BASS_Mixer_ChannelRemove to stop it. Please see the documentation for details on the mentioned functions.

MrBlister

  • Posts: 13
Re: BASSASIO Play Problems
« Reply #4 on: 3 Feb '23 - 20:37 »
That's excellent - very many thanks, Ian.