Stream the default input device over the default output device.Supports specifying device and backend to use.
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct SoundIoRingBuffer *ring_buffer = NULL;
};
static int prioritized_sample_rates[] = {
48000,
44100,
96000,
24000,
0,
};
__attribute__ ((cold))
__attribute__ ((noreturn))
__attribute__ ((format (printf, 1, 2)))
static void panic(const char *format, ...) {
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
va_end(ap);
abort();
}
static int min_int(int a, int b) {
return (a < b) ? a : b;
}
static void read_callback(
struct SoundIoInStream *instream,
int frame_count_min,
int frame_count_max) {
int err;
if (frame_count_min > free_count)
panic("ring buffer overflow");
int write_frames = min_int(free_count, frame_count_max);
int frames_left = write_frames;
for (;;) {
int frame_count = frames_left;
if (!frame_count)
break;
if (!areas) {
fprintf(stderr, "Dropped %d frames due to internal overflow\n", frame_count);
} else {
for (int frame = 0; frame < frame_count; frame += 1) {
}
}
}
frames_left -= frame_count;
if (frames_left <= 0)
break;
}
}
static void write_callback(
struct SoundIoOutStream *outstream,
int frame_count_min,
int frame_count_max) {
int frame_count;
int err;
if (frame_count_min > fill_count) {
for (;;) {
if (frame_count <= 0)
return;
for (int frame = 0; frame < frame_count; frame += 1) {
}
}
}
}
int read_count = min_int(frame_count_max, fill_count);
int frames_left = read_count;
while (frames_left > 0) {
int frame_count = frames_left;
if (frame_count <= 0)
break;
for (int frame = 0; frame < frame_count; frame += 1) {
}
}
frames_left -= frame_count;
}
}
static int count = 0;
fprintf(stderr, "underflow %d\n", ++count);
}
static int usage(char *exe) {
fprintf(stderr, "Usage: %s [options]\n"
"Options:\n"
" [--backend dummy|alsa|pulseaudio|jack|coreaudio|wasapi]\n"
" [--in-device id]\n"
" [--in-raw]\n"
" [--out-device id]\n"
" [--out-raw]\n"
" [--latency seconds]\n"
, exe);
return 1;
}
int main(int argc, char **argv) {
char *exe = argv[0];
char *in_device_id = NULL;
char *out_device_id = NULL;
bool in_raw = false;
bool out_raw = false;
double microphone_latency = 0.2;
for (int i = 1; i < argc; i += 1) {
char *arg = argv[i];
if (arg[0] == '-' && arg[1] == '-') {
if (strcmp(arg, "--in-raw") == 0) {
in_raw = true;
} else if (strcmp(arg, "--out-raw") == 0) {
out_raw = true;
} else if (++i >= argc) {
return usage(exe);
} else if (strcmp(arg, "--backend") == 0) {
if (strcmp("dummy", argv[i]) == 0) {
} else if (strcmp("alsa", argv[i]) == 0) {
} else if (strcmp("pulseaudio", argv[i]) == 0) {
} else if (strcmp("jack", argv[i]) == 0) {
} else if (strcmp("coreaudio", argv[i]) == 0) {
} else if (strcmp("wasapi", argv[i]) == 0) {
} else {
fprintf(stderr, "Invalid backend: %s\n", argv[i]);
return 1;
}
} else if (strcmp(arg, "--in-device") == 0) {
in_device_id = argv[i];
} else if (strcmp(arg, "--out-device") == 0) {
out_device_id = argv[i];
} else if (strcmp(arg, "--latency") == 0) {
microphone_latency = atof(argv[i]);
} else {
return usage(exe);
}
} else {
return usage(exe);
}
}
if (!soundio)
panic("out of memory");
if (err)
if (default_out_device_index < 0)
panic("no output device found");
if (default_in_device_index < 0)
panic("no output device found");
int in_device_index = default_in_device_index;
if (in_device_id) {
bool found = false;
if (device->
is_raw == in_raw && strcmp(device->
id, in_device_id) == 0) {
in_device_index = i;
found = true;
break;
}
}
if (!found)
panic("invalid input device id: %s", in_device_id);
}
int out_device_index = default_out_device_index;
if (out_device_id) {
bool found = false;
if (device->
is_raw == out_raw && strcmp(device->
id, out_device_id) == 0) {
out_device_index = i;
found = true;
break;
}
}
if (!found)
panic("invalid output device id: %s", out_device_id);
}
if (!out_device)
panic("could not get output device: out of memory");
if (!in_device)
panic("could not get input device: out of memory");
fprintf(stderr,
"Input device: %s\n", in_device->
name);
fprintf(stderr,
"Output device: %s\n", out_device->
name);
if (!layout)
panic("channel layouts not compatible");
int *sample_rate;
for (sample_rate = prioritized_sample_rates; *sample_rate; sample_rate += 1) {
{
break;
}
}
if (!*sample_rate)
panic("incompatible sample rates");
{
break;
}
}
panic("incompatible sample formats");
if (!instream)
panic("out of memory");
return 1;
}
if (!outstream)
panic("out of memory");
return 1;
}
if (!ring_buffer)
panic("unable to create ring buffer: out of memory");
memset(buf, 0, fill_count);
for (;;)
return 0;
}