/* Copyright (c) 2017-2018 Mozilla */ /* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include "kiss_fft.h" #include "common.h" #include #include "freq.h" #include "pitch.h" #include "arch.h" #include #include "lpcnet.h" #include "lpcnet_private.h" #include "os_support.h" #include "cpu_support.h" static void biquad(float *y, float mem[2], const float *x, const float *b, const float *a, int N) { int i; for (i=0;i \n", argv0); fprintf(stderr, " or %s -test \n", argv0); return 1; } f1 = fopen(argv[2], "r"); if (f1 == NULL) { fprintf(stderr,"Error opening input .s16 16kHz speech input file: %s\n", argv[2]); exit(1); } ffeat = fopen(argv[3], "wb"); if (ffeat == NULL) { fprintf(stderr,"Error opening output feature file: %s\n", argv[3]); exit(1); } if (training && !pitch) { fpcm = fopen(argv[4], "wb"); if (fpcm == NULL) { fprintf(stderr,"Error opening output PCM file: %s\n", argv[4]); exit(1); } } while (1) { size_t ret; ret = fread(tmp, sizeof(opus_int16), FRAME_SIZE, f1); if (feof(f1) || ret != FRAME_SIZE) { if (!training) break; rewind(f1); ret = fread(tmp, sizeof(opus_int16), FRAME_SIZE, f1); if (ret != FRAME_SIZE) { fprintf(stderr, "error reading\n"); exit(1); } one_pass_completed = 1; } for (i=0;i=10000000 && one_pass_completed) break; if (training && ++gain_change_count > 2821) { speech_gain = pow(10., (-30+(rand()%40))/20.); if (rand()&1) speech_gain = -speech_gain; if (rand()%20==0) speech_gain *= .01; if (!pitch && rand()%100==0) speech_gain = 0; gain_change_count = 0; rand_resp(a_sig, b_sig); if (fnoise != NULL) { long pos; /* Randomize the fraction because rand() only gives us 31 bits. */ float frac_pos = rand()/(float)RAND_MAX; pos = (long)(frac_pos*noise_size); /* 32-bit alignment. */ pos = pos/4 * 4; if (pos > noise_size-500000) pos = noise_size-500000; noise_gain = pow(10., (-15+(rand()%40))/20.); if (rand()%10==0) noise_gain = 0; fseek(fnoise, pos, SEEK_SET); } } if (fnoise != NULL) { opus_int16 noise[FRAME_SIZE]; ret = fread(noise, sizeof(opus_int16), FRAME_SIZE, fnoise); for (i=0;ixcorr_features[i]); } for (i=0;iif_features[i]); } fwrite(pitch_features, PITCH_MAX_PERIOD-PITCH_MIN_PERIOD+PITCH_IF_FEATURES, 1, ffeat); } else { fwrite(st->features, sizeof(float), NB_TOTAL_FEATURES, ffeat); } /*if(pitch) fwrite(pcm, FRAME_SIZE, 2, stdout);*/ if (fpcm) fwrite(pcm, FRAME_SIZE, 2, fpcm); /*if (fpcm) fwrite(pcm, sizeof(opus_int16), FRAME_SIZE, fpcm);*/ for (i=0;i