Libraryless. Click here for Pure Java version (57L/1K/2K).
!636 !quicknew import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; main { psvm { new SoundMeter sm; sm.start(); for (int i = 0; i < 20; i ++) { Thread.sleep(500); System.out.println(sm.getAmplitude()); } sm.stop(); } } class SoundMeter { private AudioRecord ar = null; private int minSize; public void start() { minSize= AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); ar = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT,minSize); ar.startRecording(); } public void stop() { if (ar != null) { ar.stop(); } } public double getAmplitude() { short[] buffer = new short[minSize]; ar.read(buffer, 0, minSize); int max = 0; for (short s : buffer) { if (Math.abs(s) > max) { max = Math.abs(s); } } return max; } }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, exkalrxbqyxc, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000439 |
Snippet name: | Sound meter |
Eternal ID of this version: | #1000439/1 |
Text MD5: | 9e5b0659ec3fdad2dca4fbb77bf10fe5 |
Transpilation MD5: | 2d4c0c56aaa8d69d31936c0b0ab089ef |
Author: | stefan |
Category: | javax android |
Type: | JavaX source code (Android) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-06 03:25:05 |
Source code size: | 1154 bytes / 51 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 577 / 537 |
Referenced in: | #1000440 - Graphical sound meter #3000190 - Answer for stefanreich(>> t 20 questions) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |