Hi All,
I know this question comes up now and again and has quite a bit of discussion but, for me never really gets a definite answer. So my apologies for asking this again - Is there a proper method of checking the mic sound input level? I have the following code that I've put together from examples in various post.
If this gets the thumbs-up then I'm going to use it in my app.
Thanks
I know this question comes up now and again and has quite a bit of discussion but, for me never really gets a definite answer. So my apologies for asking this again - Is there a proper method of checking the mic sound input level? I have the following code that I've put together from examples in various post.
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim tm As Timer
Dim ar As AudioRecorder
Dim pb As ProgressBar
Dim pnl As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Calls sub AmplitudeCheck every 100 milliseconds
tm.Initialize("AmplitudeCheck",100)
ar.Initialize
'Set up recorder
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
tm.Enabled=True
pnl.Initialize("")
Activity.AddView(pnl,0,25%y,100%x,25%y)
pnl.Color=Colors.DarkGray
pb.Initialize("")
pb.Enabled=False
pnl.AddView(pb,0,50dip,90%x,5dip)
pb.Left = (pnl.Width-pb.Width)/2 'place progress bar in the middle on x
pb.Top = (pnl.Height-pb.Height)/2 'place progress bar in the middle on y
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
tm.Enabled=False
ar.stop
Activity.Finish
End Sub
Sub AmplitudeCheck_tick
Dim Level As Int = 0
Level = ar.AudioMaxAmplitude
pb.Progress = (Level/2700)*100 'convert value to percentage
If pb.Progress>2 Then Log(pb.Progress)
End Sub
If this gets the thumbs-up then I'm going to use it in my app.
Thanks