android - FFT audio input -
i want apply fft on signal recorded audiorecorder , saved wav file. fft using has complex[] input parameter. confused, there difference between converting bytes comlex dividing 32768, , converting adding 0 imaginary part , leaving real part byte?
edit:
public complex[] converttocomplex(byte[] file) { int size= file.length; double[]x=new double[size]; complex[]data= new complex[size]; for(int i=0;i<size;i++) { x[i]=file[i]/32768.0; data[i]=new complex(x[i],0); // log.d("tag", "indice"+i+":"+data[i]); } homecoming data; }
if working sound bit depth of 16 bits (each sample has 16 bits), each byte have half of sample.what need cast bytes 16 bit samples split resulting number 32768 (this magnitude of smallest number 2's complement 16 bit number can store i.e 2^15) actual sound sample number between -1 , 1.you convert number complex number setting it's imaginary component 0.
a little c# sample can seen below (indicative code):
byte[] myaudiobytes = readaudio(); int numbytes = myaudiobytes.length; var myaudiosamples = list<short>(); for( int = 0; < numbytes; = + 2) { //cast 16 bit sound , add together sample short sample = (short) ((myaudiobytes[i] << 8 | myaudiobytes[i + 1]) / 32768 ); myaudiosamples.add(sample); } //change real sound complex sound complex[] complexaudio = new complex[myaudiosamples.length]; int = 0; foreach(short sample in myaudiosamples) complexaudio[i++] = new complex(){ real = sample, imaginary = 0 }; //now can proceed getting fft of sound here hope code has guided on how should handle audio.
android audio fft
No comments:
Post a Comment