2
* gen_sine.c -- generate DTMF sequences
5
* Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
/* ---------------------------------------------------------------------- */
27
/* ---------------------------------------------------------------------- */
29
void gen_init_sine(struct gen_params *p, struct gen_state *s)
31
memset(s, 0, sizeof(struct gen_state));
33
s->s.sine.phinc = (float)0x10000 * p->p.sine.freq / SAMPLE_RATE;
34
s->s.sine.time = p->p.sine.duration;
37
int gen_sine(signed short *buf, int buflen, struct gen_params *p, struct gen_state *s)
41
for (; (buflen > 0) && (s->s.sine.time > 0); buflen--, buf++, num++, s->s.sine.time--) {
42
*buf += (p->ampl * COS(s->s.sine.ph)) >> 15;
43
s->s.sine.ph += s->s.sine.phinc;