Code: Alles auswählen
Declare AudioGetError(ErrorValue.l)
Declare.l AudioGetNumber() ;Anzahl der Audiogeräte ermitteln (Erstes Gerät = 0,...)
Declare.l AudioOpenDevice(lDeviceID.l) ;Handle des Audiodevices wird für alle weiteren functionen benötigt
Declare.s AudioGetDeviceInfo(lDeviceID.l,lDeviceInfoType.l) ;Gibt den String des Devices zurück der dem Typen entspricht
Declare.l AudioBuildHeaderStart(lSoundDeviceHandle.l)
Declare.l AudioStartRecording(lSoundDeviceHandle.l)
Declare.l AudioStopRecording(lSoundDeviceHandle.l)
Declare.l AudioBuildHeaderStop(lSoundDeviceHandle.l)
Declare.l AudioCloseDevice(lSoundDeviceHandle.l)
;Declare CallBack( hWnd.l, uMsg.l, wParam.l, lParam.l )
Declare ReadAndSave(wParam.l,lParam.l)
#SOUND_NCHANNELS = 1 ; This example only support Mono
#SOUND_NBITS = 16 ; This example only support 16bits
#SOUND_NHERTZ = 44100 ; Try 8000, 11050, 22100, 44100...
#BUFFER_NUM = 8 ; Number of buffer for capture
#BUFFER_SIZE = 512 ; Size of each buffer, should be x2 in Stereo
#BUFFER_TICK = 10 ; Wave redraw delay : SetTimer_ in CAPTURE_Start()
Enumeration
#AudioGetInfo_ManufacturerID
#AudioGetInfo_ProductID
#AudioGetInfo_DriverVersionNumber
#AudioGetInfo_ProductName
#AudioGetInfo_Formats
#AudioGetInfo_Channels
EndEnumeration
Structure WAVEFORMATEX
wFormatTag.w
nChannels.w
nSamplesPerSec.l
nAvgBytesPerSec.l
nBlockAlign.w
wBitsPerSample.w
cbSize.w
EndStructure
Dim inHdr.WAVEHDR(#BUFFER_NUM)
lpWaveHdr.WAVEHDR
;Ende der deffinitionen
lSoundDevicesNumber = AudioGetNumber()
Debug "Anzahl: "+Str(lSoundDevicesNumber)
If lSoundDevicesNumber
For i = 0 To lSoundDevicesNumber - 1
lSoundDeviceID.l = i + 1
lSoundDeviceHandle.l = AudioOpenDevice(i)
lSoundDeviceName.s = AudioGetDeviceInfo(lSoundDeviceHandle,#AudioGetInfo_ProductName)
Debug "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
Debug "Gerät: " + Str(lSoundDeviceID.l)
Debug "Gerätehandle: " + Str(lSoundDeviceHandle)
Debug "Aufnahmegerät: " + lSoundDeviceName
Debug "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
Next i
AudioBuildHeaderStart(lSoundDeviceHandle)
AudioStartRecording(lSoundDeviceHandle)
OpenWindow(0,0,0,200,200,#PB_Window_SystemMenu,"")
CreateGadgetList(WindowID(0))
ButtonGadget(0,0,0,100,100,"Hallo")
; SetWindowCallback(@CallBack())
CreateFile(0,"C:\TEST1.raw")
Debug #MM_WIM_DATA
While WindowEvent() <> #WM_CLOSE
Result.l = #PB_ProcessPureBasicEvents
Select uMsg
Case #MM_WIM_DATA
Debug wParam
Debug lParam
ReadAndSave(wParam,lParam)
Case #WM_TIMER
;CAPTURE_Draw()
Case #WM_SIZE
;GUI_Resize()
Case #WM_CLOSE
End
Case #WM_COMMAND
;Select wParam
; Case #gadRecord : ;FILE_Create()
; Case #gadStop : ;FILE_Close()
; Case #gadMode : rec\mode = #TRUE-rec\mode
;EndSelect
EndSelect
Wend
AudioStopRecording(lSoundDeviceHandle)
CloseFile(0)
AudioBuildHeaderStop(lSoundDeviceHandle)
AudioCloseDevice(lSoundDeviceHandle)
Else
MessageRequester("Fehler","Keine Soundkarte vorhanden!",16)
EndIf
End
Procedure.l AudioGetNumber()
ProcedureReturn waveInGetNumDevs_()
EndProcedure
Procedure.l AudioOpenDevice(lDeviceID.l)
pwfx.WAVEFORMATEX
pwfx\wFormatTag = #WAVE_FORMAT_PCM
pwfx\nChannels = #SOUND_NCHANNELS
pwfx\wBitsPerSample = #SOUND_NBITS
pwfx\nSamplesPerSec = #SOUND_NHERTZ
pwfx\nBlockAlign = #SOUND_NCHANNELS * (#SOUND_NBITS/8)
pwfx\nAvgBytesPerSec = #SOUND_NHERTZ * pwfx\nBlockAlign
pwfx\cbSize = 0;SizeOf(WAVEFORMATEX)
AudioGetError(waveInOpen_(@lfuncptrDeviceHandle.l,lDeviceID,@pwfx,#NULL,#NULL,#WAVE_FORMAT_DIRECT))
;#WAVE_FORMAT_DIRECT = 8
ProcedureReturn lfuncptrDeviceHandle.l
EndProcedure
Procedure.s AudioGetDeviceInfo(lDeviceHandle.l,lDeviceInfoType.l)
AudioGetError(waveInGetDevCaps_(lDeviceHandle,strucDeviceCapacity.WAVEINCAPS,SizeOf(WAVEINCAPS)))
Select lDeviceInfoType
Case #AudioGetInfo_ManufacturerID
;Manufacturer identifier For the device driver For the waveform-audio input device.
;sAudioDeviceInfo.s = strucDeviceCapacity\lDeviceInfoType
Case #AudioGetInfo_ProductID
;Product identifier For the waveform-audio input device.
Case #AudioGetInfo_DriverVersionNumber
;Version number of the device driver For the waveform-audio input device. The high-order byte is the major version number, And the low-order byte is the minor version number.
Case #AudioGetInfo_ProductName
;Null-terminated string that contains the product name.
sAudioDeviceInfo.s = PeekS(@strucDeviceCapacity\szPname)
Case #AudioGetInfo_Formats
;Specifies the standard formats that are supported. It is one Or a combination of the following flags.
;Flag Description
;WAVE_FORMAT_1M08 11.025 kHz, mono, 8-bit
;WAVE_FORMAT_1M16 11.025 kHz, mono, 16-bit
;WAVE_FORMAT_1S08 11.025 kHz, stereo, 8-bit
;WAVE_FORMAT_1S16 11.025 kHz, stereo, 16-bit
;WAVE_FORMAT_2M08 22.05 kHz, mono, 8-bit
;WAVE_FORMAT_2M16 22.05 kHz, mono, 16-bit
;WAVE_FORMAT_2S08 22.05 kHz, stereo, 8-bit
;WAVE_FORMAT_2S16 22.05 kHz, stereo, 16-bit
;WAVE_FORMAT_4M08 44.1 kHz, mono, 8-bit
;WAVE_FORMAT_4M16 44.1 kHz, mono, 16-bit
;WAVE_FORMAT_4S08 44.1 kHz, stereo, 8-bit
;WAVE_FORMAT_4S16 44.1 kHz, stereo, 16-bit
Case #AudioGetInfo_Channels
;Number that specifies whether the device supports mono (1) Or stereo (2) input.
EndSelect
ProcedureReturn sAudioDeviceInfo
EndProcedure
Procedure.l AudioBuildHeaderStart(lDeviceHandle.l)
For i = 0 To #BUFFER_NUM - 1
inHdr(i)\lpData = AllocateMemory(#BUFFER_SIZE)
inHdr(i)\dwBufferLength = #BUFFER_SIZE
AudioGetError(waveInPrepareHeader_(lDeviceHandle,inHdr(i),SizeOf(WAVEHDR)))
AudioGetError(waveInAddBuffer_(lDeviceHandle,inHdr(i),SizeOf(WAVEHDR)))
Next i
EndProcedure
Procedure AudioStartRecording(lDeviceHandle.l)
AudioGetError(waveInStart_(lDeviceHandle))
EndProcedure
Procedure AudioStopRecording(lDeviceHandle.l)
AudioGetError(waveInReset_(lDeviceHandle))
AudioGetError(waveInStop_(lDeviceHandle))
EndProcedure
Procedure AudioBuildHeaderStop(lDeviceHandle.l)
For i = 0 To #BUFFER_NUM - 1
AudioGetError(waveInUnprepareHeader_(lDeviceHandle,inHdr(i),SizeOf(WAVEHDR)))
Next i
EndProcedure
Procedure AudioCloseDevice(lDeviceHandle.l)
AudioGetError(waveInClose_(lDeviceHandle))
EndProcedure
Procedure AudioGetError(ErrorValue.l)
If ErrorValue.l
ErrorMessage.s = Space(500);Space(#MAXERRORLENGTH)
waveInGetErrorText_(ErrorValue,ErrorMessage,500);#MAXERRORLENGTH)
;waveOutGetErrorText_(ErrorValue,ErrorMessage,#MAXERRORLENGTH)
MessageRequester("Fehler "+Str(ErrorValue),ErrorMessage,16)
;CAPTURE_Stop()
End
EndIf
EndProcedure
Procedure ReadAndSave( hWaveIn.l,lpWaveHdr.l)
AudioGetError( waveInAddBuffer_(hWaveIn,lpWaveHdr,SizeOf(WAVEHDR)))
Buffer = PeekL(lpWaveHdr)
Size = PeekL(lpWaveHdr + 8)
Recorded = Recorded + Size
; dwBytesRecorded
WriteData(Buffer,Size)
Debug Str(Recorded) + " bytes recorded"
EndProcedure