#Region Project Attributes
#ApplicationLabel: Knock
#VersionCode: 1
#VersionName:
#BridgeLogger: True
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private timer1 As Timer
Private streamer As AudioStreamer
End Sub
Sub Globals
Dim buffers As List
Dim Lbl As Button
Dim btnPlay As Button
Dim btnStartRec As Button
Dim btnStopRec As Button
Private rp As RuntimePermissions
End Sub
Sub Activity_Create(FirstTime As Boolean)
buffers.Initialize
timer1.Initialize("timer1", 1000)
Screen
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Screen
Lbl.Initialize("None")
Lbl.Color=Colors.LightGray
Lbl.Gravity=Gravity.FILL
Lbl.Text="Время"
Activity.AddView(Lbl, 20%x, 31%y, 60%x, 10%y)
btnStartRec.Initialize("StartRec")
btnStartRec.Color=Colors.Gray
btnStartRec.Gravity=Gravity.FILL
btnStartRec.Text="START"
Activity.AddView(btnStartRec, 10%x, 2%y, 30%x, 10%y)
btnStopRec.Initialize("StopRec")
btnStopRec.Color=Colors.Gray
btnStopRec.Gravity=Gravity.FILL
btnStopRec.Text="STOP"
Activity.AddView(btnStopRec, 50%x, 2%y, 30%x, 10%y)
btnPlay.Initialize("Play")
btnPlay.Color=Colors.Gray
btnPlay.Gravity=Gravity.FILL
btnPlay.Text="PLAY"
Activity.AddView(btnPlay, 10%x, 16%y, 30%x, 10%y)
End Sub
Private Sub StartRec_Click
rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
MsgboxAsync("No permission", "")
Return
End If
If streamer.PlayerBufferSize = 0 Then
streamer.Initialize("streamer", 44100, True, 16, streamer.VOLUME_MUSIC)
End If
buffers.Clear
streamer.StartRecording
recordingStart = DateTime.Now
timer1.Enabled = True
Timer1_Tick
btnPlay.Enabled = False
End Sub
Private Sub StopRec_Click
streamer.StopRecording
timer1.Enabled = False
btnPlay.Enabled = True
Lbl.Text = ""
End Sub
Private Sub Play_Click
btnStartRec.Enabled = False
streamer.StartPlaying
For Each b() As Byte In buffers
streamer.Write(b)
Next
streamer.Write(Null)
End Sub
Private Sub streamer_PlaybackComplete
Log("PlaybackComplete")
btnStartRec.Enabled = True
End Sub
Private Sub streamer_RecordBuffer (Buffer() As Byte)
buffers.Add(Buffer)
End Sub
Sub streamer_Error
Log(LastException)
End Sub
Private Sub Timer1_Tick
Dim razmer As Long, v As Int, b As String, db As Float
Log("tick")
razmer=buffers.size
If razmer>22 Then
b=buffers.Get(razmer-1)
v=Bit.ParseInt(b.SubString(4),16)
db=Logarithm(v,10)
Lbl.Text = "Size bufer " & razmer & " Vol: " & db
End If
End Sub