Example #1
0
void* capture_thread(void *arg)
{
    size_t capt_samples_num = samplerate / 1000 * frame_length;
    uint8_t *capt_buf = calloc(1, capt_samples_num * 2);
    assert(capt_buf != NULL);

    /* start the capture */
	snd_pcm_prepare(acapt_hdl);
    snd_pcm_start(acapt_hdl);
    snd_pcm_reset(acapt_hdl);

    while (!terminate_threads) {
		/* capture, track the capture time  */
        struct timeval start_ts, stop_ts;
        gettimeofday(&start_ts, NULL);

        if (!audio_capture_read(capt_buf, capt_samples_num))
            continue;

        gettimeofday(&stop_ts, NULL);
        uint32_t time_delta = (stop_ts.tv_sec - start_ts.tv_sec) * 1000000 +
                                        (stop_ts.tv_usec - start_ts.tv_usec);

        if (capt_min_time == 0)
            capt_min_time = time_delta;
        else
            capt_min_time = (time_delta < capt_min_time) ?
                                                time_delta : capt_min_time;

        if (capt_max_time == 0)
            capt_max_time = time_delta;
        else
            capt_max_time = (time_delta > capt_max_time) ?
                                                time_delta : capt_max_time;

        capt_time += time_delta;
        capt_buffers++;

        if (!spsc_circular_queue_push(queue, capt_buf)) {
            capt_buffers_dropped++;
            sched_yield();
        }
    }

    free(capt_buf);
    return NULL;
}
Example #2
0
int main(int argc, char *argv[])
{
	int rc, rdnum;
	printf("APRSDUMP V1.0, Stefan Koch <*****@*****.**>\n");

	if (2 != argc) {
		printf("need sound device\n");
		return EXIT_FAILURE;
	}
	audio_dev = strdup(argv[1]);
	//audio_dev = strdup("plughw:0,0");

	printf("- init audio capture\n");
	printf("  + audio device = %s\n", audio_dev);
	rc = audio_capture_init(audio_dev);
	if (0 == rc) {
		printf("  + init sucess\n");
	} else {
		printf("  + init failed (%d)\n", rc);
		return EXIT_FAILURE;
	}
	
	/* register sigint handler */
	printf("- register sigint handler\n");
	signal(SIGINT, sig_int_handler);

	/* start decoder loop */
	while (1 == run) {
		rdnum = audio_capture_read(&aubuf);
		if (-1 == rdnum) break;
	//	cdump(aubuf, rdnum);
		cbar(audiometer(aubuf, rdnum));
	}

	printf("- shutdown audio capture\n");
	audio_capture_close();

	return 0;
}