Related links:
Android calls built-in recording audioProgram
Http://www.eoeandroid.com/thread-78949-1-1.html
Mediarecoder enables audio recording and playing
Http://www.eoeandroid.com/thread-237311-1-1.html
Android audio Introduction
Http://www.eoeandroid.com/thread-68377-1-1.html
-------------- Post body ----------------
Let's take a look at it first:
Public Class Fftactivity Extends Activity Implements Onclicklistener { Private Button button; Private Imageview; Private Int Frequency = 8000 ; Private Int Channelconfiguration = Audioformat. channel_configuration_mono; Private Int Audioencoding = Audioformat. encoding_pcm_16bit; Private Realdoublefft transformer; Private Int Blocksize = 256 ; Private Boolean Started = False ; Private Canvas canvas; Private Paint paint; Private Bitmap bitmap; @ override Protected Void Oncreate (bundle savedinstancestate ){ Super . Oncreate (savedinstancestate); setcontentview (R. layout. FFT); button = (Button) findviewbyid (R. Id. fft_button); button. setonclicklistener ( This ); Imageview = (Imageview) findviewbyid (R. Id. fft_imageview); Transformer = New Realdoublefft (blocksize); bitmap = Bitmap. createbitmap (256,100, Bitmap. config. argb_8888); canvas = New Canvas (Bitmap); Paint = New Paint (); paint. setcolor (color. Green); imageview. setimagebitmap (Bitmap );} Private Class Recordaudio Extends Asynctask <void, Double [], Void> {@ Override Protected Void doinbackground (void... Params ){ Int Buffersize = Audiorecord. getminbuffersize (frequency, channelconfiguration, audioencoding); audiorecord = New Audiorecord (mediarecorder. audiosource. Mic, frequency, channelconfiguration, audioencoding, buffersize ); Short [] Buffer = New Short [Blocksize]; Double [] Totransform = New Double [Blocksize]; audiorecord. startrecording (); While (Started ){ // Read the record data to the buffer, but I think it may be more appropriate to write the data. Int Bufferresult = audiorecord. Read (buffer, 0 , Blocksize ); For (Int I = 0; I <bufferresult; I ++ ) {Totransform <I> = ( Double ) Buffer <I>/ Short. max_value;} transformer. ft (totransform); publishprogress (totransform);} audiorecord. Stop (); Return Null ;} @ Override Protected Void Onprogressupdate ( Double []... Values ){ Super . Onprogressupdate (values); canvas. drawcolor (color. Black ); For ( Int I = 0; I <values [0]. length; I ++ ){ Int X = I; Int Downy = ( Int ) (100-(Values [0] <I>) * 10); Int Upy = 100. ; Canvas. drawline (x, downy, X, upy, paint);} imageview. invalidate () ;}@ override Public Void Onclick (view v) {started = True ; New Recordaudio(.exe cute ();}}
Android audio visualization uses discrete Fourier transform, but do not worry about poor mathematics. There are open-source Java Discrete Fourier TransformCode!! Go to www.netlib.org/fftpack/jfftpack.tgzand drag the internal ourcedirectory to the src directory !!