From: drowe67 Date: Fri, 18 Nov 2011 00:39:28 +0000 (+0000) Subject: bunch of changes to support separate enc/dec at 1400. Builds but I haven't tested yet X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=51a78018b41676e4a0240a49e20ddee12887130a;p=freetel-svn-tracking.git bunch of changes to support separate enc/dec at 1400. Builds but I haven't tested yet git-svn-id: https://svn.code.sf.net/p/freetel/code@307 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/pllsp.m b/codec2-dev/octave/pllsp.m index 7602fa3b..15da6748 100644 --- a/codec2-dev/octave/pllsp.m +++ b/codec2-dev/octave/pllsp.m @@ -31,12 +31,12 @@ function pllsp(rawfile, figure(1); clf; - subplot(211); + %subplot(211); sp = s((start_f-2)*80:(end_f-2)*80); plot(sp); - subplot(212); - plot(lpc10_snr((start_f+1):end_f)-lsp_snr((start_f+1):end_f)); + %subplot(212); + %plot(lpc10_snr((start_f+1):end_f)-lsp_snr((start_f+1):end_f)); figure(2); plot((4000/pi)*lsp((start_f+1):end_f,:)); diff --git a/codec2-dev/src/c2dec.c b/codec2-dev/src/c2dec.c index b866d04d..bf3499e4 100644 --- a/codec2-dev/src/c2dec.c +++ b/codec2-dev/src/c2dec.c @@ -36,45 +36,63 @@ int main(int argc, char *argv[]) { - void *codec2; - FILE *fin; - FILE *fout; - short buf[CODEC2_SAMPLES_PER_FRAME]; - unsigned char bits[BITS_SIZE]; + int mode; + void *codec2; + FILE *fin; + FILE *fout; + short *buf; + unsigned char *bits; + int nsam, nbit; if (argc != 3) { - printf("usage: %s InputBitFile OutputRawSpeechFile\n", argv[0]); + printf("usage: %s 2500|1400 InputBitFile OutputRawSpeechFile\n", argv[0]); + printf("e.g %s 1400 hts1a.c2 hts1a_1400.raw\n", argv[0]); exit(1); } - if (strcmp(argv[1], "-") == 0) fin = stdin; + if (strcmp(argv[1],"1400") == 0) + mode = CODEC2_MODE_2500; + else if (strcmp(argv[1],"2500") == 0) + mode = CODEC2_MODE_1400; + else { + fprintf(stderr, "Error in mode: %s. Must be 2500 or 1400\n", argv[1]); + exit(1); + } + + if (strcmp(argv[2], "-") == 0) fin = stdin; else if ( (fin = fopen(argv[1],"rb")) == NULL ) { fprintf(stderr, "Error opening input bit file: %s: %s.\n", argv[1], strerror(errno)); exit(1); } - if (strcmp(argv[2], "-") == 0) fout = stdout; + if (strcmp(argv[3], "-") == 0) fout = stdout; else if ( (fout = fopen(argv[2],"wb")) == NULL ) { fprintf(stderr, "Error opening output speech file: %s: %s.\n", argv[2], strerror(errno)); exit(1); } - codec2 = codec2_create(); + codec2 = codec2_create(mode); + nsam = codec2_samples_per_frame(codec2); + nbit = codec2_bits_per_frame(codec2); + buf = (short*)malloc(nsam*sizeof(short)); + bits = (char*)malloc(nbit*sizeof(char)); - while(fread(bits, sizeof(char), BITS_SIZE, fin) == BITS_SIZE) { + while(fread(bits, sizeof(char), nbit, fin) == nbit) { codec2_decode(codec2, buf, bits); - fwrite(buf, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fout); + fwrite(buf, sizeof(short), nsam, fout); //if this is in a pipeline, we probably don't want the usual //buffering to occur if (fout == stdout) fflush(stdout); if (fin == stdin) fflush(stdin); - } + } codec2_destroy(codec2); + free(buf); + free(bits); fclose(fin); fclose(fout); diff --git a/codec2-dev/src/c2demo.c b/codec2-dev/src/c2demo.c index efa8d644..36be5948 100644 --- a/codec2-dev/src/c2demo.c +++ b/codec2-dev/src/c2demo.c @@ -42,11 +42,12 @@ 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; if (argc != 3) { printf("usage: %s InputRawSpeechFile OutputRawSpeechFile\n", argv[0]); @@ -68,15 +69,20 @@ int main(int argc, char *argv[]) /* Note only one set of Codec 2 states is required for an encoder and decoder pair. */ - codec2 = codec2_create(); + codec2 = codec2_create(CODEC2_MODE_1400); + 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) == nsam) { codec2_encode(codec2, bits, buf); codec2_decode(codec2, buf, bits); - fwrite(buf, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fout); + fwrite(buf, sizeof(short), nsam, fout); } + free(buf); + free(bits); codec2_destroy(codec2); fclose(fin); diff --git a/codec2-dev/src/c2enc.c b/codec2-dev/src/c2enc.c index 4d1d019d..5ca503f8 100644 --- a/codec2-dev/src/c2enc.c +++ b/codec2-dev/src/c2enc.c @@ -37,37 +37,52 @@ int main(int argc, char *argv[]) { - void *codec2; - FILE *fin; - FILE *fout; - short buf[CODEC2_SAMPLES_PER_FRAME]; - unsigned char bits[BITS_SIZE]; + int mode; + void *codec2; + FILE *fin; + FILE *fout; + short *buf; + unsigned char *bits; + int nsam, nbit; if (argc != 3) { - printf("usage: %s InputRawspeechFile OutputBitFile\n", argv[0]); + printf("usage: %s 2500|1400 InputRawspeechFile OutputBitFile\n", argv[0]); + printf("e.g %s 1400 ../raw/hts1a.raw hts1a.c2\n", argv[0]); exit(1); } - if (strcmp(argv[1], "-") == 0) fin = stdin; + if (strcmp(argv[1],"1400") == 0) + mode = CODEC2_MODE_2500; + else if (strcmp(argv[1],"2500") == 0) + mode = CODEC2_MODE_1400; + else { + fprintf(stderr, "Error in mode: %s. Must be 2500 or 1400\n", argv[1]); + exit(1); + } + + if (strcmp(argv[2], "-") == 0) fin = stdin; else if ( (fin = fopen(argv[1],"rb")) == NULL ) { fprintf(stderr, "Error opening input bit file: %s: %s.\n", argv[1], strerror(errno)); exit(1); } - if (strcmp(argv[2], "-") == 0) fout = stdout; + if (strcmp(argv[3], "-") == 0) fout = stdout; else if ( (fout = fopen(argv[2],"wb")) == NULL ) { fprintf(stderr, "Error opening output speech file: %s: %s.\n", argv[2], strerror(errno)); exit(1); } - codec2 = codec2_create(); + codec2 = codec2_create(mode); + nsam = codec2_samples_per_frame(codec2); + nbit = codec2_bits_per_frame(codec2); + buf = (short*)malloc(nsam*sizeof(short)); + bits = (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) == nsam) { codec2_encode(codec2, bits, buf); - fwrite(bits, sizeof(char), BITS_SIZE, fout); + fwrite(bits, sizeof(char), nbit, fout); //if this is in a pipeline, we probably don't want the usual //buffering to occur if (fout == stdout) fflush(stdout); @@ -76,6 +91,8 @@ int main(int argc, char *argv[]) codec2_destroy(codec2); + free(buf); + free(bits); fclose(fin); fclose(fout); diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index e1ee1b3c..a6eed4ae 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -353,8 +353,8 @@ int main(int argc, char *argv[]) /* various LSP quantisation schemes */ if (lsp) { - encode_lsps(lsp_indexes, lsps, LPC_ORD); - decode_lsps(lsps_, lsp_indexes, LPC_ORD); + encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD); + decode_lsps_scalar(lsps_, lsp_indexes, LPC_ORD); bw_expand_lsps(lsps_, LPC_ORD); lsp_to_lpc(lsps_, ak, LPC_ORD); } diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 4b669153..48c0f27f 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -42,22 +42,24 @@ #include "interp.h" #include "postfilter.h" #include "codec2.h" - -typedef struct { - float w[M]; /* time domain hamming window */ - COMP W[FFT_ENC]; /* DFT of w[] */ - float Pn[2*N]; /* trapezoidal synthesis window */ - float Sn[M]; /* input speech */ - float hpf_states[2]; /* high pass filter states */ - void *nlp; /* pitch predictor states */ - float Sn_[2*N]; /* synthesised output speech */ - float ex_phase; /* excitation model phase track */ - float bg_est; /* background noise estimate for post filter */ - float prev_Wo; /* previous frame's pitch estimate */ - MODEL prev_model; /* previous frame's model parameters */ - float prev_lsps[LPC_ORD]; /* previous frame's LSPs */ - float prev_energy; /* previous frame's LPC energy */ -} CODEC2; +#include "lsp.h" + +struct CODEC2 { + int mode; + float w[M]; /* time domain hamming window */ + COMP W[FFT_ENC]; /* DFT of w[] */ + float Pn[2*N]; /* trapezoidal synthesis window */ + float Sn[M]; /* input speech */ + float hpf_states[2]; /* high pass filter states */ + void *nlp; /* pitch predictor states */ + float Sn_[2*N]; /* synthesised output speech */ + float ex_phase; /* excitation model phase track */ + float bg_est; /* background noise estimate for post filter */ + float prev_Wo; /* previous frame's pitch estimate */ + MODEL prev_model; /* previous frame's model parameters */ + float prev_lsps_[LPC_ORD]; /* previous frame's LSPs */ + float prev_energy; /* previous frame's LPC energy */ +}; /*---------------------------------------------------------------------------*\ @@ -65,8 +67,13 @@ typedef struct { \*---------------------------------------------------------------------------*/ -void analyse_one_frame(CODEC2 *c2, MODEL *model, short speech[]); -void synthesise_one_frame(CODEC2 *c2, short speech[], MODEL *model,float ak[]); +void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]); +void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, + float ak[]); +void codec2_encode_2500(struct CODEC2 *c2, unsigned char * bits, short speech[]); +void codec2_decode_2500(struct CODEC2 *c2, short speech[], const unsigned char * bits); +void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]); +void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * bits); /*---------------------------------------------------------------------------*\ @@ -88,15 +95,17 @@ void synthesise_one_frame(CODEC2 *c2, short speech[], MODEL *model,float ak[]); \*---------------------------------------------------------------------------*/ -void *codec2_create() +struct CODEC2 *codec2_create(int mode) { - CODEC2 *c2; - int i,l; + struct CODEC2 *c2; + int i,l; - c2 = (CODEC2*)malloc(sizeof(CODEC2)); + c2 = (struct CODEC2*)malloc(sizeof(struct CODEC2)); if (c2 == NULL) return NULL; - + + assert((mode == CODEC2_MODE_2500) || (mode == CODEC2_MODE_1400)); + c2->mode = mode; for(i=0; iSn[i] = 1.0; c2->hpf_states[0] = c2->hpf_states[1] = 0.0; @@ -116,7 +125,7 @@ void *codec2_create() c2->prev_model.voiced = 0; for(i=0; iprev_lsps[i] = i*PI/(LPC_ORD+1); + c2->prev_lsps_[i] = i*PI/(LPC_ORD+1); } c2->prev_energy = 1; @@ -126,12 +135,12 @@ void *codec2_create() return NULL; } - return (void*)c2; + return c2; } /*---------------------------------------------------------------------------*\ - FUNCTION....: codec2_create + FUNCTION....: codec2_destroy AUTHOR......: David Rowe DATE CREATED: 21/8/2010 @@ -139,23 +148,81 @@ void *codec2_create() \*---------------------------------------------------------------------------*/ -void codec2_destroy(void *codec2_state) +void codec2_destroy(struct CODEC2 *c2) { - CODEC2 *c2; - - assert(codec2_state != NULL); - c2 = (CODEC2*)codec2_state; + assert(c2 != NULL); nlp_destroy(c2->nlp); - free(codec2_state); + free(c2); +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_bits_per_frame + AUTHOR......: David Rowe + DATE CREATED: Nov 14 2011 + + Returns the number of bits per frame. + +\*---------------------------------------------------------------------------*/ + +int codec2_bits_per_frame(struct CODEC2 *c2) { + if (c2->mode == CODEC2_MODE_2500) + return 50; + if (c2->mode == CODEC2_MODE_1400) + return 56; + + return 0; /* shouldn't get here */ } + /*---------------------------------------------------------------------------*\ - FUNCTION....: codec2_encode + FUNCTION....: codec2_samples_per_frame + AUTHOR......: David Rowe + DATE CREATED: Nov 14 2011 + + Returns the number of bits per frame. + +\*---------------------------------------------------------------------------*/ + +int codec2_samples_per_frame(struct CODEC2 *c2) { + if (c2->mode == CODEC2_MODE_2500) + return 160; + if (c2->mode == CODEC2_MODE_1400) + return 320; + + return 0; /* shouldnt get here */ +} + +void codec2_encode(struct CODEC2 *c2, unsigned char *bits, short speech[]) +{ + assert(c2 != NULL); + assert((c2->mode == CODEC2_MODE_2500) || (c2->mode == CODEC2_MODE_1400)); + + if (c2->mode == CODEC2_MODE_2500) + codec2_encode_2500(c2, bits, speech); + else + codec2_encode_1400(c2, bits, speech); +} + +void codec2_decode(struct CODEC2 *c2, short speech[], const unsigned char *bits) +{ + assert(c2 != NULL); + assert((c2->mode == CODEC2_MODE_2500) || (c2->mode == CODEC2_MODE_1400)); + + if (c2->mode == CODEC2_MODE_2500) + codec2_decode_2500(c2, speech, bits); + else + codec2_decode_1400(c2, speech, bits); +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_encode_2500 AUTHOR......: David Rowe DATE CREATED: 21/8/2010 - Encodes 160 speech samples (20ms of speech) into 51 bits. + Encodes 160 speech samples (20ms of speech) into 50 bits. The codec2 algorithm actually operates internally on 10ms (80 sample) frames, so we run the encoding algorithm twice. On the @@ -167,27 +234,29 @@ void codec2_destroy(void *codec2_state) Parameter bits/frame -------------------------------------- Harmonic magnitudes (LSPs) 36 - Low frequency LPC correction 1 Energy 5 Wo (fundamental frequnecy) 7 Voicing (10ms update) 2 - TOTAL 51 + TOTAL 50 \*---------------------------------------------------------------------------*/ -void codec2_encode(void *codec2_state, unsigned char * bits, short speech[]) +void codec2_encode_2500(struct CODEC2 *c2, unsigned char * bits, short speech[]) { - CODEC2 *c2; MODEL model; int voiced1, voiced2; + float lsps[LPC_ORD]; + float ak[LPC_ORD+1]; + float e; int lsp_indexes[LPC_ORD]; int energy_index; int Wo_index; int i; unsigned int nbit = 0; - assert(codec2_state != NULL); - c2 = (CODEC2*)codec2_state; + assert(c2 != NULL); + + memset(bits, '\0', ((codec2_bits_per_frame(c2) + 7) / 8)); /* first 10ms analysis frame - we just want voicing */ @@ -200,43 +269,42 @@ void codec2_encode(void *codec2_state, unsigned char * bits, short speech[]) voiced2 = model.voiced; Wo_index = encode_Wo(model.Wo); - encode_amplitudes(lsp_indexes, - &energy_index, - &model, - c2->Sn, - c2->w); - memset(bits, '\0', ((CODEC2_BITS_PER_FRAME + 7) / 8)); + + e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); + encode_lsps_scalar(lsp_indexes, lsps, LPC_ORD); + energy_index = encode_energy(e); + pack(bits, &nbit, Wo_index, WO_BITS); - for(i=0; iprev_model, &model, + c2->prev_lsps_, c2->prev_energy, lsps_, energy, ak_interp); + apply_lpc_correction(&model_interp); + + /* synthesise two 10ms frames */ + + synthesise_one_frame(c2, speech, &model_interp, ak_interp); + synthesise_one_frame(c2, &speech[N], &model, ak); + + /* update memories (decode states) for next time */ + + memcpy(&c2->prev_model, &model, sizeof(MODEL)); + memcpy(c2->prev_lsps_, lsps_, sizeof(lsps_)); + c2->prev_energy = energy; +} + + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_encode_1400 + AUTHOR......: David Rowe + DATE CREATED: Nov 14 2011 + + Encodes 320 speech samples (50ms of speech) into 56 bits. + + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm for times: + + frame 0: just send voicing bit + frame 1: full quantisation of LSPs and Wo + frame 2: just send voicing bit + frame 3: delta-time quantisation of LSPs and Wo + + The bit allocation is: + + Parameter frame 2 frame 4 Total + ------------------------------------------------------- + Harmonic magnitudes (LSPs) 25 7 32 + Energy 5 5 10 + Wo (fundamental frequnecy) 7 3 10 + Voicing (10ms update) 2 2 4 + TOTAL 39 17 56 + +\*---------------------------------------------------------------------------*/ + +void codec2_encode_1400(struct CODEC2 *c2, unsigned char * bits, short speech[]) +{ + MODEL model; + float lsps[LPC_ORD], prev_lsps_[LPC_ORD]; + float ak[LPC_ORD+1]; + float e; + int voiced1, voiced2, voiced3, voiced4; + int lsp_indexes[LPC_ORD]; + int energy_index; + int Wo_index, delta_Wo_index; + int i; + unsigned int nbit = 0; + float prev_Wo; + + assert(c2 != NULL); + + memset(bits, '\0', codec2_bits_per_frame(c2)/8); + + /* frame 1: - we just want voicing -------------------------------- */ + + analyse_one_frame(c2, &model, speech); + voiced1 = model.voiced; + + /* frame 2: - full LSP and Wo ------------------------------------- */ + + analyse_one_frame(c2, &model, &speech[N]); + voiced2 = model.voiced; + + Wo_index = encode_Wo(model.Wo); + + e = speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD); + encode_lsps_diff_freq_vq(lsp_indexes, lsps, LPC_ORD); + energy_index = encode_energy(e); + + pack(bits, &nbit, Wo_index, WO_BITS); + for(i=0; iSn, c2->w, LPC_ORD); + encode_lsps_diff_time_vq(lsp_indexes, lsps, prev_lsps_, LPC_ORD); + energy_index = encode_energy(e); + + pack(bits, &nbit, delta_Wo_index, WO_DT_BITS); + pack(bits, &nbit, *lsp_indexes, LSP_DIFF_TIME_BITS); + pack(bits, &nbit, energy_index, E_BITS); + pack(bits, &nbit, voiced3, 1); + pack(bits, &nbit, voiced4, 1); + + assert(nbit == codec2_bits_per_frame(c2)); +} + + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_decode_1400 + AUTHOR......: David Rowe + DATE CREATED: 16 Nov 2011 + + Decodes frames of 56 bits into 320 samples (40ms) of speech. + +\*---------------------------------------------------------------------------*/ + +void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * bits) +{ + MODEL model; + int voiced1, voiced2, voiced3, voiced4; + int lsp_indexes[LPC_ORD]; + float lsps_[LPC_ORD]; + int energy_index; + float energy; + float snr; + int Wo_index, delta_Wo_index; + float ak[LPC_ORD+1]; + float ak_interp[LPC_ORD+1]; + int i; + unsigned int nbit = 0; + MODEL model_interp; + + assert(c2 != NULL); + + /* unpack frame 1 & 2 bit stream to integer codes */ + + Wo_index = unpack(bits, &nbit, WO_BITS); + for(i=0; iprev_model, &model, - c2->prev_lsps, c2->prev_energy, lsps, energy, ak_interp); + c2->prev_lsps_, c2->prev_energy, lsps_, energy, ak_interp); apply_lpc_correction(&model_interp); - /* synthesis two 10ms frames */ + /* synthesise frame 1 and frame 2 10ms frames */ synthesise_one_frame(c2, speech, &model_interp, ak_interp); synthesise_one_frame(c2, &speech[N], &model, ak); @@ -289,10 +537,54 @@ void codec2_decode(void *codec2_state, short speech[], /* update memories (decode states) for next time */ memcpy(&c2->prev_model, &model, sizeof(MODEL)); - memcpy(c2->prev_lsps, lsps, sizeof(lsps)); + memcpy(c2->prev_lsps_, lsps_, sizeof(lsps_)); c2->prev_energy = energy; + + /*--------------------------------------------------------------------*/ + + /* unpack frame 3 & 4 bit stream to integer codes */ + + delta_Wo_index = unpack(bits, &nbit, WO_DT_BITS); + *lsp_indexes = unpack(bits, &nbit, LSP_DIFF_TIME_BITS); + energy_index = unpack(bits, &nbit, E_BITS); + voiced3 = unpack(bits, &nbit, 1); + voiced4 = unpack(bits, &nbit, 1); + assert(nbit == codec2_bits_per_frame(c2)); + + /* decode frame 4 LSPs and model amplitudes */ + + decode_lsps_diff_time_vq(lsps_, lsp_indexes, c2->prev_lsps_, LPC_ORD); + bw_expand_lsps(lsps_, LPC_ORD); + lsp_to_lpc(lsps_, ak, LPC_ORD); + energy = decode_energy(energy_index); + aks_to_M2(ak, LPC_ORD, &model, energy, &snr, 1); + apply_lpc_correction(&model); + + /* interpolate frame 3 model parameters from adjacent frames */ + + model.voiced = voiced4; + model_interp.voiced = voiced3; + model_interp.Wo = P_MAX/2; + memset(&model_interp.A, 0, MAX_AMP*sizeof(model_interp.A[0])); + + interpolate_lsp(&model_interp, &c2->prev_model, &model, + c2->prev_lsps_, c2->prev_energy, lsps_, energy, ak_interp); + apply_lpc_correction(&model_interp); + + /* synthesise frame 3 and frame 4 10ms frames */ + + synthesise_one_frame(c2, &speech[2*N], &model_interp, ak_interp); + synthesise_one_frame(c2, &speech[3*N], &model, ak); + + /* update memories (decode states) for next time */ + + memcpy(&c2->prev_model, &model, sizeof(MODEL)); + memcpy(c2->prev_lsps_, lsps_, sizeof(lsps_)); + c2->prev_energy = energy; + } + /*---------------------------------------------------------------------------*\ FUNCTION....: synthesise_one_frame() @@ -303,7 +595,7 @@ void codec2_decode(void *codec2_state, short speech[], \*---------------------------------------------------------------------------*/ -void synthesise_one_frame(CODEC2 *c2, short speech[], MODEL *model, float ak[]) +void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float ak[]) { int i; @@ -333,7 +625,7 @@ void synthesise_one_frame(CODEC2 *c2, short speech[], MODEL *model, float ak[]) \*---------------------------------------------------------------------------*/ -void analyse_one_frame(CODEC2 *c2, MODEL *model, short speech[]) +void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) { COMP Sw[FFT_ENC]; COMP Sw_[FFT_ENC]; diff --git a/codec2-dev/src/codec2.h b/codec2-dev/src/codec2.h index 946dedca..277b8e7a 100644 --- a/codec2-dev/src/codec2.h +++ b/codec2-dev/src/codec2.h @@ -29,13 +29,16 @@ #ifndef __CODEC2__ #define __CODEC2__ -#define CODEC2_SAMPLES_PER_FRAME 160 -#define CODEC2_BITS_PER_FRAME 50 - -void *codec2_create(); -void codec2_destroy(void *codec2_state); -void codec2_encode(void *codec2_state, unsigned char * bits, short speech_in[]); -void codec2_decode(void *codec2_state, short speech_out[], - const unsigned char * bits); +#define CODEC2_MODE_2500 0 +#define CODEC2_MODE_1400 1 + +struct CODEC2; + +struct CODEC2 *codec2_create(int mode); +void codec2_destroy(struct CODEC2 *codec2_state); +void codec2_encode(struct CODEC2 *codec2_state, unsigned char * bits, short speech_in[]); +void codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits); +int codec2_samples_per_frame(struct CODEC2 *codec2_state); +int codec2_bits_per_frame(struct CODEC2 *codec2_state); #endif diff --git a/codec2-dev/src/quantise.c b/codec2-dev/src/quantise.c index b3da2a59..551a7dec 100644 --- a/codec2-dev/src/quantise.c +++ b/codec2-dev/src/quantise.c @@ -59,6 +59,10 @@ int lsp_bits(int i) { return lsp_cb[i].log2m; } +int lspd_bits(int i) { + return lsp_cbd[i].log2m; +} + /*---------------------------------------------------------------------------*\ quantise_init @@ -130,7 +134,7 @@ void lspd_quantise( int order ) { - int i,k,m,ncb, nlsp, index; + int i,k,m,index; float lsp_hz[LPC_MAX]; float lsp__hz[LPC_MAX]; float dlsp[LPC_MAX]; @@ -779,16 +783,16 @@ float speech_to_uq_lsps(float lsp[], /*---------------------------------------------------------------------------*\ - FUNCTION....: encode_lsps() + FUNCTION....: encode_lsps_scalar() AUTHOR......: David Rowe DATE CREATED: 22/8/2010 - From a vector of unquantised (floating point) LSPs finds the quantised - LSP indexes. + Thirty-six bit sclar LSP quantiser. From a vector of unquantised + (floating point) LSPs finds the quantised LSP indexes. \*---------------------------------------------------------------------------*/ -void encode_lsps(int indexes[], float lsp[], int order) +void encode_lsps_scalar(int indexes[], float lsp[], int order) { int i,k,m; float wt[1]; @@ -815,7 +819,7 @@ void encode_lsps(int indexes[], float lsp[], int order) /*---------------------------------------------------------------------------*\ - FUNCTION....: decode_lsps() + FUNCTION....: decode_lsps_scalar() AUTHOR......: David Rowe DATE CREATED: 22/8/2010 @@ -824,7 +828,7 @@ void encode_lsps(int indexes[], float lsp[], int order) \*---------------------------------------------------------------------------*/ -void decode_lsps(float lsp[], int indexes[], int order) +void decode_lsps_scalar(float lsp[], int indexes[], int order) { int i,k; float lsp_hz[LPC_MAX]; @@ -840,6 +844,190 @@ void decode_lsps(float lsp[], int indexes[], int order) for(i=0; i