Author Topic: BASS.NET API 2.4.14.1  (Read 1022656 times)

santanutosh

  • Posts: 30
Re: BASS.NET API 2.4.14.1
« Reply #1550 on: 4 Sep '20 - 20:00 »
I create 2 streams from 2 different audio files of same freq, channels and bitrate.
Code: [Select]
stream1=Bass.BASS_StreamCreateFile(file1, 0, 0, BASSFlag.BASS_STREAM_DECODE)
stream2=Bass.BASS_StreamCreateFile(file2, 0, 0, BASSFlag.BASS_STREAM_DECODE)
mixer=BassMix.BASS_Mixer_StreamCreate(FileInfo.freq, FileInfo.chans, BASSFlag.BASS_STREAM_DECODE)
BassMix.BASS_Mixer_StreamAddChannel(mixer, stream1, BASSFlag.BASS_MIXER_BUFFER)
BassMix.BASS_Mixer_StreamAddChannel(mixer, stream2, BASSFlag.BASS_MIXER_BUFFER)
Then I create a mixer and add the stream channels in the mixer. Then I set an encoder on the mixer as I need the mixed audio in another file.
Code: [Select]
encHandle=BassEnc.BASS_Encode_Start(mixer, fileName, BASSEncode.BASS_ENCODE_PCM Or BASSEncode.BASS_ENCODE_FP_16BIT, Nothing, 0)Then I use the following to get the mixed data.
Code: [Select]
While len > 0
    len= BassMix.BASS_Mixer_ChannelGetData(stream1, buffer, buffer.Length)
    len= BassMix.BASS_Mixer_ChannelGetData(stream2, buffer, buffer.Length)
End While
BassEnc.BASS_Encode_Stop(encHandle)
I do not know if I'm doing right or wrong. But I'm only getting a 0Kb audio file as an output. Please help me.

santanutosh

  • Posts: 30
Re: BASS.NET API 2.4.14.1
« Reply #1551 on: 6 Sep '20 - 10:56 »
Quote
I have been trying the Utils.GetNormalizationGain function to check the Peak and Gain factor of an Audio file. Then if required I would apply this gain factor to the same audio and save it as a new audio file.
Okay. I solved it.
Code: [Select]
fxHandle = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_VOLUME, 0)
Dim par As New BASS_FX_VOLUME_PARAM
par.fTarget = par.fCurrent * vol
Bass.BASS_FXSetParameters(fxHandle, par)
vol = Gain % delivered by GetNormalizationGain function. After this, Bass.BASS_ChannelGetData(_stream, buffer, buffer.Length) returns the modified data.  :)

santanutosh

  • Posts: 30
Re: BASS.NET API 2.4.14.1
« Reply #1552 on: 6 Sep '20 - 11:05 »
I have a question regarding the Marker used in WaveForm Class. As given in documentation, we can have Markers of different Color and Alignment by using "{...}" in the Marker Name.
Is it also possible to have Markers of different lengths? I tried by putting "{Length=0.5}", but didn't work. Also, if the vertcal position of an individual Marker could be altered, it would be very nice.
Thank you.

radio42

  • Posts: 4717
Re: BASS.NET API 2.4.14.1
« Reply #1553 on: 6 Sep '20 - 16:36 »
All Markers are drawn with the same length using the global MarkerLength property.

toob

  • Posts: 137
BASS_ChannelGetLevel via BassWasapi latency
« Reply #1554 on: 13 Sep '20 - 12:19 »
My goal is to show audio db levels via VU meters from Windows speaker output. It's my understanding I should use BassWasapi to capture the speaker output into a stream. Then use a timer event (or a loop) and use BASS_ChannelGetLevel on the stream to get left and right values for the VU meters.
The code below does this but the values output by BASS_ChannelGetLevel are approx 3 seconds behind the speaker output. For example if I stop the music playing BASS_ChannelGetLevel keeps outputting values greater than say 0.1 for 3 seconds. Likewise if I restart the track BASS_ChannelGetLevel does not output values above 0.1 for 3 seconds.
I have tried setting _wasapi.SetFullDuplex buffer to true and false without any noticeable difference.
3 is my Windows speaker output loopback channel device number.

What is causing the 3 second delay and how can I fix it?

Code: [Select]
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click

        Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
        err = Bass.BASS_ErrorGetCode()
        If Not err = 14 Then
            If err > 0 Then
                MsgBox("bass error " & err.ToString)
                Exit Sub
            End If
        End If

        '3 = loopback speaker output
        _wasapi = New BassWasapiHandler(3, False, 44100, 2, 0, 0.0F)
        _wasapi.Init()
        _wasapi.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, False)
        vu_stream = _wasapi.OutputChannel
        If _wasapi.DeviceMute Then
            _wasapi.DeviceMute = False
        End If
        _wasapi.Start()


        vu_timer.Interval = 50
        vu_timer.Start()

    End Sub

    Private Sub vu_timer_Tick(sender As System.Object, e As System.EventArgs) Handles vu_timer.Tick

        Dim left_val As Double = 0
        Dim right_val As Double = 0

        Dim Levels(2) As Single
        Bass.BASS_ChannelGetLevel(vu_stream, Levels, 0.02, BASSLevel.BASS_LEVEL_STEREO)
        left_val = Levels(0) * 100
        right_val = Levels(1) * 100

        Me.Text = left_val

        If left_val > 0.1 Then
            final_delay_left = False
            last_left_val = left_val
            Me.AGauge1.Value = left_val
        Else
            If final_delay_left = False Then
                final_delay_left = True
                Dim t = New Thread(Sub() Me.NeddleDecayLeft(last_left_val))
                t.Start()
            End If
        End If

    End Sub

Thanks

Ian @ un4seen

  • Administrator
  • Posts: 23640
Re: BASS.NET API 2.4.14.1
« Reply #1555 on: 14 Sep '20 - 13:21 »
The latency will likely be caused by buffering in the intermediate stream. I don't think you need that stream, ie. you can get the level directly from the input/recording. I'm not very familiar with the BassWasapiHandler class so I'm not sure how to best use that, but you could call BASS_WASAPI_Init to initialize and then use BASS_WASAPI_GetLevel(Ex) to get the levels instead. Alternatively, you could use the regular BASS recording functions instead of BASSWASAPI, ie. BASS_RecordInit/Start and BASS_ChannelGetLevel(Ex), as BASS itself supports WASAPI loopback recording too.

If you just want to display the level (no other processing of the data) then another option is to simply use BASS_WASAPI_GetDeviceLevel instead. There's no need to even initialize the device for that. For example:

Code: [Select]
float left = BassWasapi.BASS_WASAPI_GetDeviceLevel(device, 0);
float right = BassWasapi.BASS_WASAPI_GetDeviceLevel(device, 1);

Please see the documentation for details on the mentioned functions.

toob

  • Posts: 137
Re: BASS.NET API 2.4.14.1
« Reply #1556 on: 15 Sep '20 - 13:49 »
Code: [Select]
float left = BassWasapi.BASS_WASAPI_GetDeviceLevel(device, 0);
float right = BassWasapi.BASS_WASAPI_GetDeviceLevel(device, 1);

Thanks Ian that last option worked a treat and more concise for my VU meters.

I use the code below to feed a spectrum visuals stream and also to breakdown FFT frequencies into low/mid/hi ranges to drive DMX lighting on another stream, using two separate timers. The code works fine but your simplified answer above got me thinking if BassWasapiHandler is the best / most effective method to get the live windows speaker output for either the spectrum visuals or FFT data for the low/mid/hi freq triggering?

Code: [Select]
        _wasapi1 = New BassWasapiHandler(3, False, 44100, 2, 0.0F, 0.0F)
        _wasapi1.Init()
        _wasapi1.SetFullDuplex(0, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_STREAM_DECODE, False)
        _wasapi1.DeviceMute = False
        _wasapi1.DeviceVolume = 1.0F
        spectrum_stream = _wasapi1.OutputChannel
        bassmidhi_stream = _wasapi1.OutputChannel
        _wasapi1.Start()

       start_timers...