Created
September 17, 2011 12:30
-
-
Save Themaister/1223899 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <portaudio.h> | |
#include <stdio.h> | |
#include <rsound.h> | |
#include <assert.h> | |
#include <signal.h> | |
static volatile sig_atomic_t g_alive; | |
static void sighandler(int sig) | |
{ | |
(void)sig; | |
g_alive = 0; | |
} | |
#define FRAMES 1024 | |
int main(void) | |
{ | |
signal(SIGINT, sighandler); | |
signal(SIGTERM, sighandler); | |
signal(SIGPIPE, sighandler); | |
Pa_Initialize(); | |
PaDeviceIndex index = Pa_GetDefaultInputDevice(); | |
const PaDeviceInfo *info = Pa_GetDeviceInfo(index); | |
PaStreamParameters params = { | |
.device = index, | |
.channelCount = 2, | |
.sampleFormat = paInt16, | |
.suggestedLatency = info->defaultLowInputLatency, | |
}; | |
PaStream *stream; | |
assert(Pa_OpenStream(&stream, ¶ms, NULL, info->defaultSampleRate, FRAMES, 0, NULL, NULL) == paNoError); | |
assert(Pa_StartStream(stream) == paNoError); | |
rsound_t *rd; | |
rsd_init(&rd); | |
int rate = info->defaultSampleRate; | |
rsd_set_param(rd, RSD_SAMPLERATE, &rate); | |
int channels = 2; | |
rsd_set_param(rd, RSD_CHANNELS, &channels); | |
int format = RSD_S16_NE; | |
rsd_set_param(rd, RSD_FORMAT, &format); | |
assert(rsd_start(rd) == 0); | |
g_alive = 1; | |
fprintf(stderr, "=== Starting capture ===\n"); | |
while (g_alive) | |
{ | |
int16_t buf[FRAMES * 2]; | |
Pa_ReadStream(stream, buf, FRAMES); | |
rsd_write(rd, buf, sizeof(buf)); | |
} | |
fprintf(stderr, "=== End capture ===\n"); | |
rsd_stop(rd); | |
rsd_free(rd); | |
Pa_CloseStream(stream); | |
Pa_Terminate(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment