!636 !quicknew !standard functions import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.app.Activity; import android.widget.*; import android.graphics.*; import android.content.*; // Intent etc. 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; } } main { static double gain=5.0; static Object androidContext; psvm { new SoundMeter sm; sm.start(); goToHomeScreen (); double highest = 1.0; for (int i = 0; i < 10000; i ++) { double amp = sm.getAmplitude(); highest = Math.max(highest, amp); int col = (int) Math.min(255, Math.floor(amp/highest*gain*255)); setWidgetColor(col); } sm.stop(); } }