audio - A simple Real-Time Mic Meter in Android -


i have helped book pro android media...

here code:

public class micmeter extends activity implements onclicklistener {   recordaudio recordtask; int blocksize = 256; int frequency = 8000; int channelconfig = audioformat.channel_configuration_mono; int audioencoding = audioformat.encoding_pcm_16bit; textview txt; button start; boolean started = false;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_mic_meter);     start = (button)findviewbyid(r.id.button1);     txt = (textview)findviewbyid(r.id.textview1);      start.setonclicklistener(this);   }   private class recordaudio extends asynctask <void,double[],void>{      @override     protected void doinbackground(void... params) {         try{         int buffersize = audiorecord.getminbuffersize(frequency,channelconfig,audioencoding);         audiorecord audiorecord = new audiorecord( mediarecorder.audiosource.mic, frequency, channelconfig, audioencoding, buffersize);          short[] buffer = new short[blocksize];         double[] meter = new double[blocksize];          audiorecord.startrecording();          while(started){             int bufferreadresult = audiorecord.read(buffer, 0, blocksize);              (int = 0; < blocksize && < bufferreadresult; i++) {                  meter[i] = (double) buffer[i] / 32768.0; // signed 16 bit             }             publishprogress(meter);         }         audiorecord.stop();      }catch (throwable t) {         log.e("audiorecord","recordingfail");     }          return null;     }      @override     protected void onprogressupdate(double[]... meter) {          for(int = 0 ; < meter[0].length ; i++){             double[] helper = meter[i];             txt.settext(double.tostring(helper));         }      }   }   @override public void onclick(view v) {     // todo auto-generated method stub      if(started){         recordtask.cancel(true);     }else{         started = true;         recordtask = new recordaudio();         recordtask.execute();      } } 

}

while press button. shows 255.0 , doesn't response... there way fix it?? there beter version this?

thank

for(int = 0 ; < meter[0].length ; i++){     double helper = i;     txt.settext(double.tostring(helper)); 

settext overwrites old value. last call show. last call sets helper, meter[0].length. since that's fixed number, won't change.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -