Ooops
March 05, 2021, 08:09:00 PM

Author Topic: Open AL Issue  (Read 474 times)

Online Hardcoal

Open AL Issue
« on: February 01, 2021, 09:04:17 PM »
ive been struggling with this OpenAL
Im trying to record sound..
but the command Device = alcOpenDevice(null) it finds no device..
i even tried to put the device name instead of null.. didnt work..

Im using blitzmax 1.50

here is the code.

Code: [Select]
SuperStrict

Rem
Use ESC to exit
End Rem

Framework brl.blitz
Import vertex.openal
Import brl.math
Import brl.max2d
Import brl.glmax2d
Import "float_ring_buffer.bmx"

TOpenAL.Open()
TOpenAL.InitAL()
TOpenAL.InitALC()

 Global Device:Byte Ptr,  ..
        Context:Byte Ptr

 Device = alcOpenDevice(Null)
 If Device = Null Then Notify "device is null" ; End
 Context = alcCreateContext(Device, Null)
 alcMakeContextCurrent(Context)

 WriteStdout("List of capture devices:~n")
 For Local CaptureDevice:String = EachIn EnumCaptureDevices()
WriteStdout(CaptureDevice + "~n")
 Next
 WriteStdout("#Default: " + String.FromCString( ..
alcGetString(Null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)))

 Graphics(800, 600)

 Const SAMPLE_RATE:Int = 44100,  ..    'In Hertz [Hz]
      BUFFER_SIZE:Int = SAMPLE_RATE 'In Samples
'Null means using default capture device
 Global CaptureDevice:Byte Ptr
 CaptureDevice = alcCaptureOpenDevice(Null, 44100, AL_FORMAT_MONO16, BUFFER_SIZE)
 If CaptureDevice = Null Then Notify ("CaptureDevice is null") ; End

Global Data:Byte[] = New Byte[BUFFER_SIZE * 2] '16 Bit per sample
Global RingBuffer : TFloatRingBuffer = TFloatRingBuffer.Create(BUFFER_SIZE)
Global Samples : Float[] = New Float[GraphicsWidth()]

alcCaptureStart(CaptureDevice)

While Not KeyDown(KEY_ESCAPE)
' Read Samples
Local NumAvailableSamples:Int
alcGetIntegerv(CaptureDevice , ALC_CAPTURE_SAMPLES, 4, Varptr(NumAvailableSamples))
If NumAvailableSamples > 0 Then
alcCaptureSamples(CaptureDevice, Data, NumAvailableSamples)
For Local I:Int = 0 Until NumAvailableSamples
Local Offset:Int = I*2 ' 16 Bit per sample
Local Sample:Float = DecodeSigned16BitLittleEndian(Data, Offset)
RingBuffer.Put(Sample)
Next
EndIf

If RingBuffer.GetSize() >= GraphicsWidth() Then
RingBuffer.PeakLast(Samples, 0, GraphicsWidth())
EndIf

' Root Mean Square
Local RMS:Float = 0
Local Size:Int = GraphicsWidth()
For Local I:Int = 0 Until Size
RMS = RMS + (Samples[I] * Samples[I])
Next
RMS = Sqr(RMS / Size)
Assert 0 <= RMS And RMS <= 1

Cls()
' Draw Intensity
DrawRect 0, 0, RMS * GraphicsWidth(), 20

' Draw wave form

Local OldX:Int=0 ; Local OldY:Float=GraphicsHeight()/2
For Local X:Int = 0 Until GraphicsWidth()
Local Y:Float = Samples[X] * 100 + GraphicsHeight()/2
DrawLine OldX, OldY, X, Y
OldX = X ; OldY = Y
Next

Flip()
Wend

alcCaptureStop(CaptureDevice)

alcMakeContextCurrent(Null)
alcDestroyContext(Context)
alcCloseDevice(Device)

TOpenAL.Close()
EndGraphics()
End

Function EnumCaptureDevices:String[]()
Local List       : Byte Ptr, ..
      Specifiers : String[], ..
      Specifier  : String

' Null-terminated specifier list
List = alcGetString(Null, ALC_CAPTURE_DEVICE_SPECIFIER)

' Separate specifier by null character
While List[0]
Specifiers = Specifiers[..Specifiers.Length + 1]
Specifiers[Specifiers.Length - 1] = String.FromCString(List)
List :+ Specifiers[Specifiers.Length - 1].Length + 1
Wend

Return Specifiers
End Function

Function DecodeSigned16BitLittleEndian:Float(Buffer:Byte Ptr, Offset:Int)
Local LowerB:Byte, HigherB:Byte
HigherB = Buffer[offset + 1]
LowerB = Buffer[offset]
Local SampleInt:Int = (HigherB Shl 8) | (LowerB & $ff)
If SampleInt & $8000 Then SampleInt = $FFFF8000 | (SampleInt & $7FFF)
Local Sample:Float = Float(SampleInt) / Float($7fff)
Return Sample
End Function

i also tried vanilla mode.. for openal.. but it uses other sets of commands and there is no Demo.. to learn from
hmmmm

Online Dabz

Re: Open AL Issue
« Reply #1 on: February 01, 2021, 09:14:20 PM »
Do you have OpenAL installed?

Code: [Select]
If OpenALInstalled()=False Then
RuntimeError "Please install OpenAl"
EndIf

Global Device%
Device=alcOpenDevice(Null)
If Device=Null Then
RuntimeError "Cannot Open Device"
EndIf

Works on vanilla, not tried on NG!

If its not installed, you can nab the redist package here:-

https://community.pcgamingwiki.com/files/file/10-openal/

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Online Dabz

Re: Open AL Issue
« Reply #2 on: February 01, 2021, 09:19:49 PM »
I've also spied this:-

https://mojolabs.nz/posts.php?topic=90830

Which should help, but I've never tried to capture sound from a device so sadly... This is all I have!

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Online Hardcoal

Re: Open AL Issue
« Reply #3 on: February 01, 2021, 11:03:43 PM »
thanks, but ive failed solving it..
some commands in vertex mod are missing..
anyway.. it wont work..
hmmmm

Offline Midimaster

Re: Open AL Issue
« Reply #4 on: February 11, 2021, 08:12:20 AM »
Ok... 10 years ago I did a lot with OpenAl recording. Two of my music apps used OpenAl for recording or listening to the microphon (for real time FFT-analysing).

In this time I wrote this tutorial Dabz found in the old blitzmax forum. I can tell you it still works 100%

Today I testet my old apps, and both work as expected. The only difference to the times of old XP is, that now on Win-10 a real device needs to be connected.  At first I forgot to conncet a microphone and this was the reason why alcCaptureOpenDevice() failt. Without it, my apps will crash!

Now I reduced the code of the tutorial to a very minimum as you can see here: This code runs perfect if a microphone is attached to the computer.

For installation of OpenAL I still use the last "official Installer" oalinst.exe from 2009. It is a 800k-Exe file.

Here is my code:
Code: BlitzMax
  1. If OpenALInstalled()=False
  2.   Notify "OpenAl Driver is missing"
  3.   InstallOpenAl
  4. EndIf
  5. EnableOpenALAudio()
  6.  
  7. Global Device:Int=alcOpenDevice(Null)
  8. If Device=Null Then RuntimeError "No access to OpenAL Device !"
  9.  
  10. Local flag%=InitCapture()
  11. If flag=False Then  RuntimeError "No access to OpenAL capture Device !"
  12.  
  13. Global CaptureDevice:Int
  14. alcCaptureStart(CaptureDevice)
  15.  
  16. Function InitCapture%()
  17.         CaptureDevice = alcCaptureOpenDevice(Null, 44100, AL_FORMAT_STEREO16, 44100*5*4);
  18.         If Not(CaptureDevice) Then Return False
  19.         Return True
  20. EndFunction
  21.  
  22. Function InstallOpenAl()
  23.                 system_ "oalinst.exe"
  24.                 Notify("Open AL Installer")
  25.                 End
  26. End Function
  27.  

with this minimum code it will be more  easy for you to test and perhaps find a solution. I will also contact Brucey, whether he already knows a modern module with recording facilities.
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Derron

Re: Open AL Issue
« Reply #5 on: February 11, 2021, 09:59:42 AM »
I posted some similar piece of code in the discord channel


Enum capture devices:
Code: BlitzMax
  1. SuperStrict
  2. Framework Brl.StandardIO
  3. Import Brl.OpenALAudio
  4. ?linux
  5. Import "-ldl" 'fix "undefined reference to "dlopen/dlsym"
  6. ?
  7.  
  8. EnableOpenALAudio()
  9.  
  10. print "OpenALInstalled: " + OpenALInstalled()
  11. if not OpenALInstalled() then End
  12.  
  13.  
  14. For local device:String = EachIn EnumOpenALCaptureDevices()
  15.     print "capture device: " + device
  16. Next
  17.  
  18.  
  19. print "DEFAUlT capture device: " + GetOpenALDefaultCaptureDevice()
  20.  
  21. Function GetOpenALDefaultCaptureDevice:String()
  22.     Return String.FromCString( alcGetString(Null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER) )
  23. End Function
  24.  
  25.  
  26. Function EnumOpenALCaptureDevices:String[]()
  27.     Local p:Byte Ptr = alcGetString(Null,ALC_CAPTURE_DEVICE_SPECIFIER )
  28.     If Not p Return Null
  29.  
  30.     Local devices:String[100]
  31.     Local n:Int
  32.     While p[0] And n<100
  33.         Local sz:Int
  34.         Repeat
  35.             sz:+1
  36.         Until Not p[sz]
  37.  
  38.         devices[n] = String.FromBytes(p, sz)
  39.  
  40.         n :+ 1
  41.         p :+ sz + 1
  42.     Wend
  43.     Return devices[.. n]
  44. End Function
  45.  


But trying to capure stuff fails - seems I miss something:
Code: BlitzMax
  1. '        device = alcCaptureOpenDevice( String.FromCString(alcGetString(Null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)), 48000, AL_FORMAT_MONO16, 1024)
  2.         device = alcCaptureOpenDevice( "960 Headset Analog Mono", 48000, AL_FORMAT_MONO16, 4*1024 )
  3. ...
  4.         alcCaptureStart(device)
  5.         Local numberOfFrames:Int
  6.         alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, 1, Varptr numberOfFrames)
  7.        
  8.         print "captured: " + numberOfFrames
  9.        
  10.         if numberOfFrames
  11.             Local bank:TBank = CreateBank(8*1024)
  12.  
  13.             alcCaptureSamples(device, bank._buf, numberOfFrames)
  14.         EndIf
  15.  


bye
Ron

Online Hardcoal

Re: Open AL Issue
« Reply #6 on: February 11, 2021, 10:01:40 AM »
hi midimaster..

since im using vertex demo to test recording.. i dont have a demo code for brl openaudioal mod

can you please post a full demo that works under this mod?

here is my code..
and the code you have posted wont recognize some of the commands..
it is unrecognized by vertex mod  like EnableOpenALAudio()


thats my corrent code


anyway midimaster, i tried your code and got "No access to OpenAL Device !" error

Code: [Select]
Strict

Rem
Use ESC to exit
End Rem

Import brl.blitz

Framework pub.openal
Import vertex.openal

Import brl.math
Import brl.max2d
Import brl.glmax2d
Import "float_ring_buffer.bmx"

Import pub.freeaudio

TOpenAL.Open()
TOpenAL.InitAL()
TOpenAL.InitALC()

 Global Device:Byte Ptr,  ..
        Context:Byte Ptr

 Device = alcOpenDevice(Null)
 If Device = Null Then WriteStdout "Device is null when using alcOpenDevice~n"
 Context = alcCreateContext(Device, Null)
 alcMakeContextCurrent(Context)

 WriteStdout("List of capture devices:~n")
 For Local CaptureDevice:String = EachIn EnumCaptureDevices()
WriteStdout(CaptureDevice + "~n")
 Next
 WriteStdout("#Default: " + String.FromCString( ..
alcGetString(Null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)))

 Graphics(800, 600)

 Const SAMPLE_RATE:Int = 44100,  ..    'In Hertz [Hz]
      BUFFER_SIZE:Int = SAMPLE_RATE 'In Samples
'Null means using default capture device
 Global CaptureDevice:Byte Ptr
 CaptureDevice = alcCaptureOpenDevice(Null, 44100, AL_FORMAT_MONO16, BUFFER_SIZE)
 If CaptureDevice = Null Then Notify ("CaptureDevice is null") ; End

Global Data:Byte[] = New Byte[BUFFER_SIZE * 2] '16 Bit per sample
Global RingBuffer : TFloatRingBuffer = TFloatRingBuffer.Create(BUFFER_SIZE)
Global Samples : Float[] = New Float[GraphicsWidth()]

alcCaptureStart(CaptureDevice)

While Not KeyDown(KEY_ESCAPE)
' Read Samples
Local NumAvailableSamples:Int
alcGetIntegerv(CaptureDevice , ALC_CAPTURE_SAMPLES, 4, Varptr(NumAvailableSamples))
If NumAvailableSamples > 0 Then
alcCaptureSamples(CaptureDevice, Data, NumAvailableSamples)
For Local I:Int = 0 Until NumAvailableSamples
Local Offset:Int = I*2 ' 16 Bit per sample
Local Sample:Float = DecodeSigned16BitLittleEndian(Data, Offset)
RingBuffer.Put(Sample)
Next
EndIf

If RingBuffer.GetSize() >= GraphicsWidth() Then
RingBuffer.PeakLast(Samples, 0, GraphicsWidth())
EndIf

' Root Mean Square
Local RMS:Float = 0
Local Size:Int = GraphicsWidth()
For Local I:Int = 0 Until Size
RMS = RMS + (Samples[I] * Samples[I])
Next
RMS = Sqr(RMS / Size)
Assert 0 <= RMS And RMS <= 1

Cls()
' Draw Intensity
DrawRect 0, 0, RMS * GraphicsWidth(), 20

' Draw wave form

Local OldX:Int=0 ; Local OldY:Float=GraphicsHeight()/2
For Local X:Int = 0 Until GraphicsWidth()
Local Y:Float = Samples[X] * 100 + GraphicsHeight()/2
DrawLine OldX, OldY, X, Y
OldX = X ; OldY = Y
Next

Flip()
Wend

alcCaptureStop(CaptureDevice)

alcMakeContextCurrent(Null)
alcDestroyContext(Context)
alcCloseDevice(Device)

TOpenAL.Close()
EndGraphics()
End

Function EnumCaptureDevices:String[]()
Local List       : Byte Ptr, ..
      Specifiers:String[]

' Null-terminated specifier list
List = alcGetString(Null, ALC_CAPTURE_DEVICE_SPECIFIER)

' Separate specifier by null character
While List[0]
Specifiers = Specifiers[..Specifiers.Length + 1]
Specifiers[Specifiers.Length - 1] = String.FromCString(List)
List :+ Specifiers[Specifiers.Length - 1].Length + 1
Wend

Return Specifiers
End Function

Function DecodeSigned16BitLittleEndian:Float(Buffer:Byte Ptr, Offset:Int)
Local LowerB:Byte, HigherB:Byte
HigherB = Buffer[offset + 1]
LowerB = Buffer[offset]
Local SampleInt:Int = (HigherB Shl 8) | (LowerB & $ff)
If SampleInt & $8000 Then SampleInt = $FFFF8000 | (SampleInt & $7FFF)
Local Sample:Float = Float(SampleInt) / Float($7fff)
Return Sample
End Function
hmmmm

Offline Midimaster

Re: Open AL Issue
« Reply #7 on: February 11, 2021, 02:44:55 PM »
My code should run as stand alone app. If not... the OpenAl maybe installed not correct. I will send you the original installer by CreativeLabs from 2009 in a pm
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Derron

Re: Open AL Issue
« Reply #8 on: February 11, 2021, 03:10:41 PM »
Think I got it working with pub.openal too.

I am not sure - but I assume it would be better to kick off audio recording in a new thread (dunno if openal can work in threads). And then to either define a "record X seconds" or a "record until stopped" ...
Another option is to call a callback each time a "second" is recorded (so you can fetch the audio data) or everytime the "buffer" is full.

Plenty of options.


bye
Ron

Online Hardcoal

Re: Open AL Issue
« Reply #9 on: February 11, 2021, 03:43:31 PM »
i never messed with threads , i have no idea how to do that..
anyway i keep testing..
eventually i must make it work or im stuck in the specific project :)

Derron if you got an example code.. ill be glad to see it because i only have example code for the vertex version.

hmmmm

Offline Derron

Re: Open AL Issue
« Reply #10 on: February 11, 2021, 04:01:18 PM »
You want to create some advanced stuff (your project).
I do not have any more clues than you about OpenAL - it is googling what the commands do (in C) and what samples do (in C)
and then trying to use these commands in Blitzmax.

Experiment with the code, look what others did with openal - and try to adopt the code, bit by bit.


bye
Ron

Online Hardcoal

Re: Open AL Issue
« Reply #11 on: February 11, 2021, 04:13:37 PM »
Ive experimented for hours.. Its not that i come here and expect people to feed me.
And ill keep trying, until ill succeed..

Thanks
hmmmm

Offline Midimaster

Re: Open AL Issue
« Reply #12 on: February 11, 2021, 04:19:37 PM »
also news from me. also my code works and my apps too. I simply forgot to connect a microphone to the computer. Without any input device the code fails. With a microphone connected it works. I updated my reply #4.
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Derron

Re: Open AL Issue
« Reply #13 on: February 11, 2021, 04:59:44 PM »
Here is another approach - just using "pub.openal":


Code: BlitzMax
  1. SuperStrict
  2. Framework Brl.StandardIO
  3. Import Brl.OpenALAudio
  4. Import Brl.Bank
  5. Import Brl.Threads
  6. Import "-ldl" 'fix "undefined reference to "dlopen/dlsym"
  7.  
  8.  
  9. EnableOpenALAudio()
  10.  
  11. print "OpenALInstalled: " + OpenALInstalled()
  12. if not OpenALInstalled() then End
  13.  
  14.  
  15. For local device:String = EachIn TOpenALCapture.EnumDevices()
  16.         print "capture device: " + device
  17. Next
  18.  
  19. print "DEFAUlT capture device: " + TOpenALCapture.GetDefaultDevice()
  20.  
  21.  
  22. local openALCapture:TOpenALCapture = new TOpenALCapture( TOpenALCapture.GetDefaultDevice() )
  23. openALCapture.StartCapture()
  24. For local i:int = 1 to 10
  25.         Delay(100)
  26.         print "waited "+(i*100)+"ms"
  27. Next
  28. openALCapture.StopCapture()
  29. Local result:TBank = openALCapture.GetCapturedData()
  30. SaveBank(result, "record.dat")
  31.  
  32.  
  33. Type TOpenALCapture
  34.         Field deviceName:String
  35.         Field device:Byte Ptr
  36.         Field context:Byte Ptr
  37.         Field captureThread:TThread
  38.         Field captureThreadExit:Int
  39.         Field captureRunning:Int
  40.         Field capturedData:TBank
  41.         Field capturedDataFrames:Int = 0
  42.        
  43.         Method New(deviceName:String)
  44.                 SetDeviceName(deviceName)
  45.         End Method
  46.        
  47.        
  48.         Method SetDeviceName:TOpenALCapture(deviceName:String)
  49.                 self.deviceName = deviceName
  50. rem
  51.                 context = alcCreateContext(device, Null)
  52.                 If not context
  53. print "cannot create context"
  54.                         alcCloseDevice( device )
  55.                         Return Null
  56.                 EndIf
  57.                
  58.                 alcMakeContextCurrent(context)
  59. endrem
  60.                 Return Self
  61.         End Method
  62.        
  63.        
  64.         Method StartCapture:Int()
  65.                 If captureThread Then Return False
  66.                
  67.                 capturedData = CreateBank(2048)
  68.                 capturedDataFrames = 0
  69.                 captureRunning = True
  70.  
  71.                 'device = alcCaptureOpenDevice( String.FromCString(alcGetString(Null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)), 48000, AL_FORMAT_MONO16, 1024)
  72.                 'device = alcCaptureOpenDevice( Null, 48000, AL_FORMAT_MONO16, 1024)
  73.                 device = alcCaptureOpenDevice( deviceName, 48000, AL_FORMAT_MONO16, 1024)
  74.                 If Not device
  75.                         captureRunning = False
  76.                         Throw "StartCapture: failed opening device"
  77.                         Return False
  78.                 EndIf
  79.  
  80.                 captureThread = CreateThread( RunCaptureThread, self )
  81.                 if not captureRunning Then Return False
  82.                
  83.                 Return True
  84.         End Method
  85.        
  86.  
  87.         Method StopCapture:Int()
  88.                 If not captureThread then Return False
  89.  
  90.                 captureThreadExit = True
  91.                 WaitThread(captureThread)
  92.                
  93.                 captureThread = Null
  94.                 _Close()
  95.                
  96.                 print "captured: " + capturedDataFrames + " frames."
  97.  
  98.                 Return True
  99.         End Method
  100.        
  101.        
  102.         'returns a window (static memory) to the captured data
  103.         Method GetCapturedDataWindow:TBank()
  104.                 if not capturedData then return Null
  105.                 Return capturedData.Window(0, capturedDataFrames)
  106.         End Method
  107.  
  108.  
  109.         'creates a new bank containing only the valid record data
  110.         Method GetCapturedData:TBank()
  111.                 if not capturedData then return new TBank()
  112.                 Local result:TBank = CreateBank(capturedDataFrames)
  113.                 ?bmxng
  114.                 CopyBank(capturedData, 0:Size_T, result, 0:Size_T, Size_T(capturedDataFrames))
  115.                 ?not bmxng
  116.                 CopyBank(capturedData, 0, result, 0, capturedDataFrames)
  117.                 ?
  118.                 return result
  119.         End Method
  120.        
  121.        
  122.         Method OnCaptureData(data:TBank, capturedFrames:Int)
  123.                 'print "OnCaptureData: could read " + capturedFrames +" captured frames."
  124.                 if not capturedData then capturedData = CreateBank(4096)
  125.                
  126.                 if capturedData.Size() < capturedDataFrames + capturedFrames
  127.                         'plus some space to avoid resizing it over and over
  128.                         capturedData.Resize(capturedDataFrames + capturedFrames + 4096)
  129.                 endif
  130.                
  131.                 capturedDataFrames :+ capturedFrames
  132.         End Method
  133.  
  134.  
  135.         Function RunCaptureThread:object( data:object )
  136.                 local openALCapture:TOpenALCapture = TOpenALCapture(data)
  137.  
  138.                 alcCaptureStart(openALCapture.device)
  139.                
  140.  
  141.                 Local availableFrames:Int
  142.                 Local bank:TBank = CreateBank(4096)
  143.                 Repeat
  144.                         'how much is available to fetch?
  145.                         alcGetIntegerv(openALCapture.device, ALC_CAPTURE_SAMPLES, 1, Varptr availableFrames)
  146.  
  147.                         if availableFrames > 0
  148.                                 'print "Capture size: " + availableFrames
  149.                                 if bank.Size() < availableFrames * 1 '* 2 if stereo
  150.                                         bank.Resize(availableFrames * 1 + 1024) 'with a little space on top
  151.                                 endif
  152.                                 alcCaptureSamples(openALCapture.device, bank.Lock(), availableFrames)
  153.                                 bank.Unlock()
  154.                                
  155.                                 openALCapture.OnCaptureData(bank, availableFrames)
  156.                         endif
  157.  
  158.                         delay(10) 'sleep a bit
  159.  
  160.                         'received command to exit the thread
  161.                         if openALCapture.captureThreadExit then exit
  162.                 Forever
  163.  
  164.                 alcCaptureStop(openALCapture.device)
  165.  
  166.                 openALCapture.captureRunning = False
  167.         End Function
  168.  
  169.  
  170.         Method _Close()
  171.                 If context Then alcDestroyContext(context)
  172.                 'dunno, still get an "AL lib: (EE) alc_cleanup: 1 device not closed"
  173.                 If device Then alcCloseDevice(device)
  174.         End Method
  175.        
  176.        
  177.         Method Delete()
  178.                 _Close()
  179.         End Method
  180.  
  181.  
  182.         Function GetDefaultDevice:String()
  183.                 Return String.FromCString( alcGetString(Null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER) )
  184.         End Function
  185.  
  186.  
  187.         Function EnumDevices:String[]()
  188.                 Local p:Byte Ptr = alcGetString(Null,ALC_CAPTURE_DEVICE_SPECIFIER )
  189.                 If Not p Return Null
  190.  
  191.                 Local devices:String[100]
  192.                 Local n:Int
  193.                 While p[0] And n<100
  194.                         Local sz:Int
  195.                         Repeat
  196.                                 sz:+1
  197.                         Until Not p[sz]
  198.  
  199.                         devices[n] = String.FromBytes(p, sz)
  200.  
  201.                         n :+ 1
  202.                         p :+ sz + 1
  203.                 Wend
  204.                 Return devices[.. n]
  205.         End Function
  206. End Type
  207.  


What it does is recording (here for ... 1 second) and saving it to a "record.dat" file.

I assume one might also load that into a TSound to play it back or so.

Using threads allows to process other stuff in your app without being blocked by the capture / data processing in the capture.


bye
Ron

Online Hardcoal

Re: Open AL Issue
« Reply #14 on: February 11, 2021, 05:41:47 PM »
your example produced this error

Compile Error: Expression of type '<unknown>' cannot be invoked

when it reached this code line

local openALCapture:TOpenALCapture = new TOpenALCapture( TOpenALCapture.GetDefaultDevice() )

also i had to copy the 'Type TThread' Type from brl.mod threads.mod file.. because it didnt find this type for some reason..

although ive built the mod
hmmmm

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal