tonedec.c

来自「Fax and soft modem source code. - Slow m」· C语言 代码 · 共 39 行

C
39
字号
#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 + =
减小字号Ctrl + -
显示快捷键?