building up test framework to track down clicking bug on Windows

pull/7/head
David Rowe 2019-05-12 07:29:26 +09:30
parent 645ab41410
commit ed9494dead
6 changed files with 141 additions and 7 deletions

View File

@ -1,3 +1,5 @@
/* test tool to diffs two .f32 files */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@ -6,13 +8,17 @@
int main(int argc, char *argv[]) {
float f1[NB_FEATURES],f2[NB_FEATURES],fdiff=0.0;
int ret,f=0,i;
int f=0;
unsigned int ret, i, stride = NB_FEATURES;
FILE *file1 = fopen(argv[1],"rb");
FILE *file2 = fopen(argv[2],"rb");
while(fread(&f1,sizeof(float),NB_FEATURES,file1) == NB_FEATURES) {
ret = fread(&f2,sizeof(float),NB_FEATURES,file2);
if (ret != NB_FEATURES) break;
for(i=0; i<NB_FEATURES; i++) {
if (argc == 4) {
stride = atoi(argv[3]);
}
while(fread(&f1,sizeof(float),stride,file1) == stride) {
ret = fread(&f2,sizeof(float),stride,file2);
if (ret != stride) break;
for(i=0; i<stride; i++) {
fdiff += fabs(f1[i]-f2[i]);
if (isnan(fdiff) || (fdiff > 1E-6)) {
@ -22,6 +28,6 @@ int main(int argc, char *argv[]) {
}
f++;
}
fprintf(stderr,"f: %d fdiff: %f\n", f, fdiff);
fprintf(stderr,"stride: %d f: %d fdiff: %f\n", stride, f, fdiff);
fclose(file1); fclose(file2);
}

View File

@ -0,0 +1,70 @@
% linux_v_windows.m
% David Rowe May 2019
%
% Part of system to generate and compare Linux and Windows test files
% that contain LPCNet states. Use to track down issue with Windows version
%
% Run in Octave from LPCNet/src
1;
function check_vec(fig_num, name, vec1, vec2)
figure(fig_num); clf;
plot(vec1); hold on; plot(vec2); hold off;
title(name);
diff = var(vec1-vec2);
if diff < 1E-3
printf("%s [PASS]\n", name);
else
printf("%s [FAIL]\n", name);
end
endfunction
function check_matrix(fig_num, name, mat1, mat2)
figure(fig_num); clf;
mesh(mat1); hold on; mesh(mat2); hold off;
title(name);
mdiff = mat1-mat2; diff = var(mdiff(:));
if diff < 1E-3
printf("%s [PASS]\n", name);
else
printf("%s [FAIL]\n", name);
% find first row where problem occurs
[rows cols]= size(mat1);
first_error = 1;
for r=1:rows
e = var(mat1(r,:) - mat2(r,:));
if e > 1E-3
printf("error %f in row: %d\n", e, r);
if (first_error)
clf; plot(mat1(r,:)); hold on; plot(mat2(r,:)); plot(mat1(r,:) - mat2(r,:)); hold off;
first_error = 0;
end
end
end
end
endfunction
n_pitch_embed = 64;
n_pitch = 1;
n_pitch_gain = 1;
n_lpc = 16;
n_condition = 128;
n_cols = n_pitch_embed + n_pitch + n_pitch_gain + n_lpc + n_condition;
linux=load_f32("../build_linux/src/test_lpcnet_states.f32", n_cols);
[r c]=size(linux);
printf("linux %d x %d\n", r, c);
windows=load_f32("../build_win/src/test_lpcnet_states.f32", n_cols);
[r c]=size(windows);
printf("windows %d x %d\n", r, c);
fig = 1;
st = 1;
en = st + n_pitch_embed-1; check_matrix(fig++, "pitch_embed", linux(:,st:en), windows(:,st:en)); st += n_pitch_embed;
check_vec(fig++, "pitch", linux(:,st), windows(:,st)); st += n_pitch;
check_vec(fig++, "pitch_gain", linux(:,st), windows(:,st)); st += n_pitch_gain;
en = st + n_lpc-1; check_matrix(fig++, "lpc", linux(:,st:en), windows(:,st:en)); st += n_lpc;
en = st + n_condition-1; check_matrix(fig++, "condition", linux(:,st:en), windows(:,st:en)); st += n_condition;

View File

@ -0,0 +1,24 @@
#!/bin/bash
# linux_v_windows.sh
# David Rowe May 2019
#
# Part of system to generate and compare Linux and Windows test files
# that contain LPCNet states. Use to track down issue with Windows version
export WINEPATH=$HOME/freedv-gui/codec2/build_win/src';'$HOME/freedv-gui/build_win/_CPack_Packages/win64/NSIS/FreeDV-1.4.0-devel-win64/bin/
# start in LPCNet dir
p=$PWD
# Windows
cd build_win/src && make test_lpcnet
wine test_lpcnet.exe wia.f32 wia_out.raw
cd $p
# Linux
cd build_linux/src && make test_lpcnet
./test_lpcnet ../../build_win/src/wia.f32 wia_out.raw
./diff32 test_lpcnet_states.f32 ../../build_win/src/test_lpcnet_states.f32 210
cd $p

View File

@ -53,6 +53,7 @@ struct LPCNetState {
float old_gain[FEATURES_DELAY];
int frame_count;
float deemph_mem;
FILE *ftest; /* used to dump states for automates tests */
};
@ -86,6 +87,10 @@ void run_frame_network(LPCNetState *lpcnet, float *condition, float *gru_a_condi
compute_dense(&feature_dense2, condition, dense1_out);
compute_dense(&gru_a_dense_feature, gru_a_condition, condition);
if (lpcnet->frame_count < 1000) lpcnet->frame_count++;
if (lpcnet->ftest) {
fwrite(&in[NB_FEATURES], sizeof(float), EMBED_PITCH_OUT_SIZE, lpcnet->ftest);
}
}
void run_sample_network(NNetState *net, float *pdf, const float *condition, const float *gru_a_condition, int last_exc, int last_sig, int pred)
@ -109,14 +114,24 @@ LPCNetState *lpcnet_create()
LPCNetState *lpcnet;
lpcnet = (LPCNetState *)calloc(sizeof(LPCNetState), 1);
lpcnet->last_exc = 128;
lpcnet->ftest = NULL;
return lpcnet;
}
void lpcnet_destroy(LPCNetState *lpcnet)
{
if (lpcnet->ftest) fclose(lpcnet->ftest);
free(lpcnet);
}
void lpcnet_open_test_file(LPCNetState *lpcnet, char file_name[]) {
lpcnet->ftest = fopen(file_name, "wb");
if (lpcnet->ftest == NULL) {
fprintf(stderr, "Error opening LPCNet test file: %s\n", file_name);
exit(1);
}
}
void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features, int N)
{
int i;
@ -137,6 +152,19 @@ void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features
memcpy(lpc, lpcnet->old_lpc[FEATURES_DELAY-1], LPC_ORDER*sizeof(lpc[0]));
memmove(lpcnet->old_lpc[1], lpcnet->old_lpc[0], (FEATURES_DELAY-1)*LPC_ORDER*sizeof(lpc[0]));
lpc_from_cepstrum(lpcnet->old_lpc[0], features);
if (lpcnet->ftest) {
float pitch_f = pitch;
fwrite(&pitch_f, sizeof(float), 1, lpcnet->ftest);
fwrite(&pitch_gain, sizeof(float), 1, lpcnet->ftest);
fwrite(lpc, sizeof(float), LPC_ORDER, lpcnet->ftest);
fwrite(condition, sizeof(float), FEATURE_DENSE2_OUT_SIZE, lpcnet->ftest);
if (lpcnet->frame_count==1) {
fprintf(stderr, "%d %d %d %d %d\n", EMBED_PITCH_OUT_SIZE, 1,1,LPC_ORDER,FEATURE_DENSE2_OUT_SIZE);
fprintf(stderr, "ftest cols = %d\n", EMBED_PITCH_OUT_SIZE+1+1+LPC_ORDER+FEATURE_DENSE2_OUT_SIZE);
}
}
if (lpcnet->frame_count <= FEATURES_DELAY)
{
RNN_CLEAR(output, N);

View File

@ -36,4 +36,6 @@ LPCNetState *lpcnet_create();
void lpcnet_destroy(LPCNetState *lpcnet);
void lpcnet_synthesize(LPCNetState *lpcnet, short *output, const float *features, int N);
void lpcnet_open_test_file(LPCNetState *lpcnet, char file_name[]);
#endif

View File

@ -34,7 +34,10 @@
int main(int argc, char **argv) {
FILE *fin, *fout;
LPCNetState *net;
net = lpcnet_create();
lpcnet_open_test_file(net, "test_lpcnet_states.f32");
if (argc != 3)
{
fprintf(stderr, "usage: test_lpcnet <features.f32> <output.pcm>\n");
@ -58,7 +61,8 @@ int main(int argc, char **argv) {
}
}
while (1) {
while (1) {
float in_features[NB_TOTAL_FEATURES];
float features[NB_FEATURES];
short pcm[FRAME_SIZE];