March 05, 2021, 07:27:41 PM

Author Topic: Open AL Issue  (Read 469 times)

Offline Derron

Re: Open AL Issue
« Reply #15 on: February 11, 2021, 06:12:52 PM »
I am not "Rontek" - I am GWRon from discord, from github, from gamezworld, from tvtower - and Derron from syntaxbomb ...

My example was written in NG, so yeah you might need to remove the overloaded "method new(..." and also replace your error line with
... = new TOpenALCapture.SetDeviceName( ...)

If it did not find "TThread" then you missed to do a "threaded" build -- NG is threaded by default, vanilla isn't.


Offline Hardcoal

Re: Open AL Issue
« Reply #16 on: February 17, 2021, 05:03:38 AM »
Ok.  problem solved.. thanks to Audicity and MidiMaster

The problem was that there was no permission for micorphone under windows 10 privacy...
Thats all what It was. now everything works..

I still didnt check Line In Recording.. only mic though

Offline Hardcoal

Re: Open AL Issue
« Reply #17 on: March 03, 2021, 04:18:38 PM »
Ok im trying to work with  Vertex OpenAL
but when i delete the framework it complain that the command alcOpenDevice  it says
"Duplicate identifier 'alcOpenDevice' in modules 'pub.openal' and 'vertex.openal'"

i cant work under framework.. and the vertex works for me while other openal mods dont..
what can i do?

*also im trying to use LoadAudioSample() and it reads nothing ... although in the command itself it does open the Stream.
seems like it gets stuck on TAudioSampleLoader inside the loadaudiosample method

Code: [Select]
Const AL_FORMAT_MONO8=$1100
Const AL_FORMAT_MONO16=$1101
Const AL_FORMAT_STEREO16=$1103
end rem


Framework brl.blitz

Import vertex.openal

Import brl.Math    'not neccecary
Import brl.max2d   'not nceccecary
Import brl.glmax2d
Import "float_ring_buffer.bmx"

Graphics(800, 600)


 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)

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

 Const SAMPLE_RATE:Int = 44100,  ..    'In Hertz [Hz]
      BUFFER_SIZE:Int = SAMPLE_RATE 'In Samples

 Global CaptureDevice:Byte Ptr
 CaptureDevice = alcCaptureOpenDevice(Null, SAMPLE_RATE, AL_FORMAT_MONO16, BUFFER_SIZE) 'Null means using default capture device
 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()]


While Not KeyDown(KEY_ESCAPE)
Local NumAvailableSamples:Int

   'Read Samples
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)

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

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


   '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






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

' Null-terminated specifier list

' 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

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


Offline markcwm

Re: Open AL Issue
« Reply #18 on: March 04, 2021, 04:22:47 PM »
You could replace all Import pub.openal with vertex.openal in brl.mod and rebuild modules, it might work.

Offline Hardcoal

Re: Open AL Issue
« Reply #19 on: March 04, 2021, 04:57:32 PM »
ok thanks ill try

Offline Steve Elliott

Re: Open AL Issue
« Reply #20 on: March 04, 2021, 06:16:13 PM »
ok thanks

We need a like button.   ;)
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline Hardcoal

Re: Open AL Issue
« Reply #21 on: March 04, 2021, 07:18:01 PM »
lol you got it steve :)

now.. i have another question.. how do i use windows music instruments ..?
how can i get the list of the default instruments and choose one than.. use it with my virtural keyboard to play?


Offline Midimaster

Re: Open AL Issue
« Reply #22 on: March 04, 2021, 11:45:02 PM »
What do you means with "windows music instruments"? Are you talking about MIDI? Here you would change the sound with a PROGRAM CHANGE COMMAND.

PROGRAM CHANGE is a 2 byte sequence ( in HEX):

$C0 $00 changes Midi instrument on channel 0 to 0 ($00= Piano)
$C1 $13 changes Midi instrument on channel 1 to 19 ($13= Church Organ)

The C says "Programm Change". It is combined with 16 possible channels
$C0 to $CF

The second Byte represents the sound-number. There are 127 possible sounds:
$00 to $7F

table with all 127 sounds:

Afterwards you can play the scale with a 3 byte NOTE ON command:
$90 $40 $70.... plays a middle C on channel 0 with velocity $70 ($40="C")

The 9 says "NOTE ON". It is combined with 16 possible channels
$90 to $9F

$90 $42 $70 plays a middle D on channel 0 ($42="D")
(send velocity 0 to stopp the notes)

The channel 9 is a "special" channel. Here there is no need to "change the sound"

On channel 9 you can play 80 different drum sounds by the NOTE ON command:
$99 $20 $70 plays a bass drum with velocity $70
$99 $22 $70 plays a snare drum
(no need for sending a note off command)
See my current project on PlayStore: 20Tracks-Audio-Player

Offline Hardcoal

Re: Open AL Issue
« Reply #23 on: Today at 04:29:10 AM »
thanks midimaster.. i will experiment with this
but one thing i didnt realized yet about  openal. can you load a sample? and than start playing it from the middle
or get its time length and such things?

if i want to edit sound i obviously need those things

Offline Midimaster

Re: Open AL Issue
« Reply #24 on: Today at 06:59:22 AM »
to load samples and play it from anywhere you do not need openal. You can do this with BlitzMax already.

there is an other thread here in forum,where I demonstrated how to create sounds on the fly and then play it:,8285.msg347048266.html#msg347048266

There you can find this sample, which combines two sinus tones into one audiofile:

Code: [Select]
      Function MakeSinus(Duration:Int, PulseA:Int, PulseB:Int)
                        Local SampleLen:Int= SAMPLERATE*Duration/1000
                        Local FaktorA:Float = 360.0/PulseA
                        Local FaktorB:Float = 360.0/PulseB
                        Local Sample:TAudioSample = CreateAudioSample( SampleLen, SAMPLERATE, SF_MONO8 )
                        For Local n:Int=0 Until SampleLen
                                Local ValueA:Int, ValueB:Int
                                If PulseA=0
                                        ValueA=60* Sin(FaktorA*(n Mod PulseA))
                                If PulseB=0
                                        ValueB=60* Sin(FaktorB*(n Mod PulseB))
                                Sample.samples[n] = 127+ValueA+ValueB
                        Local Audio:TSound = LoadSound( Sample )
                        PlaySound Audio
        End Function

this you can use as a base to manipulate any audio file. TAudioSample is a "Bank" where you can create, combine and manipulate any audio material by writing values in the .Samples[]-Array. At the end you convert it into a TSound.
See my current project on PlayStore: 20Tracks-Audio-Player


SimplePortal 2.3.6 © 2008-2014, SimplePortal