Exemplo n.º 1
0
Arquivo: tones.c Projeto: quozl/cforth
void
bin_to_tone(int bin, tone_t *tone)
{
    unsigned int f1;
    f1 = bin * FREQ_NUM;
    tone_setup(bin * FREQ_NUM, FREQ_DEN, tone);
}
Exemplo n.º 2
0
static void *playtones_alloc(struct cw_channel *chan, void *params)
{
	struct playtones_def *pd = params;
	struct playtones_state *ps;

	if ((ps = malloc(sizeof(*ps))) == NULL)
		return NULL;
	memset(ps, 0, sizeof(*ps));
	ps->origwfmt = chan->writeformat;
	if (cw_set_write_format(chan, CW_FORMAT_SLINEAR))
    {
		cw_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
		playtones_release(NULL, ps);
		ps = NULL;
	}
    else
    {
		struct playtones_item *pi;

		ps->vol = pd->vol;
		ps->reppos = pd->reppos;
		ps->nitems = pd->nitems;
		ps->items = pd->items;

		/* Initialize the tone generator */
		pi = &pd->items[0];
    	tone_setup(ps, pi);
	}
	/* Let interrupts interrupt :) */
	if (pd->interruptible)
		cw_set_flag(chan, CW_FLAG_WRITE_INT);
	else
		cw_clear_flag(chan, CW_FLAG_WRITE_INT);
	return ps;
}
Exemplo n.º 3
0
static int playtones_generator(struct cw_channel *chan, void *data, int samples)
{
	struct playtones_state *ps = data;
	struct playtones_item *pi;
	int len;
    int x;

	/*
	 * We need to prepare a frame with 16 * timelen samples as we're 
	 * generating SLIN audio
	 */
	len = samples + samples;
	if (len > sizeof(ps->data)/sizeof(int16_t) - 1)
    {
		cw_log(LOG_WARNING, "Can't generate that much data!\n");
		return -1;
	}

    x = tone_gen(&ps->tone_state, ps->data, samples);
	pi = &ps->items[ps->npos];

	/* Assemble frame */
	cw_fr_init_ex(&ps->f, CW_FRAME_VOICE, CW_FORMAT_SLINEAR, NULL);
	ps->f.datalen = len;
	ps->f.samples = samples;
	ps->f.offset = CW_FRIENDLY_OFFSET;
	ps->f.data = ps->data;
	cw_write(chan, &ps->f);

	ps->pos += x;
	if (pi->duration  &&  ps->pos >= pi->duration*8)
    {
    	/* item finished? */
		ps->pos = 0;					/* start new item */
		ps->npos++;
		if (ps->npos >= ps->nitems)
        {
            /* last item */
			if (ps->reppos == -1)			/* repeat set? */
				return -1;
			ps->npos = ps->reppos;			/* redo from top */
		}

		/* Prepare the tone generator for more */
		pi = &ps->items[ps->npos];
		tone_setup(ps, pi);
	}
	return 0;
}
Exemplo n.º 4
0
Arquivo: tones.c Projeto: quozl/cforth
void
hz_to_tone(int hz, tone_t *tone)
{
    tone_setup(hz, 1, tone);
}