From ac7c48b4dee99d4c772f133d70d8d1b38262fcd2 Mon Sep 17 00:00:00 2001 From: Author Name Date: Fri, 7 Jul 2023 12:20:59 +0930 Subject: shallow zip-file copy from codec2 e9d726bf20 --- misc/timpulse.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 misc/timpulse.c (limited to 'misc/timpulse.c') diff --git a/misc/timpulse.c b/misc/timpulse.c new file mode 100644 index 0000000..8227c0d --- /dev/null +++ b/misc/timpulse.c @@ -0,0 +1,128 @@ +/* + timpulse.c + David Rowe Dec 2019 + + Generate a synthetic speech signal from a sum of sinusoids. Generates a known test + signals for phaseNN and ampNN projects. +*/ + +#include +#include +#include +#include +#include + +#define FS 8000 + +int main(int argc, char *argv[]) { + short buf[FS] = {0}; + float f0 = 60.0; + float n0 = 0.0; + int Nsecs = 1; + int randf0 = 0; + int filter = 0; + int rande = 0; + + int o = 0; + int opt_idx = 0; + while( o != -1 ) { + static struct option long_opts[] = { + {"help", no_argument, 0, 'h'}, + {"n0", required_argument, 0, 'n'}, + {"f0", required_argument, 0, 'f'}, + {"secs", required_argument, 0, 's'}, + {"randf0", no_argument, 0, 'r'}, + {"rande", required_argument, 0, 'e'}, + {"filter", no_argument, 0, 'i'}, + {0, 0, 0, 0} + }; + + o = getopt_long(argc,argv,"hn:f:s:r",long_opts,&opt_idx); + + switch(o) { + case 'n': + n0 = atof(optarg); + break; + case 'f': + f0 = atof(optarg); + break; + case 's': + Nsecs = atoi(optarg); + break; + case 'r': + randf0 = 1; + break; + case 'i': + filter = 1; + break; + case 'e': + rande = atoi(optarg); + break; + case '?': + case 'h': + fprintf(stderr, + "usage: %s\n" + "[--f0 f0Hz] fixed F0\n" + "[--n0 samples] time offset\n" + "[--secs Nsecs] number of seconds to generate\n" + "[--randf0] choose a random F0 every second\n" + "[--rande Ndiscrete] choose a random frame energy every second, Ndiscrete values\n" + "\n", argv[0]); + exit(1); + break; + } + } + + int t = 0; + float A = 100.0; + + /* optionally filter with 2nd order system */ + float alpha = 0.25*M_PI, gamma=0.99; + float a[2] = {-2.0*gamma*cos(alpha), gamma*gamma}; + float mem[2] = {0}; + + for (int j=0; j