#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private streamer As AudioStreamer
Private buffers As List
Private timer1 As Timer
Private recordingStart As Long
Private j As Int
Private s As Int
Private t As Int
Private z As Byte
End Sub
Sub Globals
Dim Label1 As Label
Dim btnPlay As Button
Dim btnStartRecording As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
If FirstTime Then
streamer.Initialize("streamer", 44100, True, 16, streamer.VOLUME_MUSIC)
buffers.Initialize
timer1.Initialize("timer1", 1000)
End If
End Sub
Sub streamer_RecordBuffer (Buffer() As Byte)
'collect the recording data
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Dim j As Int
' j = Buffer.Length/2
' Dim intbuffer() As Short
' 'Conv.LittleEndian = True
' 'intbuffer = Conv.ShortsFromBytes(Buffer)
'
' For i = 0 To j - 1
' buffers.Add(intbuffer(i))
' Next
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
buffers.Add(Buffer)
'buffers.Add(120) '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
End Sub
Sub btnStartRecording_Click
buffers.Clear
streamer.StartRecording
'streamer.StopRecording'&&&&&&&&&&&&
recordingStart = DateTime.Now
timer1.Enabled = True
Timer1_Tick
btnPlay.Enabled = False
End Sub
Sub Timer1_Tick
Label1.Text = "Recording: " & _
Round((DateTime.Now - recordingStart) / DateTime.TicksPerSecond) & " seconds"
End Sub
Sub btnStopRecording_Click
streamer.StopRecording
timer1.Enabled = False
btnPlay.Enabled = True
Label1.Text = ""
End Sub
Sub btnPlay_Click
btnStartRecording.Enabled = False
streamer.StartPlaying
' For Each b() As Byte In buffers 'REMOVED&&&&&&&&&&&&&
For i = 0 To buffers.Size - 1
'Dim b2() As Byte = buffers.Get(i)
Dim b2() As Byte = Type(200)
'streamer.Write(b) '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
streamer.Write(b2) '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Next
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' For i = 0 To buffers.Size - 1
' Dim b2() As Byte = buffers.Get(i)
' 'Log("b2.Length = " & b2.Length)
' streamer.Write(b2)
' Next
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' For z = 0 To 100 Step 4 '&&^^^^^^^^^^^^^^^^^^^^^^^
' 'For Each b() As Byte In buffers
' 'streamer.Write(b)
' Log(b(z))
' Log(b(z+1))
' Log(b(z)+256*b(z+1))
' Log(" ")
' Next
'To convert the byte buffer To signed ints Do something like this (For 16 Bit):'
'j = b.Length / 2
'For i = 0 To 9
' s = Bit.And ( b( 2 * i ), 255)
' t = Bit.And ( b( 2 * i + 1), 255)
' Log( s + Bit.ShiftLeft(t, 8) + Bit.And(t,128) * -512 )
'Next
' Dim buf() As List
' buf.add(0)
' buf.add(200)
' For s = 0 To 10000
' For t = 0 To 10000
' streamer.Write(buf(0)) 'Left LSB
' streamer.Write(buf(1)) 'Left MSB
' streamer.Write(buf(0)) 'Right LSB
' streamer.Write(buf(0)) 'Right MSB
' Next
'
' For t = 0 To 10000
' streamer.Write(buf(0)) 'Left LSB
' streamer.Write(buf(0)) 'Left MSB
' streamer.Write(buf(0)) 'Right LSB
' streamer.Write(buf(0)) 'Right MSB
' Next
'
' Next
streamer.Write(Null) 'when this "message" will be processed, the player will stop.
End Sub
Sub streamer_PlaybackComplete
Log("PlaybackComplete")
btnStartRecording.Enabled = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub