📄 tonedec.c
字号:
#include <stdio.h>
#include "private.h"
#include "complex.h"
#include "filters.h"
#include "tonedec.h"
#define THRESH 0.1 /* tone threshold */
inline float fsgn(float x) { return (x > 0.0f) ? +1.0f : (x < 0.0f) ? -1.0f : 0.0f; }
inline float sqr(float f) { return f*f; }
tone_detector::tone_detector(fspec *fefs, fspec *bpfs, fspec *lpfs, bool lim)
{ fef = new filter(fefs);
bpf = new filter(bpfs);
lpf = new filter(lpfs);
limit = lim;
pow = 0.0; prescount = 0; present = false;
}
tone_detector::~tone_detector()
{ delete fef; delete bpf; delete lpf;
}
void tone_detector::insert(float x)
{ x = fef -> fstep(x); /* front-end filter to remove d.c. */
if (limit) x = fsgn(x); /* hard limit */
float y = bpf -> fstep(x);
pow = lpf -> fstep(sqr(y));
present = (pow >= THRESH);
if (present) prescount++; else prescount = 0;
}
void tone_detector::debug()
{ fprintf(stderr, " %14.5e (%5d)", pow, prescount);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -