diff options
Diffstat (limited to 'gr-vocoder/lib/codec2/c2demo.c')
-rw-r--r-- | gr-vocoder/lib/codec2/c2demo.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/gr-vocoder/lib/codec2/c2demo.c b/gr-vocoder/lib/codec2/c2demo.c index b9e17a78eb..0090069c65 100644 --- a/gr-vocoder/lib/codec2/c2demo.c +++ b/gr-vocoder/lib/codec2/c2demo.c @@ -32,21 +32,26 @@ */ #include "codec2.h" +#include "sine.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> -#define BITS_SIZE ((CODEC2_BITS_PER_FRAME + 7) / 8) - int main(int argc, char *argv[]) { - void *codec2; - FILE *fin; - FILE *fout; - short buf[CODEC2_SAMPLES_PER_FRAME]; - unsigned char bits[BITS_SIZE]; + struct CODEC2 *codec2; + FILE *fin; + FILE *fout; + short *buf; + unsigned char *bits; + int nsam, nbit, i, r; + + for(i=0; i<10; i++) { + r = codec2_rand(); + printf("[%d] r = %d\n", i, r); + } if (argc != 3) { printf("usage: %s InputRawSpeechFile OutputRawSpeechFile\n", argv[0]); @@ -65,18 +70,27 @@ int main(int argc, char *argv[]) exit(1); } + #ifdef DUMP + dump_on("c2demo"); + #endif + /* Note only one set of Codec 2 states is required for an encoder and decoder pair. */ - codec2 = codec2_create(); + codec2 = codec2_create(CODEC2_MODE_1300); + nsam = codec2_samples_per_frame(codec2); + buf = (short*)malloc(nsam*sizeof(short)); + nbit = codec2_bits_per_frame(codec2); + bits = (unsigned char*)malloc(nbit*sizeof(char)); - while(fread(buf, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fin) == - CODEC2_SAMPLES_PER_FRAME) { + while(fread(buf, sizeof(short), nsam, fin) == (size_t)nsam) { codec2_encode(codec2, bits, buf); - codec2_decode(codec2, buf, bits); - fwrite(buf, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fout); + codec2_decode(codec2, buf, bits, 0.0); + fwrite(buf, sizeof(short), nsam, fout); } + free(buf); + free(bits); codec2_destroy(codec2); fclose(fin); |