43
43
#define INBLOCK 1024
44
44
#define RATE 48000
45
45
46
- int main ()
46
+ int main (int argc , char * * argv )
47
47
{
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 );
52
57
speex_resampler_set_rate (st , RATE , rate );
53
58
speex_resampler_skip_zeros (st );
54
59
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 ;i ++ ) {
62
+ val = sinf ((float )i /PERIOD * 2 * M_PI ) * 0.9 ;
63
+ for (j = 0 ; j < channels ; j ++ ) {
64
+ fin [i + j ] = val ;
65
+ }
66
+ }
58
67
59
- fout = malloc (INBLOCK * 4 * sizeof (float ));
68
+ fout = malloc (INBLOCK * 4 * sizeof (float )* channels );
60
69
61
70
while (1 )
62
71
{
@@ -68,7 +77,7 @@ int main()
68
77
69
78
fprintf (stderr , "%d %d %d %d -> " , rate , off , in_len , out_len );
70
79
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 );
72
81
73
82
fprintf (stderr , "%d %d\n" , in_len , out_len );
74
83
off += in_len ;
@@ -77,7 +86,7 @@ int main()
77
86
if (off >= INBLOCK )
78
87
off -= INBLOCK ;
79
88
80
- fwrite (fout , sizeof (float ), out_len , stdout );
89
+ fwrite (fout , sizeof (float ), out_len * channels , stdout );
81
90
82
91
rate += 100 ;
83
92
if (rate > 128000 )
0 commit comments