Ive downloaded the IDE recently, Ive tried many AudioStream. Initialize parameters but none work. Can anyone help? Ive tried AudioStream.Initialize("AudioStream") & AudioStream.Initialize() & AudioStream.Initialize. ChatGpt gave up the ghost. Java, Audio & AudioRecord are checked in the library. Something Im missing, Im trying to show sound levels from a microphone.
Sub Process_Globals
Dim AudioStream As AudioStreamer
Dim Buffer(2048) As Byte ' Buffer size for audio data
End Sub
Sub Globals
Private Timer1 As Timer
Private lblVolume As Label ' Label to display sound levels
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main") ' Load layout with lblVolume
'If FirstTime Then
' Initialize the AudioStreamer
AudioStream.Initialize'(AudioStream) '(AudioStream) ' Event handler name
AudioStream.SampleRate = 44100 ' Set sample rate (44.1 kHz)
AudioStream.Mono = True ' Use mono audio
AudioStream.StartRecording ' Start recording audio
'End If
' Set up a timer to process the audio data at regular intervals
Timer1.Initialize("Timer1", 200) ' Every 200ms
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
' Read audio data into buffer
Dim ReadBytes As Int = AudioStream.Read(Buffer, 0, Buffer.Length)
If ReadBytes > 0 Then
Dim Sum As Long = 0
' Process the audio buffer (taking every two bytes as a sample)
For i = 0 To ReadBytes - 1 Step 2
Dim Sample As Short = Bit.Or(Bit.And(0xff, Buffer(i)), Bit.ShiftLeft(Bit.And(0xff, Buffer(i + 1)), 8))
Sum = Sum + Abs(Sample) ' Accumulate absolute values of the samples
Next
' Calculate the amplitude (average absolute value of the samples)
Dim Amplitude As Float = Sum / ReadBytes
' Calculate decibels (20 * log10(Amplitude))
Dim Decibels As Float = 20 * (Log(Amplitude) / Log(10))
' Display the decibel value on the label
lblVolume.Text = "Volume: " & NumberFormat2(Decibels, 1, 2, 2, False) & " dB"
End If
End Sub
Sub Process_Globals
Dim AudioStream As AudioStreamer
Dim Buffer(2048) As Byte ' Buffer size for audio data
End Sub
Sub Globals
Private Timer1 As Timer
Private lblVolume As Label ' Label to display sound levels
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main") ' Load layout with lblVolume
'If FirstTime Then
' Initialize the AudioStreamer
AudioStream.Initialize'(AudioStream) '(AudioStream) ' Event handler name
AudioStream.SampleRate = 44100 ' Set sample rate (44.1 kHz)
AudioStream.Mono = True ' Use mono audio
AudioStream.StartRecording ' Start recording audio
'End If
' Set up a timer to process the audio data at regular intervals
Timer1.Initialize("Timer1", 200) ' Every 200ms
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
' Read audio data into buffer
Dim ReadBytes As Int = AudioStream.Read(Buffer, 0, Buffer.Length)
If ReadBytes > 0 Then
Dim Sum As Long = 0
' Process the audio buffer (taking every two bytes as a sample)
For i = 0 To ReadBytes - 1 Step 2
Dim Sample As Short = Bit.Or(Bit.And(0xff, Buffer(i)), Bit.ShiftLeft(Bit.And(0xff, Buffer(i + 1)), 8))
Sum = Sum + Abs(Sample) ' Accumulate absolute values of the samples
Next
' Calculate the amplitude (average absolute value of the samples)
Dim Amplitude As Float = Sum / ReadBytes
' Calculate decibels (20 * log10(Amplitude))
Dim Decibels As Float = 20 * (Log(Amplitude) / Log(10))
' Display the decibel value on the label
lblVolume.Text = "Volume: " & NumberFormat2(Decibels, 1, 2, 2, False) & " dB"
End If
End Sub
Last edited: