Open AL Issue

Started by Hardcoal, February 01, 2021, 21:04:17

Previous topic - Next topic

Hardcoal

Im recording from an external sound card called Ag06 from yamaha..
all my Microphone and Other sounds passes Through this Sound Card.
im using the savesong function  that was posted here or somewhere in this forum

Method SaveSong()
        Local WavFile$ = RequestFile$("Save as...", "Wav files:wav", True)
        Local SampleSize%, SndBank:TBank, FileStream:TStream
        Local Channels%, BitRate%, BlockAlign%
               
        Channels = 2
        BitRate = 16
        SampleSize = RecordingPointer
        BlockAlign = 4
       
       'create a bank from the loaded sound
        SndBank = CreateStaticBank(MySample.samples, SampleSize)

       'Prevent
If WavFile = "" Then Return

        fileStream = WriteStream(wavFile$)
       
       'write 44-byte wav header info
        fileStream.WriteString("RIFF")                          '"RIFF" file description header (4 bytes)
        fileStream.WriteInt(SampleSize + 40)                    'file size - 8 (4 bytes)
        fileStream.WriteString("WAVE")                          '"WAVE" description header (4 bytes)
        fileStream.WriteString("fmt ")                          '"fmt " description header (4 bytes)
        fileStream.WriteInt(16)                                 'size of WAVE section chunk (4 bytes)
        fileStream.WriteShort(1)                                'WAVE type format (2 bytes)
        fileStream.WriteShort(Channels)                         'mono/stereo (2 bytes)
        fileStream.WriteInt(MySample.hertz)                     'sample rate (4 bytes)
        fileStream.WriteInt(MySample.hertz * BlockAlign)        'avg bytes/sec (4 bytes)
        fileStream.WriteShort(BlockAlign)                       'Block alignment (2 bytes)
        fileStream.WriteShort(BitRate)                          'Bits/sample (2 bytes)
        fileStream.WriteString("data")                          '"data" description header (4 bytes)
        fileStream.WriteInt(SampleSize)                         'size of data chunk (4 bytes)
             
       'write wav sound data
        SndBank.Write(fileStream, 0, sampleSize)
         
       'close the stream
        CloseStream fileStream
End Method


Im wondering , if the sample is stereo, how does it appear in the Sample Bank?
I mean what is the Left Sample and what is the Right Sample Data?
Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]

Midimaster

In 16bit-recording the 2 samples are organized in 4-Byte-Blocks one after the other. At first a  SHORT for left, than a SHORT for right, than a SHORT for left,...an so on. So you need to fetch always 4 bytes to get the corresponding samples.

The YAMAHA AG6 mixer is able to process 24bit. So you need to have a look on the length of the blocks. Such devices can also send 6 Bytes-blocks.

...back from North Pole.

Baggey

Quote from: Baggey on March 14, 2021, 13:59:52
Quote from: Dabz on February 01, 2021, 21:14:20
Do you have OpenAL installed?


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

Hi, ive installed 10-openal and it dosent work with Blitzmax 1.5? I think ive got vanilla as i overwrite the Blitmax 1.5 folders with it!

Is there a guide on how to use or install OpenAL with Blitzmax 1.5? I need something quicker than Tsound as it seems ok with milli sec sounds but not microsecs sounds.

Kind Regards Baggey

Hi, Running the code above, i am now getting no errors
QuoteBuilding untitled1
Compiling:untitled1.bmx
flat assembler  version 1.69.14  (1572863 kilobytes memory)
3 passes, 2446 bytes.
Linking:untitled1.exe
Executing:untitled1.exe

Process complete

Im assuming it's installed now. I think re-booting the PC must have sorted the origonal error i was getting.

Just need to find a decent site with examples so i can use OpenAL  :D

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Hardcoal

hi.. im trying to increase the volume of the sample

this is what i did..
but i got background noises while the volume increases slightly

what am i doing wrong?

(probably everything)

Method IncreaseSampleVolume(Sample:TAudioSample)
Local I, Left:Short, Right:Short
If Sample = Null Then Return
If Sample.length = 0 Then Return
For I = 0 To Sample.length
Left = Sample.samples[I] * 2
Right = Sample.samples[I] Shr 32 * 2
Sample.samples[I] = Left + Right
Next
End Method
Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]

Midimaster

#64
This depends on the Audio-Format you are using....

First the signals for left and right are never combined into one variable. On a typical SF_STEREO16 there is one sample for the left followed by a second sample for the right channel. So you would use SHORTs to write it directly:
For I = 0 To Sample.length Step 4
Left:Short  = Sample.samples[I]+Sample.samples[I+1]*256
Right:Short = Sample.samples[I+2]+Sample.samples[I+3]*256
Next


to increase the volume you are alreay doing the correct way, but...
The type SHORT is unsigned in BlitzMax, but signed in TAudioSample. To calculate the true value you have to transform it into INT:

RealLeft:INT=Left
If RealLeft>32768
     RealLeft=RealLeft-65535
Endif
'now volume:
RealLeft=RealLeft*2
'now back to SHORT
If RealLeft<0
     RealLeft=RealLeft+65535
EndIf
Left=RealLeft
Sample.samples[I] = Left mod 256
Sample.samples[I+1]= Left/256

This doubles the volume and rises +10dB

But you have to care about the limitations. In a SF_STEREO16 the values are allowed to be between -32700 to +32700.

In a 32bit Floating point format the maximum is -1.00 to +1.00 only!!!

In a 8bit format the values are 0 to 255, where 127.5 means 0 and 0 means -127 and 254 means +127

8bit:
Sample.samples[I] = (Sample.samples[I]-127) * 2 + 127

...back from North Pole.

Hardcoal

#65
Sure I get it midimaster.. Im getting the picture.

Ill go experiment  now. Thanks
Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]

Hardcoal

ok, here is the thing..
when im raising the volume for a wave i didnt create it works fine..
but what ive recorded when i raise volume it adds hiss noise..

also im trying to start a sample play from the middle and it aint working either

here is what ive done
Method PlaySample(Sample:TAudioSample)
Local Sound:TSound = LoadSound(Sample)
If Sound = Null Then Notify "Sound not loaded" ; Return - 1
    PlaySound (Sound)
End Method

Method PlaySampleFromMiddle(Sample:TAudioSample)
Local TmpSample:TAudioSample, StartLocation
StartLocation = Sample.length / 2
TmpSample = Sample.copy()
TmpSample.samples = Null
For Local I = 0 To 1023
TmpSample.samples = TmpSample.samples + Sample.samples[I]
Delay(1)
Next
PlaySample(TmpSample)
End Method



this is my sample definitions..
Const SampBuffSize = 1800
Field SamplesBuff:Float[] = New Float[SampBuffSize] 'This number is temp

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

Field Device:Byte Ptr, Context:Byte Ptr
Field CaptureDevice:Byte Ptr

   'For Recording
Field MaxRecordingTime:Int = 60 'Seconds
Field MySample:TAudioSample = CreateAudioSample(44100 * 4 * MaxRecordingTime, 44100, SF_STEREO16LE)
Field RecordingPointer:Int

Field NumAvailableSamples:Int
Const SampelingChunckSize:Float = 1000 'I think its the chunck of the moment sampeling
Field SampleCurrentVolume:Float


cheers
Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]

Midimaster

What do you mean with "play from the middle"?

If you need a part of a TAudioSample as a new sample you have to copy a lot of sample bytes:
source:TAudioSample
target:TAudioSample

For local i=0 to length
   Target.Samples[i]=Source.Samples[distance+i]
Next


This copies a part from one TAudioSample to another


I have updated my post#65 because SF_STEREO16 is more complicate, that I wrote before. See new information to prevent the noise.


...back from North Pole.

Hardcoal

#68
Ok Ive managed to increase volume by doing so..

Method IncreaseSampleVolume(Sample:TAudioSample, Increment:Float = 1.1)
Local Left:Short, Right:Short, I

For I = 0 To Sample.length Step 4

Left = Sample.samples[I] + Sample.samples[I + 1] * 256
Right = Sample.samples[I + 2] + Sample.samples[I + 3] * 256

   'Left
Local RealLeft# = Left
If RealLeft > 32768 Then RealLeft = RealLeft - 65535

   'now volume:
RealLeft = RealLeft * Increment
   'now back to SHORT
    If RealLeft < 0 Then RealLeft = RealLeft + 65535

Left=RealLeft
Sample.samples[I + 2] = Left Mod 256
Sample.samples[I + 3] = Left / 256

   'Right
Local RealRight:Float = Right
If RealRight > 32768 Then RealRight = RealRight - 65535

   'now volume:
RealRight = RealRight * Increment
   'now back to SHORT
    If RealRight < 0 Then RealRight = RealRight + 65535

Right = RealRight
Sample.samples[I + 2] = Right Mod 256
Sample.samples[I + 3] = Right / 256

Next

End Method


but how come the capture volume from the beginning is so crappy low?
I did one volume increase, and on the second one it already added noises..
and it was still low.
maybe i need to generally increase the playsound volume? maybe thats the case?

Lets try and see

Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]

Midimaster

maybe you read it the wrong way? maybe the input is 24 and sending in 24 bit, but you are reading 8bit or 16bit. This means, that you only check the high byte and lost the low byte information. a forgotten low byte information causes small noise.

When you now increase the sample-values by multiplication the noise is rising too. In a real working 24bit recording you should not be able to find any noise in the signal. also when you accidentally recorded with too small level, you are able to raise the volume with f.e. a factor of 32 (50dB) without noticing any noise additional noise. Can you send some sample recording?

You could create a 1 second test.ogg with a square wave and a volume rising from 0 to max. Then play this on a second computer and record the signal with your equipment. now you can check, whether the values in the recording are continously increasing as expected or if the values are "jumping".
...back from North Pole.

Baggey

Quote from: Midimaster on February 11, 2021, 08:12:20
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) Select
If OpenALInstalled()=False
  Notify "OpenAl Driver is missing"
  InstallOpenAl
EndIf
EnableOpenALAudio()

Global Device:Int=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 !"

Global CaptureDevice:Int
alcCaptureStart(CaptureDevice)

Function InitCapture%()
CaptureDevice = alcCaptureOpenDevice(Null, 44100, AL_FORMAT_STEREO16, 44100*5*4);
    If Not(CaptureDevice) Then Return False
Return True
EndFunction

Function InstallOpenAl()
system_ "oalinst.exe"
Notify("Open AL Installer")
End
End Function


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.

Hi I tried using the code above and get this?

Building untitled1
Compiling:untitled1.bmx
flat assembler  version 1.69.14  (1572863 kilobytes memory)
3 passes, 3331 bytes.
Linking:untitled1.exe
Executing:untitled1.exe
No access to OpenAL capture Device !
Process complete


i have installed OpenAL  :(

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Hardcoal

Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]