i've tested, now you can too

This commit is contained in:
Brian West
2012-12-20 20:08:42 -06:00
parent d3fcfa8245
commit d67b96af8a
94 changed files with 25305 additions and 2005 deletions

View File

@@ -22,8 +22,7 @@
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
@@ -32,39 +31,43 @@
#include <string.h>
#include <math.h>
#include "defines.h"
#include "comp.h"
#include "codec2.h"
#include "quantise.h"
#include "interp.h"
/* CODEC2 struct copies from codec2.c to help with testing */
typedef struct {
float Sn[M]; /* input speech */
float w[M]; /* time domain hamming window */
COMP W[FFT_ENC]; /* DFT of w[] */
float Pn[2*N]; /* trapezoidal synthesis window */
float Sn_[2*N]; /* synthesised speech */
float prev_Wo; /* previous frame's pitch estimate */
float ex_phase; /* excitation model phase track */
float bg_est; /* background noise estimate for post filter */
MODEL prev_model; /* model parameters from 20ms ago */
} CODEC2;
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 */
};
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[]);
int test1()
{
FILE *fin, *fout;
short buf[N];
void *c2;
CODEC2 *c3;
struct CODEC2 *c2;
MODEL model;
float ak[LPC_ORD+1];
float lsps[LPC_ORD];
c2 = codec2_create();
c3 = (CODEC2*)c2;
c2 = codec2_create(CODEC2_MODE_2400);
fin = fopen("../raw/hts1a.raw", "rb");
assert(fin != NULL);
@@ -72,9 +75,9 @@ int test1()
assert(fout != NULL);
while(fread(buf, sizeof(short), N, fin) == N) {
analyse_one_frame(c3, &model, buf);
speech_to_uq_lsps(lsps, ak, c3->Sn, c3->w, LPC_ORD);
synthesise_one_frame(c3, buf, &model, ak);
analyse_one_frame(c2, &model, buf);
speech_to_uq_lsps(lsps, ak, c2->Sn, c2->w, LPC_ORD);
synthesise_one_frame(c2, buf, &model, ak);
fwrite(buf, sizeof(short), N, fout);
}
@@ -90,22 +93,22 @@ int test2()
{
FILE *fin, *fout;
short buf[2*N];
void *c2;
CODEC2 *c3;
struct CODEC2 *c2;
MODEL model, model_interp;
float ak[LPC_ORD+1];
int voiced1, voiced2;
int lsp_indexes[LPC_ORD];
int lpc_correction;
int energy_index;
int Wo_index;
char bits[CODEC2_BITS_PER_FRAME];
char *bits;
int nbit;
int i;
c2 = codec2_create();
c3 = (CODEC2*)c2;
float lsps[LPC_ORD];
float e;
c2 = codec2_create(CODEC2_MODE_2400);
bits = (char*)malloc(codec2_bits_per_frame(c2));
assert(bits != NULL);
fin = fopen("../raw/hts1a.raw", "rb");
assert(fin != NULL);
fout = fopen("hts1a_test.raw", "wb");
@@ -114,60 +117,57 @@ int test2()
while(fread(buf, sizeof(short), 2*N, fin) == 2*N) {
/* first 10ms analysis frame - we just want voicing */
analyse_one_frame(c3, &model, buf);
analyse_one_frame(c2, &model, buf);
voiced1 = model.voiced;
/* second 10ms analysis frame */
analyse_one_frame(c3, &model, &buf[N]);
analyse_one_frame(c2, &model, &buf[N]);
voiced2 = model.voiced;
Wo_index = encode_Wo(model.Wo);
encode_amplitudes(lsp_indexes,
&lpc_correction,
&energy_index,
&model,
c3->Sn,
c3->w);
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);
nbit = 0;
pack(bits, &nbit, Wo_index, WO_BITS);
pack((unsigned char*)bits, (unsigned *)&nbit, Wo_index, WO_BITS);
for(i=0; i<LPC_ORD; i++) {
pack(bits, &nbit, lsp_indexes[i], lsp_bits(i));
pack((unsigned char*)bits, (unsigned *)&nbit, lsp_indexes[i], lsp_bits(i));
}
pack(bits, &nbit, lpc_correction, 1);
pack(bits, &nbit, energy_index, E_BITS);
pack(bits, &nbit, voiced1, 1);
pack(bits, &nbit, voiced2, 1);
pack((unsigned char*)bits, (unsigned *)&nbit, energy_index, E_BITS);
pack((unsigned char*)bits, (unsigned *)&nbit, voiced1, 1);
pack((unsigned char*)bits, (unsigned *)&nbit, voiced2, 1);
nbit = 0;
Wo_index = unpack(bits, &nbit, WO_BITS);
Wo_index = unpack((unsigned char*)bits, (unsigned *)&nbit, WO_BITS);
for(i=0; i<LPC_ORD; i++) {
lsp_indexes[i] = unpack(bits, &nbit, lsp_bits(i));
lsp_indexes[i] = unpack((unsigned char*)bits, (unsigned *)&nbit, lsp_bits(i));
}
lpc_correction = unpack(bits, &nbit, 1);
energy_index = unpack(bits, &nbit, E_BITS);
voiced1 = unpack(bits, &nbit, 1);
voiced2 = unpack(bits, &nbit, 1);
energy_index = unpack((unsigned char*)bits, (unsigned *)&nbit, E_BITS);
voiced1 = unpack((unsigned char*)bits, (unsigned *)&nbit, 1);
voiced2 = unpack((unsigned char*)bits, (unsigned *)&nbit, 1);
model.Wo = decode_Wo(Wo_index);
model.L = PI/model.Wo;
decode_amplitudes(&model,
ak,
lsp_indexes,
lpc_correction,
energy_index);
energy_index,
lsps,
&e);
model.voiced = voiced2;
model_interp.voiced = voiced1;
interpolate(&model_interp, &c3->prev_model, &model);
interpolate(&model_interp, &c2->prev_model, &model);
synthesise_one_frame(c3, buf, &model_interp, ak);
synthesise_one_frame(c3, &buf[N], &model, ak);
synthesise_one_frame(c2, buf, &model_interp, ak);
synthesise_one_frame(c2, &buf[N], &model, ak);
memcpy(&c3->prev_model, &model, sizeof(MODEL));
memcpy(&c2->prev_model, &model, sizeof(MODEL));
fwrite(buf, sizeof(short), 2*N, fout);
}
free(bits);
codec2_destroy(c2);
fclose(fin);
@@ -181,10 +181,14 @@ int test3()
FILE *fin, *fout, *fbits;
short buf1[2*N];
short buf2[2*N];
char bits[CODEC2_BITS_PER_FRAME];
void *c2;
char *bits;
struct CODEC2 *c2;
c2 = codec2_create();
c2 = codec2_create(CODEC2_MODE_2400);
int numBits = codec2_bits_per_frame(c2);
int numBytes = (numBits+7)>>3;
bits = (char*)malloc(numBytes);
fin = fopen("../raw/hts1a.raw", "rb");
assert(fin != NULL);
@@ -194,12 +198,13 @@ int test3()
assert(fout != NULL);
while(fread(buf1, sizeof(short), 2*N, fin) == 2*N) {
codec2_encode(c2, bits, buf1);
fwrite(bits, sizeof(char), CODEC2_BITS_PER_FRAME, fbits);
codec2_decode(c2, buf2, bits);
fwrite(buf2, sizeof(short), CODEC2_SAMPLES_PER_FRAME, fout);
codec2_encode(c2, (void*)bits, buf1);
fwrite(bits, sizeof(char), numBytes, fbits);
codec2_decode(c2, buf2, (void*)bits);
fwrite(buf2, sizeof(short), numBytes, fout);
}
free(bits);
codec2_destroy(c2);
fclose(fin);