Android audio Visualization

Source: Internet
Author: User

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 !!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.