How to get the amplitude when blowing into MIC on android device -


how amplitude when blowing mic in android device.

mediarecorder recorder = new mediarecorder();    recorder.setaudiosource(mediarecorder.audiosource.mic);     timer timer = new timer();    timer.scheduleatfixedrate(new recordertask(recorder), 0, 1000);  private class recordertask extends timertask { private mediarecorder recorder;  public recordertask(mediarecorder recorder) {     this.recorder = recorder; }  public void run() {     log.v("", "amplitude is" + recorder.getmaxamplitude()); } } 

i getting error:

error/androidruntime(20927): caused by: java.lang.runtimeexception: setaudiosource failed. error/androidruntime(20927): @ android.media.mediarecorder.setaudiosource(native method) 

public boolean isblowing()     {         boolean recorder=true;          int minsize = audiorecord.getminbuffersize(8000,audioformat.channel_configuration_mono, audioformat.encoding_pcm_16bit);         audiorecord ar = new audiorecord(mediarecorder.audiosource.mic, 8000,audioformat.channel_configuration_mono, audioformat.encoding_pcm_16bit,minsize);           short[] buffer = new short[minsize];          ar.startrecording();         while(recorder)         {              ar.read(buffer, 0, minsize);             (short s : buffer)              {                 if (math.abs(s) > 27000)   //detect volume (if blow in mic)                 {                     blow_value=math.abs(s);                     system.out.println("blow value="+blow_value);                     ar.stop();                     recorder=false;                      return true;                  }              }         }         return false;      } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -