File: gen_ccir.c

package info (click to toggle)
multimon 1.0-7.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 576 kB
  • ctags: 924
  • sloc: ansic: 8,144; makefile: 233; perl: 41
file content (90 lines) | stat: -rw-r--r-- 2,859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 *      gen_ccir.c -- generate DTMF sequences
 *
 *      Copyright (C) 1997
 *          Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *	
 *
 *	Copied from gen_zvei.c and modified by Mathias Bøhn Grytemark, 2010, by idea of Mathias Nilsen.
*/

/* ---------------------------------------------------------------------- */

#include "gen.h"
#include <string.h>
#include <ctype.h>
#include <stdio.h>

/* ---------------------------------------------------------------------- */

#define PHINC(x)   ((float)(x)*0x10000/SAMPLE_RATE)

static const unsigned int ccir_freq[16] = {
	PHINC(1981), PHINC(1124), PHINC(1197), PHINC(1275), 
	PHINC(1358), PHINC(1446), PHINC(1540), PHINC(1640), 
	PHINC(1747), PHINC(1860), PHINC(2400), PHINC(930), 
	PHINC(2247), PHINC(991), PHINC(2110), PHINC(1055)
};

static const unsigned int ccirs_freq[16] = {
	PHINC(1981), PHINC(1124), PHINC(1197), PHINC(1275), 
	PHINC(1358), PHINC(1446), PHINC(1540), PHINC(1640), 
	PHINC(1747), PHINC(1860), PHINC(2400), PHINC(930), 
	PHINC(2247), PHINC(991), PHINC(2110), PHINC(1055)
};

void gen_init_ccir(struct gen_params *p, struct gen_state *s)
{
	memset(s, 0, sizeof(struct gen_state));
}

int gen_ccir(signed short *buf, int buflen, struct gen_params *p, struct gen_state *s)
{
	char c;
	int num = 0, i;

	for (; buflen > 0; buflen--, buf++, num++) {
		if (s->s.ccir.time <= 0) {
			c = p->p.ccir.str[s->s.ccir.ch_idx];
			if (!c)
				return num;
			s->s.ccir.ch_idx++;
			if (!isxdigit(c)) {
				s->s.ccir.time = s->s.ccir.time2 = 1;
				fprintf(stderr, "gen: ccir; invalid char '%c'\n", c);
			} else {
				s->s.ccir.time = p->p.ccir.duration + p->p.ccir.pause;
				s->s.ccir.time2 = p->p.ccir.duration;
				if (c >= '0' && c <= '9')
					i = c - '0';
				else if (c >= 'A' && c <= 'F')
					i = c - 'A' + 10;
				else
					i = c - 'a' + 10;
				s->s.ccir.phinc = ccir_freq[i & 0xf];
			}
		} else if (!s->s.ccir.time2) {
			s->s.ccir.phinc = 0;
			s->s.ccir.ph = 0xc000;
		}
		s->s.ccir.time--;
		s->s.ccir.time2--;
		*buf += (p->ampl * COS(s->s.ccir.ph)) >> 15;
		s->s.ccir.ph += s->s.ccir.phinc;
	}
	return num;
}