@@ -836,6 +836,55 @@ int main(int argc, char *argv[])
836836 return 0 ;
837837 }
838838
839+ if (!strcmp (argv [1 ],"shift_addition_fc" ))
840+ {
841+ bigbufs = 1 ;
842+
843+ float starting_phase = 0 ;
844+ float rate ;
845+
846+ int fd ;
847+ if (fd = init_fifo (argc ,argv ))
848+ {
849+ while (!read_fifo_ctl (fd ,"%g\n" ,& rate )) usleep (10000 );
850+ }
851+ else
852+ {
853+ if (argc <=2 ) return badsyntax ("need required parameter (rate)" );
854+ sscanf (argv [2 ],"%g" ,& rate );
855+ }
856+
857+ if (!sendbufsize (initialize_buffers ())) return -2 ;
858+ for (;;)
859+ {
860+ shift_addition_data_t data = shift_addition_init (rate );
861+ fprintf (stderr ,"shift_addition_fc: reinitialized to %g\n" ,rate );
862+ int remain , current_size ;
863+ float * ibufptr ;
864+ float * obufptr ;
865+ for (;;)
866+ {
867+ FEOF_CHECK ;
868+ if (!FREAD_R ) break ;
869+ remain = the_bufsize ;
870+ ibufptr = input_buffer ;
871+ obufptr = output_buffer ;
872+ while (remain )
873+ {
874+ current_size = (remain > 1024 )?1024 :remain ;
875+ starting_phase = shift_addition_fc (ibufptr , (complexf * )obufptr , current_size , data , starting_phase );
876+ ibufptr += current_size ;
877+ obufptr += current_size * 2 ;
878+ remain -= current_size ;
879+ }
880+ FWRITE_C ;
881+ if (read_fifo_ctl (fd ,"%g\n" ,& rate )) break ;
882+ TRY_YIELD ;
883+ }
884+ }
885+ return 0 ;
886+ }
887+
839888 if (!strcmp (argv [1 ],"shift_addition_cc_test" ))
840889 {
841890 if (argc <=2 ) return badsyntax ("need required parameter (rate)" );
@@ -1495,6 +1544,94 @@ int main(int argc, char *argv[])
14951544 TRY_YIELD ;
14961545 }
14971546 }
1547+
1548+ if (!strcmp (argv [1 ],"fft_fc" ))
1549+ {
1550+ /*
1551+ For real FFT, the parameter is the number of output complex bins
1552+ instead of the actual FFT size.
1553+ Number of input samples used for each FFT is twice the given parameter.
1554+ This makes it easier to replace fft_cc by fft_fc in some applications. */
1555+ if (argc <=3 ) return badsyntax ("need required parameters (fft_out_size, out_of_every_n_samples)" );
1556+ int fft_in_size = 0 , fft_out_size = 0 ;
1557+ sscanf (argv [2 ],"%d" ,& fft_out_size );
1558+ if (log2n (fft_out_size )== -1 ) return badsyntax ("fft_out_size should be power of 2" );
1559+ fft_in_size = 2 * fft_out_size ;
1560+ int every_n_samples ;
1561+ sscanf (argv [3 ],"%d" ,& every_n_samples );
1562+ int benchmark = 0 ;
1563+ int octave = 0 ;
1564+ window_t window = WINDOW_DEFAULT ;
1565+ if (argc >=5 )
1566+ {
1567+ window = firdes_get_window_from_string (argv [4 ]);
1568+ }
1569+ if (argc >=6 )
1570+ {
1571+ benchmark |=!strcmp ("--benchmark" ,argv [5 ]);
1572+ octave |=!strcmp ("--octave" ,argv [5 ]);
1573+ }
1574+ if (argc >=7 )
1575+ {
1576+ benchmark |=!strcmp ("--benchmark" ,argv [6 ]);
1577+ octave |=!strcmp ("--octave" ,argv [6 ]);
1578+ }
1579+
1580+ if (!initialize_buffers ()) return -2 ;
1581+ sendbufsize (fft_out_size );
1582+
1583+ //make FFT plan
1584+ float * input = (float * )fft_malloc (sizeof (float )* fft_in_size );
1585+ float * windowed = (float * )fft_malloc (sizeof (float )* fft_in_size );
1586+ complexf * output = (complexf * )fft_malloc (sizeof (complexf )* fft_out_size );
1587+ if (benchmark ) fprintf (stderr ,"fft_cc: benchmarking..." );
1588+ FFT_PLAN_T * plan = make_fft_r2c (fft_in_size , windowed , output , benchmark );
1589+ if (benchmark ) fprintf (stderr ," done\n" );
1590+ //if(octave) printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size); // TODO
1591+ float * windowt ;
1592+ windowt = precalculate_window (fft_in_size , window );
1593+ for (;;)
1594+ {
1595+ FEOF_CHECK ;
1596+ if (every_n_samples > fft_in_size )
1597+ {
1598+ fread (input , sizeof (float ), fft_in_size , stdin );
1599+ //skipping samples before next FFT (but fseek doesn't work for pipes)
1600+ for (int seek_remain = every_n_samples - fft_in_size ;seek_remain > 0 ;seek_remain -= the_bufsize )
1601+ {
1602+ fread (temp_f , sizeof (complexf ), MIN_M (the_bufsize ,seek_remain ), stdin );
1603+ }
1604+ }
1605+ else
1606+ {
1607+ //overlapped FFT
1608+ for (int i = 0 ;i < fft_in_size - every_n_samples ;i ++ ) input [i ]= input [i + every_n_samples ];
1609+ fread (input + fft_in_size - every_n_samples , sizeof (float ), every_n_samples , stdin );
1610+ }
1611+ //apply_window_c(input,windowed,fft_size,window);
1612+ apply_precalculated_window_f (input ,windowed ,fft_in_size ,windowt );
1613+ fft_execute (plan );
1614+ if (octave )
1615+ {
1616+ #if 0
1617+ // TODO
1618+ printf ("fftdata=[" );
1619+ //we have to swap the two parts of the array to get a valid spectrum
1620+ for (int i = fft_size /2 ;i < fft_size ;i ++ ) printf ("(%g)+(%g)*i " ,iof (output ,i ),qof (output ,i ));
1621+ for (int i = 0 ;i < fft_size /2 ;i ++ ) printf ("(%g)+(%g)*i " ,iof (output ,i ),qof (output ,i ));
1622+ printf (
1623+ "];\n"
1624+ "y=abs(fftdata);\n"
1625+ "refreshdata;\n"
1626+ );
1627+ #endif
1628+ }
1629+ else fwrite (output , sizeof (complexf ), fft_out_size , stdout );
1630+ TRY_YIELD ;
1631+ }
1632+ }
1633+
1634+
14981635 #define LOGPOWERCF_BUFSIZE 64
14991636 if (!strcmp (argv [1 ],"logpower_cf" ))
15001637 {
0 commit comments