low latency linux audio i/o library
Posted: Thu Sep 12, 2019 5:57 am
Hi. I've tried PulseAudio with poor results given what I need. I'm trying to make my audio output match the input as fast as possible. The situation involves me connecting my electric guitar via USB cable.. There's a delay however. I know it's possible to achieve near real-time latency because I've used a program on Windows called Rocksmith that has a built-in amp and does such a thing. I haven't managed to get guitarix working so I can't say how reliable that is for my situation. If anyone could help me out I'd appreciate it. Here's my PulseAudio example:
If someone can help me rid the delay and lower the latency as much as possible I'd appreciate it.
Otherwise, please suggest libraries that I can use for this project!
Thank you!
Code: Select all
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <pulse/simple.h>
#include <pulse/error.h>
#define BUFSIZE 8
/* A simple routine calling UNIX write() in a loop */
int main(int argc, char*argv[]) {
/* The sample type to use */
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,
.channels = 2
};
pa_simple *s = NULL;
pa_simple *x = NULL;
int ret = 1;
int error;
/* Create the recording stream */
if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) {
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
goto finish;
}
if (!(x = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
goto finish;
}
for (;;) {
uint8_t buf[BUFSIZE];
/* Record some data ... */
if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
goto finish;
}
/* And write it to STDOUT */
if (pa_simple_write(x, buf, sizeof(buf), &error) < 0) {
fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));
goto finish;
}
}
ret = 0;
finish:
if (s)
pa_simple_free(s);
return ret;
}
Otherwise, please suggest libraries that I can use for this project!
Thank you!