From 5d65033efcc9841323d9ca6e892017199b7341d3 Mon Sep 17 00:00:00 2001 From: markster Date: Fri, 24 Oct 2003 13:36:13 +0000 Subject: fxsdump git-svn-id: http://svn.digium.com/svn/zaptel/trunk@257 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- fxsdump.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 fxsdump.c (limited to 'fxsdump.c') diff --git a/fxsdump.c b/fxsdump.c new file mode 100755 index 0000000..0451ca3 --- /dev/null +++ b/fxsdump.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "coeffs.h" + +#define FREQ 1000.0 +#define LEVEL 16384.0 + +#define FIRLEN (sizeof(coeffs) / sizeof(coeffs[0])) + +int firguess(int sample) +{ + static float hist[FIRLEN] = { 0, }; + int x; + float sum; + for (x=FIRLEN-2;x>=0;x--) + hist[x + 1] = hist[x]; + hist[0] = sample; + sum = 0; + for (x=0;x 32767.0) + sum = 32767.0; + if (sum < -32768.0) + sum = -32768.0; + return (int)sum; +} + +int obufnext(void) +{ + static int pos = 0; + static int spos = 0; + float res; + if (++spos > 100) { + res = LEVEL * sin(2.0 * FREQ * M_PI * (float)pos / 8000.0); + if (res > 32767.0) + res = 32767.0; + if (res < -32768.0) + res = -32768.0; + + pos++; + } else { + res = 0.0; + spos++; + } + return (int)res; +} + +int percent(int a, int b) +{ + float af = a; + float bf = b; + if (!b) + return 0; + return (int)((af/bf) * 100.0); +} + +int main() +{ + int fd; + int fdo,fdo2,fdo3; + int res, x; + int z=0; + short ibuf[512]; + short obuf[512]; + short pred[512]; + fd = open("/dev/zap/1", O_RDWR); + if (fd < 0) { + fprintf(stderr, "open: %s\n", strerror(errno)); + exit(1); + } + fdo = open("datain.raw", O_WRONLY | O_TRUNC | O_CREAT); + fdo2 = open("dataout.raw", O_WRONLY | O_TRUNC | O_CREAT); + fdo3 = open("datapred.raw", O_WRONLY | O_TRUNC | O_CREAT); + x = 1; +#if 0 + if (ioctl(fd, ZT_AUDIOMODE, &x)) { + fprintf(stderr, "audiomode: %s\n", strerror(errno)); + exit(1); + } + x = 1; + if (ioctl(fd, ZT_SETLINEAR, &x)) { + fprintf(stderr, "linear: %s\n", strerror(errno)); + exit(1); + } +#endif + for (x=0;x