Beispiel #1
0
Datei: main.c Projekt: texane/dsp
int main(int ac, char** av)
{
    static const double fsampl = 44100;

    tonegen_t gen;
    unsigned int i;
    unsigned int ms;
    unsigned int nsampl;

#define CONFIG_BUF_SIZE 1024
    double genbuf[CONFIG_BUF_SIZE];
    int16_t rawbuf[2 * CONFIG_BUF_SIZE];

    if (ac <= 2) return -1;
    ms = atoi(av[1]);
    nsampl = ((unsigned int)fsampl * ms) / 1000;

    tonegen_init(&gen);

    for (i = 2; i < ac; ++i)
    {
        double w = 0;
        double a = 0;
        double phi = 0;

        if (split3(av[i], &w, &a, &phi) == -1) continue;

        tonegen_add(&gen, fsampl, w, a, phi);
    }

    for (i = 0; i < nsampl; i += CONFIG_BUF_SIZE)
    {
        unsigned int n = CONFIG_BUF_SIZE;
        if ((i + CONFIG_BUF_SIZE) > nsampl) n = nsampl - i;
        tonegen_read(&gen, genbuf, n);
        convert_double_to_s16x2(rawbuf, genbuf, n);
        write(1, rawbuf, n * 2 * sizeof(int16_t));
    }

    return 0;
}
Beispiel #2
0
void audio_io_task(void)
{
	sndbuf_t * out_buf;
	sndbuf_t * in_buf;
	uint32_t ts = 0;
	int i;

	tracef("%s(): <%d> started...", __func__, thinkos_thread_self());

	tonegen_init(&tonegen, 0, 0);
	spectrum_init(&audio_tx_sa, SAMPLE_RATE);
	spectrum_init(&audio_rx_sa, SAMPLE_RATE);

	for (;;) {
#if DISABLE_JITBUF
		out_buf = xfr_buf;
#else
		out_buf = jitbuf_dequeue(&audio_drv.jitbuf);
#endif

		if (audio_drv.tone_mode == TONE_DAC) {
			if (out_buf == NULL) {
				if ((out_buf = sndbuf_alloc()) != NULL)
					tonegen_apply(&tonegen, out_buf);
				else
					out_buf = (sndbuf_t *)&sndbuf_zero;
			}
		} else {
			if (out_buf == NULL) {
#if 0
			tracef("%s(): out_buf == NULL!", __func__);
#endif
				out_buf = (sndbuf_t *)&sndbuf_zero;
			}
		}

		spectrum_rec(&audio_tx_sa, out_buf);

		in_buf = i2s_io(out_buf);

  		for (i = 0; i < SNDBUF_LEN; i++)
		    in_buf->data[i] = FxaIirApply(&iir_hp_120hz, in_buf->data[i]);
//		    in_buf->data[i] = FxaIirApply(&iir_hp_240hz, in_buf->data[i]);

		led_flash(LED_I2S, 100);

		if (in_buf != &sndbuf_null) {
			if (audio_drv.tone_mode == TONE_ADC)
				tonegen_apply(&tonegen, in_buf);

			spectrum_rec(&audio_rx_sa, in_buf);
		}

		if (audio_drv.stream_enabled) {
#if ENABLE_G711
			if (g711_alaw_send(0, in_buf, ts) < 0) {
				tracef("%s(): net_send() failed!", __func__);
			}
#else
			if (audio_send(0, in_buf, ts) < 0) {
				tracef("%s(): net_send() failed!", __func__);
			}
#endif
			led_flash(LED_NET, 100);
		}

		ts += SNDBUF_LEN;

		sndbuf_free(in_buf);
		sndbuf_free(out_buf);
	}
}
Beispiel #3
0
int audio_tone_set(int tone, int gain)
{
	return tonegen_init(&tonegen, q15_db2amp(gain), tone);
}