Im trying to record audio if there is noise at the environment and not recording when there is no noise
at first my code works great when i try to detect noise
the problem occurs when i try to record the noise:
Any ideas ?
at first my code works great when i try to detect noise
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Timer1.Initialize("Timer1",1000)
Ar.Initialize()
pws.KeepAlive(False)
Timer1.Enabled = True
End Sub
Sub Activity_Resume
Timer1.Enabled = True
Ar.AudioSource = Ar.AS_MIC
Ar.OutputFormat = Ar.OF_THREE_GPP
Ar.AudioEncoder = Ar.AE_AMR_NB
Ar.setOutputFile("","/dev/null")
Ar.prepare
Ar.start
End Sub
Sub Timer1_Tick
x = x + 1
level = Ar.AudioMaxAmplitude
avglevel = avglevel + level
avg = avglevel / x 'like doing arithmetic mean...
avrg.Text = NumberFormat(avg,1,0)
labVU.Text = NumberFormat(level,1,0)
If level > avg + (avg /10) Then
ImageView1.Visible = True
Else
ImageView1.Visible = False
End If
End Sub
the problem occurs when i try to record the noise:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Timer1.Initialize("Timer1",1000)
Ar.Initialize()
pws.KeepAlive(False)
Timer1.Enabled = True
End Sub
Sub Activity_Resume
Timer1.Enabled = True
Ar.AudioSource = Ar.AS_MIC
Ar.OutputFormat = Ar.OF_THREE_GPP
Ar.AudioEncoder = Ar.AE_AMR_NB
Ar.setOutputFile("","/dev/null")
Ar.prepare
Ar.start
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Timer1.Enabled = False
Ar.stop
End Sub
Sub Timer1_Tick
x = x + 1
level = Ar.AudioMaxAmplitude
avglevel = avglevel + level
avg = avglevel / x 'like doing arithmetic mean...
avrg.Text = NumberFormat(avg,1,0)
labVU.Text = NumberFormat(level,1,0)
If level > avg + (avg /10) Then
ImageView1.Visible = True
Ar.setOutputFile(File.DirRootExternal,"mr-rec.mp3")
Ar.prepare
Ar.start
Else
ImageView1.Visible = False
Ar.setOutputFile("","/dev/null")
Ar.prepare
Ar.start
End If
'Log(level)
End Sub
Any ideas ?