基于Android的实时音频频谱仪


前一段实习,本来打算做c++,到了公司发现没啥项目,于是乎转行做了Android,写的第一个程序竟然要我处理信号,咱可是一心搞计算机的,没接触过信号的东西,什么都没接触过,于是乎, 找各种朋友,各种熟人,现在想想,专注语言是不对的,语言就是一工具,关键还是业务,算法。好了,废话不多说,上程序,注释都很详细,应该能看懂。

分析声音,其实很简单,就是运用傅里叶变换,将声音信号由时域转化到频域(程序用的是快速傅里叶变换,比较简单),为啥要这样,好处多多,不细讲,公司里的用处是为了检测手机发出声音的信号所在的频率集中范围。

基于Android的实时音频频谱仪源码下载地址:

免费下载地址在 http://linux.bkjia.com/

用户名与密码都是www.bkjia.com

具体下载目录在 /2012年资料/1月/17/基于Android的实时音频频谱仪/

第一个类,复数的计算,用到加减乘,很简单。

  1. package com.mobao360.sunshine;  
  2. //复数的加减乘运算  
  3. public class Complex {  
  4.     public double real;  
  5.     public double image;  
  6.       
  7.     //三个构造函数  
  8.     public Complex() {  
  9.         // TODO Auto-generated constructor stub  
  10.         this.real = 0;  
  11.         this.image = 0;  
  12.     }  
  13.   
  14.     public Complex(double real, double image){  
  15.         this.real = real;  
  16.         this.image = image;  
  17.     }  
  18.       
  19.     public Complex(int real, int image) {  
  20.         Integer integer = real;  
  21.         this.real = integer.floatValue();  
  22.         integer = image;  
  23.         this.image = integer.floatValue();  
  24.     }  
  25.       
  26.     public Complex(double real) {  
  27.         this.real = real;  
  28.         this.image = 0;  
  29.     }  
  30.     //乘法  
  31.     public Complex cc(Complex complex) {  
  32.         Complex tmpComplex = new Complex();  
  33.         tmpComplex.real = this.real * complex.real - this.image * complex.image;  
  34.         tmpComplex.image = this.real * complex.image + this.image * complex.real;  
  35.         return tmpComplex;  
  36.     }  
  37.     //加法  
  38.     public Complex sum(Complex complex) {  
  39.         Complex tmpComplex = new Complex();  
  40.         tmpComplex.real = this.real + complex.real;  
  41.         tmpComplex.image = this.image + complex.image;  
  42.         return tmpComplex;  
  43.     }  
  44.     //减法  
  45.     public Complex cut(Complex complex) {  
  46.         Complex tmpComplex = new Complex();  
  47.         tmpComplex.real = this.real - complex.real;  
  48.         tmpComplex.image = this.image - complex.image;  
  49.         return tmpComplex;  
  50.     }  
  51.     //获得一个复数的值  
  52.     public int getIntValue(){  
  53.         int ret = 0;  
  54.         ret = (int) Math.round(Math.sqrt(this.real*this.real - this.image*this.image));  
  55.         return ret;  
  56.     }  
  57. }  
  • 1
  • 2
  • 3
  • 下一页

相关内容