4343#define INBLOCK 1024
4444#define RATE 48000
4545
46- int main ()
46+ int main (int argc , char * * argv )
4747{
48- spx_uint32_t i ;
49- float * fin , * fout ;
50- int rate = 1000 , off = 0 , avail = INBLOCK ;
51- SpeexResamplerState * st = speex_resampler_init (1 , RATE , RATE , 4 , NULL );
48+ spx_uint32_t i , j ;
49+ float * fin , * fout , val ;
50+ int rate = 1000 , off = 0 , avail = INBLOCK , channels = 1 ;
51+
52+ if (argc > 1 ) {
53+ channels = atoi (argv [1 ]);
54+ }
55+
56+ SpeexResamplerState * st = speex_resampler_init (channels , RATE , RATE , 4 , NULL );
5257 speex_resampler_set_rate (st , RATE , rate );
5358 speex_resampler_skip_zeros (st );
5459
55- fin = malloc (INBLOCK * 2 * sizeof (float ));
56- for (i = 0 ; i < INBLOCK * 2 ;i ++ )
57- fin [i ] = sinf ((float )i /PERIOD * 2 * M_PI ) * 0.9 ;
60+ fin = malloc (INBLOCK * 2 * sizeof (float )* channels );
61+ for (i = 0 ; i < INBLOCK * 2 * channels ;i ++ ) {
62+ val = sinf ((float )i /PERIOD * 2 * M_PI ) * 0.9 ;
63+ for (j = 0 ; j < channels ; j ++ ) {
64+ fin [i * channels + j ] = val ;
65+ }
66+ }
5867
59- fout = malloc (INBLOCK * 4 * sizeof (float ));
68+ fout = malloc (INBLOCK * 4 * sizeof (float )* channels );
6069
6170 while (1 )
6271 {
@@ -68,7 +77,7 @@ int main()
6877
6978 fprintf (stderr , "%d %d %d %d -> " , rate , off , in_len , out_len );
7079
71- speex_resampler_process_interleaved_float (st , fin + off , & in_len , fout , & out_len );
80+ speex_resampler_process_interleaved_float (st , fin + off * channels , & in_len , fout , & out_len );
7281
7382 fprintf (stderr , "%d %d\n" , in_len , out_len );
7483 off += in_len ;
@@ -77,7 +86,7 @@ int main()
7786 if (off >= INBLOCK )
7887 off -= INBLOCK ;
7988
80- fwrite (fout , sizeof (float ), out_len , stdout );
89+ fwrite (fout , sizeof (float ), out_len * channels , stdout );
8190
8291 rate += 100 ;
8392 if (rate > 128000 )
0 commit comments