Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. //Our callback function with all stream data
  2. void TutorialApplication :: visualize(int chan,int* stream,int len) {
  3. fftw_complex *in, *out;
  4. fftw_plan p;
  5. int N = 512;
  6.  
  7. if(len<N) {
  8. return;
  9. }
  10.  
  11. int cut = len / 512;
  12.  
  13. SDL_LockMutex(m_mtx);
  14. in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
  15.  
  16. long long int y;
  17. for(int i=0;i<N;i+=cut) {
  18. if( (cut%2 == 0) || (i==0) ) {
  19. y = stream[i] * stream[i+1];
  20. in[i][0] = y * (1.0/65536) ;
  21. in[i][1] = 0;
  22. }
  23. else {
  24. y = stream[i-1] * stream[i];
  25. in[i][0] = y * (1.0/65536);
  26. in[i][1] = 0;
  27. }
  28. }
  29. SDL_UnlockMutex(m_mtx);
  30.  
  31. out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
  32. p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
  33. fftw_execute(p);
  34.  
  35. SDL_LockMutex(m_mtx);
  36. std::cout << "\n\n";
  37. std::cout << len << " " << cut <<"\n";
  38. long long int temp;
  39. long double result;
  40. for(int i=0;i<N;i++) {
  41. temp = out[i][0]*out[i][0] + out[i][1]*out[i][1];
  42. result = sqrt(temp)*(1.0/65536);
  43. //std::cout << out[i][0] <<"+"<<out[i][1] << "*i ;";
  44. std::cout << i << ":" << result << "\n";
  45. }
  46.  
  47. std::cout << "\n" << "\n";
  48. SDL_UnlockMutex(m_mtx);
  49.  
  50. fftw_destroy_plan(p);
  51. fftw_free(in);
  52. fftw_free(out);
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement