Skip to content

Commit

Permalink
Use multiple channels
Browse files Browse the repository at this point in the history
The API uses per-channel dimensions.
  • Loading branch information
lu-zero committed May 12, 2022
1 parent d5338f6 commit 1696c3a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions libspeexdsp/testresample2.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,29 @@
#define INBLOCK 1024
#define RATE 48000

int main()
int main(int argc, char **argv)
{
spx_uint32_t i;
float *fin, *fout;
int rate = 1000, off = 0, avail = INBLOCK;
SpeexResamplerState *st = speex_resampler_init(1, RATE, RATE, 4, NULL);
spx_uint32_t i, j;
float *fin, *fout, val;
int rate = 1000, off = 0, avail = INBLOCK, channels = 1;

if (argc > 1) {
channels = atoi(argv[1]);
}

SpeexResamplerState *st = speex_resampler_init(channels, RATE, RATE, 4, NULL);
speex_resampler_set_rate(st, RATE, rate);
speex_resampler_skip_zeros(st);

fin = malloc(INBLOCK*2*sizeof(float));
for (i=0; i<INBLOCK*2;i++)
fin[i] = sinf ((float)i/PERIOD * 2 * M_PI) * 0.9;
fin = malloc(INBLOCK*2*sizeof(float)*channels);
for (i=0; i<INBLOCK*2*channels;i+=channels) {
val = sinf ((float)i/PERIOD * 2 * M_PI) * 0.9;
for (j=0; j<channels; j++) {
fin[i+j] = val;
}
}

fout = malloc(INBLOCK*4*sizeof(float));
fout = malloc(INBLOCK*4*sizeof(float)*channels);

while (1)
{
Expand All @@ -68,7 +77,7 @@ int main()

fprintf (stderr, "%d %d %d %d -> ", rate, off, in_len, out_len);

speex_resampler_process_interleaved_float(st, fin + off, &in_len, fout, &out_len);
speex_resampler_process_interleaved_float(st, fin + off * channels, &in_len, fout, &out_len);

fprintf (stderr, "%d %d\n", in_len, out_len);
off += in_len;
Expand All @@ -77,7 +86,7 @@ int main()
if (off >= INBLOCK)
off -= INBLOCK;

fwrite(fout, sizeof(float), out_len, stdout);
fwrite(fout, sizeof(float), out_len * channels, stdout);

rate += 100;
if (rate > 128000)
Expand Down

0 comments on commit 1696c3a

Please sign in to comment.