Guest User

Untitled

a guest
Jan 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public boolean isBlowing()
  2. {
  3. boolean recorder=true;
  4.  
  5. int minSize = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
  6. AudioRecord ar = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,minSize);
  7.  
  8.  
  9. short[] buffer = new short[minSize];
  10.  
  11. ar.startRecording();
  12. while(recorder)
  13. {
  14.  
  15. ar.read(buffer, 0, minSize);
  16. for (short s : buffer)
  17. {
  18. if (Math.abs(s) > 27000) //DETECT VOLUME (IF I BLOW IN THE MIC)
  19. {
  20. blow_value=Math.abs(s);
  21. System.out.println("Blow Value="+blow_value);
  22. ar.stop();
  23. recorder=false;
  24.  
  25. return true;
  26.  
  27. }
  28.  
  29. }
  30. }
  31. return false;
  32.  
  33. }
Add Comment
Please, Sign In to add comment