Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Our callback function with all stream data
- void TutorialApplication :: visualize(int chan,int* stream,int len) {
- fftw_complex *in, *out;
- fftw_plan p;
- int N = 512;
- if(len<N) {
- return;
- }
- int cut = len / 512;
- SDL_LockMutex(m_mtx);
- in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
- long long int y;
- for(int i=0;i<N;i+=cut) {
- if( (cut%2 == 0) || (i==0) ) {
- y = stream[i] * stream[i+1];
- in[i][0] = y * (1.0/65536) ;
- in[i][1] = 0;
- }
- else {
- y = stream[i-1] * stream[i];
- in[i][0] = y * (1.0/65536);
- in[i][1] = 0;
- }
- }
- SDL_UnlockMutex(m_mtx);
- out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
- p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
- fftw_execute(p);
- SDL_LockMutex(m_mtx);
- std::cout << "\n\n";
- std::cout << len << " " << cut <<"\n";
- long long int temp;
- long double result;
- for(int i=0;i<N;i++) {
- temp = out[i][0]*out[i][0] + out[i][1]*out[i][1];
- result = sqrt(temp)*(1.0/65536);
- //std::cout << out[i][0] <<"+"<<out[i][1] << "*i ;";
- std::cout << i << ":" << result << "\n";
- }
- std::cout << "\n" << "\n";
- SDL_UnlockMutex(m_mtx);
- fftw_destroy_plan(p);
- fftw_free(in);
- fftw_free(out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement