I forgot to post my test code.
I also modified some structures and imports.
Code: Select all
Enumeration ;PaErrorCode
#paNoError = 0
#paNotInitialized = -10000
#paUnanticipatedHostError
#paInvalidChannelCount
#paInvalidSampleRate
#paInvalidDevice
#paInvalidFlag
#paSampleFormatNotSupported
#paBadIODeviceCombination
#paInsufficientMemory
#paBufferTooBig
#paBufferTooSmall
#paNullCallback
#paBadStreamPtr
#paTimedOut
#paInternalError
#paDeviceUnavailable
#paIncompatibleHostApiSpecificStreamInfo
#paStreamIsStopped
#paStreamIsNotStopped
#paInputOverflowed
#paOutputUnderflowed
#paHostApiNotFound
#paInvalidHostApi
#paCanNotReadFromACallbackStream ;/**< @todo review error code name */
#paCanNotWriteToACallbackStream ;/**< @todo review error code name */
#paCanNotReadFromAnOutputOnlyStream ;/**< @todo review error code name */
#paCanNotWriteToAnInputOnlyStream ;/**< @todo review error code name */
#paIncompatibleStreamHostApi
#paBadBufferPtr
EndEnumeration
#paNoDevice = (-1)
#paUseHostApiSpecificDeviceSpecification = (-2)
Enumeration ;PaHostApiTypeId
#paInDevelopment = 0 ; /* use while developing support for a new host API */
#paDirectSound = 1
#paMME = 2
#paASIO = 3
#paSoundManager = 4
#paCoreAudio = 5
#paOSS = 7
#paALSA = 8
#paAL = 9
#paBeOS = 10
#paWDMKS = 11
#paJACK = 12
#paWASAPI = 13
#paAudioScienceHPI = 14
EndEnumeration
#paFloat32 = ($00000001)
#paInt32 = ($00000002)
#paInt24 = ($00000004)
#paInt16 = ($00000008)
#paInt8 = ($00000010)
#paUInt8 = ($00000020)
#paCustomFormat = ($00010000)
#paNonInterleaved = ($80000000)
#paFormatIsSupported = (0)
#paFramesPerBufferUnspecified = (0)
#paNoFlag = (0)
#paClipOff = ($00000001)
#paDitherOff = ($00000002)
#paNeverDropInput = ($00000004)
#paPrimeOutputBuffersUsingStreamCallback = ($00000008)
#paPlatformSpecificFlags = ($FFFF0000)
#paInputUnderflow = ($00000001)
#paInputOverflow = ($00000002)
#paOutputUnderflow = ($00000004)
#paOutputOverflow = ($00000008)
#paPrimingOutput = ($00000010)
Enumeration ; PaStreamCallbackResult
#paContinue=0
#paComplete=1
#paAbort=2
EndEnumeration
Structure PaHostApiInfo Align #PB_Structure_AlignC
structVersion.l
type.l
*name
deviceCount.l
defaultInputDevice.l
defaultOutputDevice.l
EndStructure
Structure PaHostErrorInfo Align #PB_Structure_AlignC
hostApiType.l
errorCode.l
errorText.s
EndStructure
Structure PaDeviceInfo Align #PB_Structure_AlignC
structVersion.l
*name
hostApi.l
maxInputChannels.l
maxOutputChannels.l
defaultLowInputLatency.d
defaultLowOutputLatency.d
defaultHighInputLatency.d
defaultHighOutputLatency.d
defaultSampleRate.d
EndStructure
Structure PaStreamParameters Align #PB_Structure_AlignC
device.l ; 4 bytes
channelCount.l ; 4 bytes
sampleFormat.l ; 4 bytes
suggestedLatency.d ; 8 bytes
pad1.l
*hostApiSpecificStreamInfo
pad2.l
;PORTAUDIO ***MUST*** BE COMPILED WITH STRUCTURE ALIGNMENT = 4
EndStructure
Structure PaStreamCallbackTimeInfo Align #PB_Structure_AlignC
inputBufferAdcTime.d
currentTime.d
outputBufferDacTime.d
EndStructure
Structure PaStreamInfo Align #PB_Structure_AlignC
structVersion.l
inputLatency.d
outputLatency.d
sampleRate.d
EndStructure
;PrototypeC PaStreamCallback(*input, *output, frameCount.l, *timeInfo, statusFlags, *userdata)
;PrototypeC PaStreamFinishedCallback(*user_data)
;Setup flags
#paWinWasapiExclusive = 1 << 0 ;puts WASAPI into exclusive mode
#paWinWasapiRedirectHostProcessor = 1 << 1 ;allows To skip internal PA processing completely
#paWinWasapiUseChannelMask = 1 << 2 ;assigns custom channel mask
#paWinWasapiPolling = 1 << 3 ;selects non-Event driven method of
#paWinWasapiThreadPriority = 1 << 4 ;forces custom thread priority setting.
;Device role
Enumeration PaWasapiDeviceRole
#eRoleRemoteNetworkDevice = 0
#eRoleSpeakers
#eRoleLineLevel
#eRoleHeadphones
#eRoleMicrophone
#eRoleHeadset
#eRoleHandset
#eRoleUnknownDigitalPassthrough
#eRoleSPDIF
#eRoleHDMI
#eRoleUnknownFormFactor
EndEnumeration
;Jack connection type
;PaWasapiJackConnectionType.l ;???
Enumeration PaWasapiJackConnectionType
#eJackConnTypeUnknown
#eJackConnType3Point5mm
#eJackConnTypeQuarter
#eJackConnTypeAtapiInternal
#eJackConnTypeRCA
#eJackConnTypeOptical
#eJackConnTypeOtherDigital
#eJackConnTypeOtherAnalog
#eJackConnTypeMultichannelAnalogDIN
#eJackConnTypeXlrProfessional
#eJackConnTypeRJ11Modem
#eJackConnTypeCombination
EndEnumeration
;Jack geometric location
;PaWasapiJackGeoLocation.l ;???
Enumeration PaWasapiJackGeoLocation
#eJackGeoLocUnk = 0
#eJackGeoLocRear = 1 ;matches EPcxGeoLocation::eGeoLocRear */
#eJackGeoLocFront
#eJackGeoLocLeft
#eJackGeoLocRight
#eJackGeoLocTop
#eJackGeoLocBottom
#eJackGeoLocRearPanel
#eJackGeoLocRiser
#eJackGeoLocInsideMobileLid
#eJackGeoLocDrivebay
#eJackGeoLocHDMI
#eJackGeoLocOutsideMobileLid
#eJackGeoLocATAPI
#eJackGeoLocReserved5
#eJackGeoLocReserved6
EndEnumeration
;Jack general location
;PaWasapiJackGenLocation.l ;???
Enumeration PaWasapiJackGenLocation
#eJackGenLocPrimaryBox = 0
#eJackGenLocInternal
#eJackGenLocSeparate
#eJackGenLocOther
EndEnumeration
;Jack type of port
;PaWasapiJackPortConnection.l ;???
Enumeration PaWasapiJackPortConnection
#eJackPortConnJack = 0
#eJackPortConnIntegratedDevice
#eJackPortConnBothIntegratedAndJack
#eJackPortConnUnknown
EndEnumeration
Enumeration ;Thread priority
#eThreadPriorityNone = 0
#eThreadPriorityAudio ;Default For Shared mode.
#eThreadPriorityCapture
#eThreadPriorityDistribution
#eThreadPriorityGames
#eThreadPriorityPlayback
#eThreadPriorityProAudio ;Default For Exclusive mode
#eThreadPriorityWindowManager
EndEnumeration
;Stream descriptor
Structure PaWasapiStreamInfo Align #PB_Structure_AlignC
size.l ;SizeOf(PaWasapiStreamInfo)
hostApiType.l ;#paWASAPI ;PaHostApiTypeId hostApiType; ;paWASAPI
version.l ;1
flags.l ;collection of PaWasapiFlags
channelMask.l
hostProcessorOutput.l
hostProcessorInput.l
threadPriority.l
streamCategory.l
streamOption.l
EndStructure ;End of Structure PaWasapiStreamInfo
Enumeration PaWasapiStreamCategory
#eAudioCategoryOther = 0
#eAudioCategoryCommunications = 3
#eAudioCategoryAlerts = 4
#eAudioCategorySoundEffects = 5
#eAudioCategoryGameEffects = 6
#eAudioCategoryGameMedia = 7
#eAudioCategoryGameChat = 8
#eAudioCategorySpeech = 9
#eAudioCategoryMovie = 10
#eAudioCategoryMedia = 11
EndEnumeration
Enumeration ;PaWasapiStreamOption
#eStreamOptionNone = 0 ;default
#eStreamOptionRaw = 1 ;bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1
#eStreamOptionMatchFormat = 2 ;force WASAPI Audio Engine into a stream format, supported since Windows 10
EndEnumeration
#paAsioUseChannelSelectors = $01
;Stream descriptor
Structure PaWasapiJackDescription Align #PB_Structure_AlignC
channelMapping.l
color.l ;derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */
connectionType.l
geoLocation.l
genLocation.l
portConnection.l
isConnected.l
EndStructure
Structure PaAsioStreamInfo Align #PB_Structure_AlignC
size.l
hostApiType.l
version.l
flags.l
*channelSelectors
EndStructure
ImportC "portaudio_x64.lib"
Pa_GetVersion()
Pa_GetVersionText()
Pa_GetErrorText(errorCode.l)
Pa_Initialize()
Pa_Terminate()
Pa_GetHostApiCount()
Pa_GetDefaultHostApi()
Pa_GetHostApiInfo(hostApi.l)
Pa_HostApiTypeIdToHostApiIndex(type.l)
Pa_HostApiDeviceIndexToDeviceIndex(hostApi.l, hostApiDeviceIndex.l)
Pa_GetLastHostErrorInfo()
Pa_GetDeviceCount()
Pa_GetDefaultInputDevice()
Pa_GetDefaultOutputDevice()
Pa_GetDeviceInfo(device.l)
Pa_IsFormatSupported(*inputParameters, *outputParameters, sampleRate.d)
Pa_OpenStream(*stream, *inputParameters, *outputParameters, sampleRate.d, framesPerBuffer, streamFlags, *streamCallback, *user_data)
Pa_OpenDefaultStream(*stream, numInputChannels.l, numOutputChannels.l, sampleFormat.l, sampleRate.d, framesPerBuffer.l, *streamCallback, *user_data)
Pa_CloseStream(*stream)
Pa_SetStreamFinishedCallback(*stream, *streamFinishedCallback)
Pa_StartStream(*stream)
Pa_StopStream(*stream)
Pa_AbortStream(*stream)
Pa_IsStreamStopped(*stream)
Pa_IsStreamActive(*stream)
Pa_GetStreamInfo(*stream)
Pa_GetStreamTime.d(*stream)
Pa_GetStreamCpuLoad.d(*stream)
Pa_ReadStream(*stream, *buffer, frames.l)
Pa_WriteStream(*stream, *buffer, frames.l)
Pa_GetStreamReadAvailable(*stream)
Pa_GetStreamWriteAvailable(*stream)
Pa_GetSampleSize(format.l)
Pa_Sleep(msec.l)
PaWasapi_GetDeviceDefaultFormat(*pFormat, nFormatSize.l, nDevice.l)
PaWasapi_GetDeviceRole(nDevice.l)
PaWasapi_ThreadPriorityBoost(*hTask, nPriorityClass.l)
PaWasapi_ThreadPriorityRevert(*hTask)
PaWasapi_GetFramesPerHostBuffer(*pStream, *nInput, *nOutput)
PaWasapi_GetJackCount(nDevice.l, *jcount);
PaWasapi_GetJackDescription(nDevice.l, jindex.l, *pJackDescription)
PaAsio_GetAvailableBufferSizes(device.l, *minBufferSizeFrames, *maxBufferSizeFrames, *preferredBufferSizeFrames, *granularity)
PaAsio_ShowControlPanel(device.l, *systemSpecific)
EndImport
Global buffersize = 16384, mutex = CreateMutex(), *outputStream, *inputStream
*buffer = AllocateMemory(buffersize)
Procedure Error(err)
Debug Pa_GetErrorText(err)
Debug PeekS(Pa_GetErrorText(err), -1, #PB_Ascii)
;MessageRequester("", PeekS(Pa_GetErrorText(err), -1, #PB_Ascii))
End
EndProcedure
ProcedureC.l outputStreamCallback(*in, *output, frameCount.l, *timeInfo.PaStreamCallbackTimeInfo, statusFlags.l, *userData)
LockMutex(mutex)
CopyMemory(*userData, *output, buffersize)
UnlockMutex(mutex)
ProcedureReturn #paContinue
EndProcedure
ProcedureC.l inputStreamCallback(*in, *output, frameCount.l, *timeInfo.PaStreamCallbackTimeInfo, statusFlags.l, *userData)
LockMutex(mutex)
CopyMemory(*in, *userData, buffersize)
UnlockMutex(mutex)
ProcedureReturn #paContinue
EndProcedure
Pa_Initialize()
*my_dev.PaDeviceInfo
For d_count = 0 To Pa_GetDeviceCount() - 1
*my_dev = Pa_GetDeviceInfo(d_count)
Debug Str(d_count) + " " + PeekS(*my_dev\name, -1, #PB_Ascii)
; Debug *my_dev\hostApi
; Debug *my_dev\maxInputChannels
; Debug *my_dev\maxOutputChannels
; Debug *my_dev\defaultLowInputLatency
; Debug *my_dev\defaultLowOutputLatency
; Debug *my_dev\defaultHighInputLatency
; Debug *my_dev\defaultHighOutputLatency
; Debug *my_dev\defaultSampleRate
Next
; Audio Output Setup
Define outputStreamParameters.PaStreamParameters
outputStreamParameters\channelCount = 2
outputStreamParameters\device = 0 ;<---- ASIO Soundcard output device
outputStreamParameters\sampleFormat = #paFloat32
Dim outputchannelselectors.l(1)
outputchannelselectors(0) = 2 ;<--------- use outputs 2L
outputchannelselectors(1) = 3 ;<--------- use outputs 3R
Define asio_info.PaAsioStreamInfo
asio_info\size = SizeOf(asio_info)
asio_info\hostApiType = #paASIO
asio_info\version = 0
asio_info\flags = #paAsioUseChannelSelectors
asio_info\channelSelectors = outputchannelselectors
outputStreamParameters\hostApiSpecificStreamInfo = @asio_info
err = Pa_OpenStream(@*outputStream, #Null, @outputStreamParameters, 48000, buffersize/8, #paNoFlag, @outputStreamCallback(), *buffer)
err = Pa_StartStream(*outputStream)
If err <> #paNoError
Error(err)
EndIf
Define inputStreamParameters.PaStreamParameters
inputStreamParameters\channelCount = 1
inputStreamParameters\device = 4 ;<----- WDM soundcard input device
inputStreamParameters\sampleFormat = #paFloat32
err = Pa_OpenStream(@*inputStream, @inputStreamParameters, #Null, 48000, buffersize/8, #paNoFlag, @inputStreamCallback(), *buffer)
err = Pa_StartStream(*inputStream)
If err <> #paNoError
Error(err)
EndIf
If err <> #paNoError
Error(err)
EndIf
Repeat
Delay(1)
ForEver