26 May '13 - 02:19 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
  Home Help Search Login Register  
  Show Posts
Pages: [1]
1  Developments / BASS / Re: BASSWASAPI beta on: 10 Jul '12 - 22:23
Hi everyone,
I'm a newbie and I'm trying to implement a delay. Live audio coming in from the mic input should be delayed by a few seconds.
I have successfully implemented it with Bass and the .net api, but had problems getting a good list of all the input devices.

The code that works is

Private delayStreamHandle As Integer
Private liveStreamHandle As Integer
Private myLiveProc As RECORDPROC
Private myDelayProc As STREAMPROC = Nothing
Private doublewritebuffer As Boolean = False
Private noreadbuffer As Boolean = False
Public MonBuffer As BASSBuffer = New BASSBuffer(5.0F, 44100, 2, 16)


Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, Guid.Empty)
Bass.BASS_RecordInit(-1)
Bass.BASS_RecordSetDevice(0)
Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_ON, -1.0F)
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20)
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 200)
myLiveProc = New RECORDPROC(AddressOf RecordProc)
liveStreamHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, 20, myLiveProc, IntPtr.Zero)
myDelayProc = New STREAMPROC(AddressOf StreamProc)
delayStreamHandle = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, myDelayProc, IntPtr.Zero)
MonBuffer.Clear()
Bass.BASS_ChannelPlay(liveStreamHandle, False) 'start playing
Bass.BASS_ChannelPlay(delayStreamHandle, False) 'start recording
End Sub


Private Function RecordProc(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
MonBuffer.Write(buffer, length)
Return True
End Function

Private Function StreamProc(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
Return MonBuffer.Read(buffer, length, user.ToInt32())
End Function

I would like to change this using wasapi instead of bass. I've been looking at the documentation and going through the message board for days now, trying to figure this out. I've successfully populated dropdowns with the input and output channels, but I don't know how to connect input and output channels in a mixer to make this work.

Here is some code that I've come up with so far (but it's not working):

Private myWasLiveProc As WASAPIPROC
Private myWasDelayProc As WASAPIPROC = Nothing


Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Dim recItem As ComboBoxItem = BassInputComboBox.SelectedItem
Dim playItem As ComboBoxItem = BassOutputComboBox.SelectedItem

Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, Guid.Empty)

myWasLiveProc = New WASAPIPROC(AddressOf InWasapiProc)
BassWasapi.BASS_WASAPI_Init(recItem.Id, 44100, 2, BASSWASAPIInit.BASS_WASAPI_SHARED, 0, 0, myWasLiveProc, IntPtr.Zero) 'initialize WASAPI input device
delayStreamHandle = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_DECODE, myDelayProc, IntPtr.Zero) 'create a stream to receive the data
myWasDelayProc = New WASAPIPROC(AddressOf OutWasapiProc)
BassWasapi.BASS_WASAPI_Init(playItem.Id, 44100, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER, 0, 0, myWasDelayProc, IntPtr.Zero) 'initialize WASAPI output device
outmixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_DECODE) 'create a mixer to feed the output device
BassMix.BASS_Mixer_StreamAddChannel(outmixer, delayStreamHandle, 0) 'plug in the input stream
End Sub


Private Function InWasapiProc(buffer As IntPtr, length As Integer, usr As IntPtr) As Integer
Bass.BASS_StreamPutData(delayStreamHandle, buffer, length) 'feed the data to the input stream
Return 1 'continue recording
End Function


Private Function OutWasapiProc(buffer As IntPtr, length As Integer, usr As IntPtr) As Integer
Dim c As Integer = Bass.BASS_ChannelGetData(outmixer, buffer, length) 'get data from the mixer
If c < 0 Then
Return 0
Else
Return c
End If
End Function

Can you guys give me a hint what I'm doing wrong? I'm sure it is something obvious. Maybe there is a good example somewhere you guys could point me to? I really appreciate any help with this.

Thanks in advance.
ReplyReply Reply with quoteQuote
Pages: [1]
Powered by SMF 1.1.18 | SMF © 2013, Simple Machines