/*---------------------------------------------------------------------------*\ FILE........: tnewamp1.c AUTHOR......: David Rowe DATE CREATED: Jan 2017 Tests for the C version of the newamp1 amplitude modelling used for 700c. This program outputs a file of Octave vectors that are loaded and automatically tested against the Octave version of the modem by the Octave script tnewamp1.m \*---------------------------------------------------------------------------*/ /* Copyright (C) 2017 David Rowe All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ #include "codec2_fft.h" #include "defines.h" #include "dump.h" #include "newamp1.h" #include "nlp.h" #include "octave.h" #include "quantise.h" #include "sine.h" #define FRAMES 300 int main(int argc, char *argv[]) { int Fs = 8000; C2CONST c2const = c2const_create(Fs, N_S); int n_samp = c2const.n_samp; int m_pitch = c2const.m_pitch; short buf[n_samp]; /* input/output buffer */ float Sn[m_pitch]; /* float input speech samples */ COMP Sw[FFT_ENC]; /* DFT of Sn[] */ codec2_fft_cfg fft_fwd_cfg; /* fwd FFT states */ float w[m_pitch]; /* time domain hamming window */ float W[FFT_ENC]; /* DFT of w[] */ MODEL model; void *nlp_states; codec2_fft_cfg phase_fft_fwd_cfg, phase_fft_inv_cfg; float pitch, prev_f0; int i, m, f, k; if (argc != 2) { printf("usage: ./tnewamp1 RawFile\n"); exit(1); } nlp_states = nlp_create(&c2const); prev_f0 = 1.0 / P_MAX_S; fft_fwd_cfg = codec2_fft_alloc(FFT_ENC, 0, NULL, NULL); make_analysis_window(&c2const, fft_fwd_cfg, w, W); phase_fft_fwd_cfg = codec2_fft_alloc(NEWAMP1_PHASE_NFFT, 0, NULL, NULL); phase_fft_inv_cfg = codec2_fft_alloc(NEWAMP1_PHASE_NFFT, 1, NULL, NULL); for (i = 0; i < m_pitch; i++) { Sn[i] = 1.0; } int K = 20; float rate_K_sample_freqs_kHz[K]; float model_octave[FRAMES][MAX_AMP + 2]; // model params in matrix format, // useful for C <-> Octave float rate_K_surface[FRAMES][K]; // rate K vecs for each frame, form a // surface that makes pretty graphs float rate_K_surface_no_mean[FRAMES][K]; // mean removed surface float rate_K_surface_no_mean_[FRAMES][K]; // quantised mean removed surface float mean[FRAMES]; float mean_[FRAMES]; float rate_K_surface_[FRAMES][K]; // quantised rate K vecs for each frame float interpolated_surface_[FRAMES][K]; // dec/interpolated surface // int voicing[FRAMES]; int voicing_[FRAMES]; float model_octave_[FRAMES][MAX_AMP + 2]; COMP H[FRAMES][MAX_AMP]; int indexes[FRAMES][NEWAMP1_N_INDEXES]; float se = 0.0; float eq[K]; for (k = 0; k < K; k++) eq[k] = 0.0; for (f = 0; f < FRAMES; f++) { for (m = 0; m < MAX_AMP + 2; m++) { model_octave[f][m] = 0.0; model_octave_[f][m] = 0.0; } for (m = 0; m < MAX_AMP; m++) { H[f][m].real = 0.0; H[f][m].imag = 0.0; } for (k = 0; k < K; k++) interpolated_surface_[f][k] = 0.0; voicing_[f] = 0; } mel_sample_freqs_kHz(rate_K_sample_freqs_kHz, K, ftomel(200.0), ftomel(3700.0)); // for(int k=0; k= M) { for (i = 0; i < M; i++) { for (k = 0; k < K; k++) { interpolated_surface_[f - M + i][k] = a_interpolated_surface_[i][k]; } } /* store test vectors */ for (i = f - M, m = 0; i < f; i++, m++) { model_octave_[i][0] = model__[m].Wo; model_octave_[i][1] = model__[m].L; voicing_[i] = model__[m].voiced; } int j; for (i = f - M, j = 0; i < f; i++, j++) { for (m = 1; m <= model__[j].L; m++) { model_octave_[i][m + 1] = model__[j].A[m]; H[i][m - 1] = HH[j][m]; // aH[m]; } } } } fclose(fin); /* save vectors in Octave format */ FILE *fout = fopen("tnewamp1_out.txt", "wt"); assert(fout != NULL); fprintf(fout, "# Created by tnewamp1.c\n"); octave_save_float(fout, "rate_K_surface_c", (float *)rate_K_surface, FRAMES, K, K); octave_save_float(fout, "mean_c", (float *)mean, 1, FRAMES, 1); octave_save_float(fout, "eq_c", eq, 1, K, K); octave_save_float(fout, "rate_K_surface_no_mean_c", (float *)rate_K_surface_no_mean, FRAMES, K, K); octave_save_float(fout, "rate_K_surface_no_mean__c", (float *)rate_K_surface_no_mean_, FRAMES, K, K); octave_save_float(fout, "mean__c", (float *)mean_, FRAMES, 1, 1); octave_save_float(fout, "rate_K_surface__c", (float *)rate_K_surface_, FRAMES, K, K); octave_save_float(fout, "interpolated_surface__c", (float *)interpolated_surface_, FRAMES, K, K); octave_save_float(fout, "model_c", (float *)model_octave, FRAMES, MAX_AMP + 2, MAX_AMP + 2); octave_save_float(fout, "model__c", (float *)model_octave_, FRAMES, MAX_AMP + 2, MAX_AMP + 2); octave_save_int(fout, "voicing__c", (int *)voicing_, 1, FRAMES); octave_save_complex(fout, "H_c", (COMP *)H, FRAMES, MAX_AMP, MAX_AMP); fclose(fout); printf( "Done! Now run\n octave:1> " "tnewamp1(\"../path/to/build_linux/src/hts1a\", " "\"../path/to/build_linux/unittest\")\n"); return 0; }