歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 基於Android的實時音頻頻譜儀

基於Android的實時音頻頻譜儀

日期:2017/3/1 10:39:06   编辑:Linux編程

前一段實習,本來打算做c++,到了公司發現沒啥項目,於是乎轉行做了Android,寫的第一個程序竟然要我處理信號,咱可是一心搞計算機的,沒接觸過信號的東西,什麼都沒接觸過,於是乎, 找各種朋友,各種熟人,現在想想,專注語言是不對的,語言就是一工具,關鍵還是業務,算法。好了,廢話不多說,上程序,注釋都很詳細,應該能看懂。

分析聲音,其實很簡單,就是運用傅裡葉變換,將聲音信號由時域轉化到頻域(程序用的是快速傅裡葉變換,比較簡單),為啥要這樣,好處多多,不細講,公司裡的用處是為了檢測手機發出聲音的信號所在的頻率集中范圍。

基於Android的實時音頻頻譜儀源碼下載地址:

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.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. public Complex() {
  8. // TODO Auto-generated constructor stub
  9. this.real = 0;
  10. this.image = 0;
  11. }
  12. public Complex(double real, double image){
  13. this.real = real;
  14. this.image = image;
  15. }
  16. public Complex(int real, int image) {
  17. Integer integer = real;
  18. this.real = integer.floatValue();
  19. integer = image;
  20. this.image = integer.floatValue();
  21. }
  22. public Complex(double real) {
  23. this.real = real;
  24. this.image = 0;
  25. }
  26. //乘法
  27. public Complex cc(Complex complex) {
  28. Complex tmpComplex = new Complex();
  29. tmpComplex.real = this.real * complex.real - this.image * complex.image;
  30. tmpComplex.image = this.real * complex.image + this.image * complex.real;
  31. return tmpComplex;
  32. }
  33. //加法
  34. public Complex sum(Complex complex) {
  35. Complex tmpComplex = new Complex();
  36. tmpComplex.real = this.real + complex.real;
  37. tmpComplex.image = this.image + complex.image;
  38. return tmpComplex;
  39. }
  40. //減法
  41. public Complex cut(Complex complex) {
  42. Complex tmpComplex = new Complex();
  43. tmpComplex.real = this.real - complex.real;
  44. tmpComplex.image = this.image - complex.image;
  45. return tmpComplex;
  46. }
  47. //獲得一個復數的值
  48. public int getIntValue(){
  49. int ret = 0;
  50. ret = (int) Math.round(Math.sqrt(this.real*this.real - this.image*this.image));
  51. return ret;
  52. }
  53. }
Copyright © Linux教程網 All Rights Reserved