unsigned char *bits;
int nsam, nbit;
- if (argc != 3) {
- printf("usage: %s 2500|1400 InputBitFile OutputRawSpeechFile\n", argv[0]);
- printf("e.g %s 1400 hts1a.c2 hts1a_1400.raw\n", argv[0]);
+ if (argc != 4) {
+ printf("usage: c2dec 2500|1400 InputBitFile OutputRawSpeechFile\n");
+ printf("e.g c2dec 1400 hts1a.c2 hts1a_1400.raw\n");
exit(1);
}
if (strcmp(argv[1],"1400") == 0)
- mode = CODEC2_MODE_2500;
- else if (strcmp(argv[1],"2500") == 0)
mode = CODEC2_MODE_1400;
+ else if (strcmp(argv[1],"2500") == 0)
+ mode = CODEC2_MODE_2500;
else {
fprintf(stderr, "Error in mode: %s. Must be 2500 or 1400\n", argv[1]);
exit(1);
}
-
+ printf("mode: %d\n", mode);
if (strcmp(argv[2], "-") == 0) fin = stdin;
- else if ( (fin = fopen(argv[1],"rb")) == NULL ) {
+ else if ( (fin = fopen(argv[2],"rb")) == NULL ) {
fprintf(stderr, "Error opening input bit file: %s: %s.\n",
argv[1], strerror(errno));
exit(1);
}
if (strcmp(argv[3], "-") == 0) fout = stdout;
- else if ( (fout = fopen(argv[2],"wb")) == NULL ) {
+ else if ( (fout = fopen(argv[3],"wb")) == NULL ) {
fprintf(stderr, "Error opening output speech file: %s: %s.\n",
argv[2], strerror(errno));
exit(1);
nsam = codec2_samples_per_frame(codec2);
nbit = codec2_bits_per_frame(codec2);
buf = (short*)malloc(nsam*sizeof(short));
- bits = (char*)malloc(nbit*sizeof(char));
+ bits = (unsigned char*)malloc(nbit*sizeof(char));
while(fread(bits, sizeof(char), nbit, fin) == nbit) {
codec2_decode(codec2, buf, bits);
unsigned char *bits;
int nsam, nbit;
- if (argc != 3) {
- printf("usage: %s 2500|1400 InputRawspeechFile OutputBitFile\n", argv[0]);
- printf("e.g %s 1400 ../raw/hts1a.raw hts1a.c2\n", argv[0]);
+ if (argc != 4) {
+ printf("usage: c2enc 2500|1400 InputRawspeechFile OutputBitFile\n");
+ printf("e.g c2enc 1400 ../raw/hts1a.raw hts1a.c2\n");
exit(1);
}
if (strcmp(argv[1],"1400") == 0)
- mode = CODEC2_MODE_2500;
- else if (strcmp(argv[1],"2500") == 0)
mode = CODEC2_MODE_1400;
+ else if (strcmp(argv[1],"2500") == 0)
+ mode = CODEC2_MODE_2500;
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 ) {
+ else if ( (fin = fopen(argv[2],"rb")) == NULL ) {
fprintf(stderr, "Error opening input bit file: %s: %s.\n",
argv[1], strerror(errno));
exit(1);
}
if (strcmp(argv[3], "-") == 0) fout = stdout;
- else if ( (fout = fopen(argv[2],"wb")) == NULL ) {
+ else if ( (fout = fopen(argv[3],"wb")) == NULL ) {
fprintf(stderr, "Error opening output speech file: %s: %s.\n",
argv[2], strerror(errno));
exit(1);
nsam = codec2_samples_per_frame(codec2);
nbit = codec2_bits_per_frame(codec2);
buf = (short*)malloc(nsam*sizeof(short));
- bits = (char*)malloc(nbit*sizeof(char));
+ bits = (unsigned char*)malloc(nbit*sizeof(char));
while(fread(buf, sizeof(short), nsam, fin) == nsam) {
codec2_encode(codec2, bits, buf);
float lsps__prev2[LPC_ORD];
float e, prev_e;
float ak_interp[LPC_MAX];
+ int lsp_indexes[LPC_MAX];
+ float lsps_[LPC_ORD];
void *nlp_states;
float hpf_states[2];
sum_snr = 0;
while(fread(buf,sizeof(short),N,fin)) {
frames++;
- //printf("frame: %d", frames);
+ printf("frame: %d", frames);
/* Read input speech */
/* optional LPC model amplitudes and LSP quantisation -----------------*/
if (lpc_model) {
- int lsp_indexes[LPC_MAX];
- float lsps_[LPC_ORD];
e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
lsp_to_lpc(lsps_, ak, LPC_ORD);
}
- /* we need lsp__prev[] for lspdt. If no other
- LSP quantisation is used we use original LSPs
- as there is no quantised version available. */
+ /* we need lsp__prev[] for lspdt and decimate. If no
+ other LSP quantisation is used we use original LSPs as
+ there is no quantised version available. */
if (!lsp && !lspd && !lspvq && !lspres)
for(i=0; i<LPC_ORD; i++)
of 4) by quantising the difference between the 1st
frames LSPs and the 3rd frames:
- 10ms, frame 1: send "full" LSP frame
- 20ms, frame 2: discard (interpolate at decoder)
- 30ms, frame 3: send LSPs differences between frame 3 and frame 1
- 40ms, frame 4: discard (interpolate at decoder)
+ 10ms, frame 1: discard (interpolate at decoder)
+ 20ms, frame 2: send "full" LSP frame
+ 30ms, frame 3: discard (interpolate at decoder)
+ 40ms, frame 4: send LSPs differences between frame 4 and frame 2
*/
if (lspdt && decimate) {
- if ((frames%4) == 3) {
+ if ((frames%4) == 0) {
lspdt_quantise(lsps, lsps_, lsps__prev2, lspdt_mode);
bw_expand_lsps(lsps_, LPC_ORD);
lsp_to_lpc(lsps_, ak, LPC_ORD);
e = decode_energy(encode_energy(e));
- if (!decimate && dt && (frames % 2)) {
- model.Wo = decode_Wo_dt(encode_Wo_dt(model.Wo, prev_Wo),prev_Wo);
- model.L = PI/model.Wo;
+ if (!decimate) {
+ /* we send paams every 10ms, delta-time every 20ms */
+ if (dt && (frames % 2))
+ model.Wo = decode_Wo_dt(encode_Wo_dt(model.Wo, prev_Wo),prev_Wo);
+ else
+ model.Wo = decode_Wo(encode_Wo(model.Wo));
}
- if (decimate && dt && ((frames % 4) == 3)) {
- model.Wo = decode_Wo_dt(encode_Wo_dt(model.Wo, prev__Wo),prev__Wo);
- model.L = PI/model.Wo;
- //printf("dWo");
+ if (decimate) {
+ /* we send params every 20ms */
+ if (dt && ((frames % 4) == 3)) {
+ /* delta-time every 40ms */
+ model.Wo = decode_Wo_dt(encode_Wo_dt(model.Wo, prev__Wo),prev__Wo);
+ }
+ else
+ model.Wo = decode_Wo(encode_Wo(model.Wo));
}
+
+ model.L = PI/model.Wo; /* if we quantise Wo re-compute L */
if (!decimate && !dt)
model.Wo = decode_Wo(encode_Wo(model.Wo));
/*
Each 20ms we synthesise two 10ms frames:
- frame 1: interpolate frame 0 LSPs from frame -1 and frame 1
- synthesise frame 0 and frame 1 speech
- frame 2: discard except for voicing bit
- frame 3: interpolate frame 2 LSPs from frame 1 and frame 3
- synthesise frame 2 and frame 3 speech
- frame 4: discard except for voicing bit
+ frame 1: discard except for voicing bit
+ frame 2: interpolate frame 1 LSPs from frame 2 and frame 0
+ synthesise frame 1 and frame 2 speech
+ frame 3: discard except for voicing bit
+ frame 4: interpolate frame 3 LSPs from frame 4 and frame 2
+ synthesise frame 3 and frame 4 speech
*/
- if (frames%2) {
- //printf("interp\n");
+ if ((frames%2) == 0) {
+ printf("interp\n");
+ printf("Wo: %1.5f L: %d e: %3.2f \n", model.Wo, model.L, e);
+ for(i=0; i<LPC_ORD; i++)
+ printf("lsp_indexes: %d lsps_: %2.3f prev_lsps_: %2.3f\n",
+ lsp_indexes[i], lsps_[i], prev_lsps[i]);
+ printf("ak: ");
+ for(i=0; i<LPC_ORD; i++)
+ printf("%2.3f ", ak[i]);
+ printf("\n");
/* decode interpolated frame */
interpolate(&interp_model, &prev_model, &model);
#else
interpolate_lsp(&interp_model, &prev_model, &model,
- prev_lsps, prev_e, lsps, e, ak_interp);
+ prev_lsps, prev_e, lsps_, e, ak_interp);
apply_lpc_correction(&interp_model);
#endif
-
+ printf("Wo: %1.5f L: %d prev_e: %3.2f\n",
+ interp_model.Wo, interp_model.L, prev_e);
+ printf("ak_interp: ");
+ for(i=0; i<LPC_ORD; i++)
+ printf("%2.3f ", ak_interp[i]);
+ printf("\n");
+ //if (frames==40)
+ // exit(0);
if (phase0)
phase_synth_zero_order(&interp_model, ak_interp, ex_phase,
order);
prev_model = model;
for(i=0; i<LPC_ORD; i++)
- prev_lsps[i] = lsps[i];
+ prev_lsps[i] = lsps_[i];
prev_e = e;
}
else {
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);
+ //for(i=0; i<LPC_ORD; i++)
+ // printf("lsp_indexes: %d lsps: %2.3f\n", lsp_indexes[i], lsps[i]);
+ //exit(0);
pack(bits, &nbit, Wo_index, WO_BITS);
for(i=0; i<LSP_SCALAR_INDEXES; i++) {
int i;
unsigned int nbit = 0;
MODEL model_interp;
+ static int frames;
+ printf("frame: %d\n", frames+=2);
assert(c2 != NULL);
-
+
/* unpack bit stream to integer codes */
Wo_index = unpack(bits, &nbit, WO_BITS);
aks_to_M2(ak, LPC_ORD, &model, energy, &snr, 1);
apply_lpc_correction(&model);
+ printf("Wo: %1.5f L: %d e: %3.2f \n", model.Wo, model.L, energy);
+ for(i=0; i<LPC_ORD; i++)
+ printf("lsp_indexes: %d lsp_: %2.3f prev_lsp_: %2.3f\n",
+ lsp_indexes[i], lsps_[i], c2->prev_lsps_[i]);
+ printf("ak: ");
+ for(i=0; i<LPC_ORD; i++)
+ printf("%2.3f ", ak[i]);
+ printf("\n");
+
/* interpolate odd frame model parameters from adjacent frames */
model.voiced = voiced2;
interpolate_lsp(&model_interp, &c2->prev_model, &model,
c2->prev_lsps_, c2->prev_energy, lsps_, energy, ak_interp);
apply_lpc_correction(&model_interp);
+ printf("Wo: %1.5f L: %d prev_e: %3.2f\n",
+ model_interp.Wo, model_interp.L, c2->prev_energy );
+ printf("ak_interp: ");
+ for(i=0; i<LPC_ORD; i++)
+ printf("%2.3f ", ak_interp[i]);
+ printf("\n");
+ //if (frames ==40)
+ // exit(0);
/* synthesise two 10ms frames */