@@ -3170,6 +3170,141 @@ int main(int argc, char *argv[])
31703170 return 0 ;
31713171 }
31723172
3173+ if (!strcmp (argv [1 ],"shift_addition_fc" ))
3174+ {
3175+ bigbufs = 1 ;
3176+
3177+ float starting_phase = 0 ;
3178+ float rate ;
3179+
3180+ int fd ;
3181+ if (fd = init_fifo (argc ,argv ))
3182+ {
3183+ while (!read_fifo_ctl (fd ,"%g\n" ,& rate )) usleep (10000 );
3184+ }
3185+ else
3186+ {
3187+ if (argc <=2 ) return badsyntax ("need required parameter (rate)" );
3188+ sscanf (argv [2 ],"%g" ,& rate );
3189+ }
3190+
3191+ if (!sendbufsize (initialize_buffers ())) return -2 ;
3192+ for (;;)
3193+ {
3194+ shift_addition_data_t data = shift_addition_init (rate );
3195+ fprintf (stderr ,"shift_addition_fc: reinitialized to %g\n" ,rate );
3196+ int remain , current_size ;
3197+ float * ibufptr ;
3198+ float * obufptr ;
3199+ for (;;)
3200+ {
3201+ FEOF_CHECK ;
3202+ if (!FREAD_R ) break ;
3203+ remain = the_bufsize ;
3204+ ibufptr = input_buffer ;
3205+ obufptr = output_buffer ;
3206+ while (remain )
3207+ {
3208+ current_size = (remain > 1024 )?1024 :remain ;
3209+ starting_phase = shift_addition_fc (ibufptr , (complexf * )obufptr , current_size , data , starting_phase );
3210+ ibufptr += current_size ;
3211+ obufptr += current_size * 2 ;
3212+ remain -= current_size ;
3213+ }
3214+ FWRITE_C ;
3215+ if (read_fifo_ctl (fd ,"%g\n" ,& rate )) break ;
3216+ TRY_YIELD ;
3217+ }
3218+ }
3219+ return 0 ;
3220+ }
3221+
3222+ if (!strcmp (argv [1 ],"fft_fc" ))
3223+ {
3224+ /*
3225+ For real FFT, the parameter is the number of output complex bins
3226+ instead of the actual FFT size.
3227+ Number of input samples used for each FFT is twice the given parameter.
3228+ This makes it easier to replace fft_cc by fft_fc in some applications. */
3229+ if (argc <=3 ) return badsyntax ("need required parameters (fft_out_size, out_of_every_n_samples)" );
3230+ int fft_in_size = 0 , fft_out_size = 0 ;
3231+ sscanf (argv [2 ],"%d" ,& fft_out_size );
3232+ if (log2n (fft_out_size )== -1 ) return badsyntax ("fft_out_size should be power of 2" );
3233+ fft_in_size = 2 * fft_out_size ;
3234+ int every_n_samples ;
3235+ sscanf (argv [3 ],"%d" ,& every_n_samples );
3236+ int benchmark = 0 ;
3237+ int octave = 0 ;
3238+ window_t window = WINDOW_DEFAULT ;
3239+ if (argc >=5 )
3240+ {
3241+ window = firdes_get_window_from_string (argv [4 ]);
3242+ }
3243+ if (argc >=6 )
3244+ {
3245+ benchmark |=!strcmp ("--benchmark" ,argv [5 ]);
3246+ octave |=!strcmp ("--octave" ,argv [5 ]);
3247+ }
3248+ if (argc >=7 )
3249+ {
3250+ benchmark |=!strcmp ("--benchmark" ,argv [6 ]);
3251+ octave |=!strcmp ("--octave" ,argv [6 ]);
3252+ }
3253+
3254+ if (!initialize_buffers ()) return -2 ;
3255+ sendbufsize (fft_out_size );
3256+
3257+ //make FFT plan
3258+ float * input = (float * )fft_malloc (sizeof (float )* fft_in_size );
3259+ float * windowed = (float * )fft_malloc (sizeof (float )* fft_in_size );
3260+ complexf * output = (complexf * )fft_malloc (sizeof (complexf )* fft_out_size );
3261+ if (benchmark ) fprintf (stderr ,"fft_cc: benchmarking..." );
3262+ FFT_PLAN_T * plan = make_fft_r2c (fft_in_size , windowed , output , benchmark );
3263+ if (benchmark ) fprintf (stderr ," done\n" );
3264+ //if(octave) printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size); // TODO
3265+ float * windowt ;
3266+ windowt = precalculate_window (fft_in_size , window );
3267+ for (;;)
3268+ {
3269+ FEOF_CHECK ;
3270+ if (every_n_samples > fft_in_size )
3271+ {
3272+ fread (input , sizeof (float ), fft_in_size , stdin );
3273+ //skipping samples before next FFT (but fseek doesn't work for pipes)
3274+ for (int seek_remain = every_n_samples - fft_in_size ;seek_remain > 0 ;seek_remain -= the_bufsize )
3275+ {
3276+ fread (temp_f , sizeof (complexf ), MIN_M (the_bufsize ,seek_remain ), stdin );
3277+ }
3278+ }
3279+ else
3280+ {
3281+ //overlapped FFT
3282+ for (int i = 0 ;i < fft_in_size - every_n_samples ;i ++ ) input [i ]= input [i + every_n_samples ];
3283+ fread (input + fft_in_size - every_n_samples , sizeof (float ), every_n_samples , stdin );
3284+ }
3285+ //apply_window_c(input,windowed,fft_size,window);
3286+ apply_precalculated_window_f (input ,windowed ,fft_in_size ,windowt );
3287+ fft_execute (plan );
3288+ if (octave )
3289+ {
3290+ #if 0
3291+ // TODO
3292+ printf ("fftdata=[" );
3293+ //we have to swap the two parts of the array to get a valid spectrum
3294+ for (int i = fft_size /2 ;i < fft_size ;i ++ ) printf ("(%g)+(%g)*i " ,iof (output ,i ),qof (output ,i ));
3295+ for (int i = 0 ;i < fft_size /2 ;i ++ ) printf ("(%g)+(%g)*i " ,iof (output ,i ),qof (output ,i ));
3296+ printf (
3297+ "];\n"
3298+ "y=abs(fftdata);\n"
3299+ "refreshdata;\n"
3300+ );
3301+ #endif
3302+ }
3303+ else fwrite (output , sizeof (complexf ), fft_out_size , stdout );
3304+ TRY_YIELD ;
3305+ }
3306+ }
3307+
31733308 if (!strcmp (argv [1 ],"none" ))
31743309 {
31753310 return 0 ;
0 commit comments