record with OpenAL

BlitzMax Forums/BlitzMax Programming/record with OpenAL

I've done that finally. It works a little but not perfectly.
Does someone see the problem, please ? (just test to listen what is the problem.)

'====================================
'          square reptile
'====================================

' record test

If OpenALInstalled()=False Then RuntimeError "You need to install OpenAL !"
EnableOpenALAudio()
SetAudioDriver("OpenAL")

Global Device
Global CaptureDevice
Device=alcOpenDevice(Null)

If Device=Null Then RuntimeError "No access to OpenAL Device !"

Local flag=InitCapture()
If flag=False Then  RuntimeError "No access to OpenAL capture Device !"


Graphics 640,480,0
SeedRnd MilliSecs()
SetClsColor 0,0,0
SetColor 255,255,255

Cls
DrawText "push [RETURN] to start 5 seconds of recording",0,0
Flip

Global sample:TAudioSample=CreateAudioSample(44100*5*2,44100,SF_MONO16LE)


Global NumSamples:Int
Global sound

While KeyDown(KEY_RETURN)=0
	If KeyDown(KEY_ESCAPE)=1
		ShutdownOpenAL()
		End
	EndIf
Wend
Cls
DrawText "RECORDING...",0,0
Flip

alcCaptureStart(CaptureDevice)
Delay 5000
alcCaptureStop(CaptureDevice)
alcGetIntegerv(CaptureDevice, ALC_CAPTURE_SAMPLES, 4, Varptr(NumSamples))
alcCaptureSamples(CaptureDevice, sample.Samples, NumSamples)

sound=LoadSound( sample,False )

Cls
DrawText "PLAYING...",0,0
Flip

PlaySound sound
Delay 5000

ShutdownOpenAL()

End

'============================================================================================

Function InitCapture()

    If (alcIsExtensionPresent(Device, "ALC_EXT_CAPTURE") = AL_FALSE) Then Return False

    CaptureDevice = alcCaptureOpenDevice(Null, 44100, AL_FORMAT_MONO16, 44100*5*2);
    If Not(CaptureDevice) Then Return False

    Return True
EndFunction


Function ShutdownOpenAL()
    alcCloseDevice(CaptureDevice)
    alcCloseDevice(Device)
EndFunction