Author Topic: Wasapi recording problems  (Read 326 times)


  • Posts: 18
Wasapi recording problems
« on: 16 Oct '17 - 08:39 »

with the following Code i want  to record the current systemsound, but if there is no sound(silence) then nothing be written into the file. If i use  BASSFlag.BASS_MIXER_NONSTOP in BASS_Mixer_StreamCreate, i get an unplayable real big file, it takes only seconds for more than 1GB. What i'm doing wrong?
The aim is ‎durable recording of this device, equal if silence or not.
Code: [Select]
Imports Un4seen.Bass
Imports Un4seen.Bass.AddOn.Enc
Imports Un4seen.BassWasapi
Imports Un4seen.Bass.AddOn.Mix

Public Class Form1

    Private Device As Integer
    Private Stream As Integer
    Private Mixer As Integer

    Private Proc As WASAPIPROC

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    End Sub

    Private Sub Form1_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        Bass.BASS_Init(0, 0, 0, Nothing)
        Proc = New WASAPIPROC(AddressOf Recording)
        BassWasapi.BASS_WASAPI_Init(5, 0, 0, 0, 1, 0.1, Proc, IntPtr.Zero)
        Dim info As New BASS_WASAPI_INFO
        Stream = Bass.BASS_StreamCreate(info.freq, info.chans, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_DECODE, BASSStreamProc.STREAMPROC_PUSH)
        Mixer = BassMix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_DECODE)
        BassMix.BASS_Mixer_StreamAddChannel(Mixer, Stream, BASSFlag.BASS_DEFAULT)
        BassEnc.BASS_Encode_Start(Mixer, "output.wav", BASSEncode.BASS_ENCODE_PCM Or BASSEncode.BASS_ENCODE_AUTOFREE, Nothing, Nothing)
    End Sub

    Private Function Recording(ByVal buffer As IntPtr, ByVal length As Integer, ByVal user As IntPtr) As Integer
        Dim temp(50000) As Byte, c As Integer
        Bass.BASS_StreamPutData(Stream, buffer, length)
            c = Bass.BASS_ChannelGetData(Mixer, temp, UBound(temp))
        Loop While c > 0
        Return 1
    End Function

End Class

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Wasapi recording problems
« Reply #1 on: 16 Oct '17 - 13:17 »
Are you recording from a "loopback" device? If so, note that a loopback device won't produce any data unless the corresponding output is active. You can force it to be active by initializing it (don't need to actually output anything). An output device always precedes its loopback device in the device list, so if the loopback device is #5 then the output device is #4.


  • Posts: 18
Re: Wasapi recording problems
« Reply #2 on: 17 Oct '17 - 06:30 »
Yes, it is a loopback device, now it works. Thank you Ian. :)