Added audio buffer mirroring, closes #53

This commit is contained in:
Jarcode
2018-08-05 17:38:59 -07:00
parent 469b8ec7ad
commit 8c3b9a5f21
6 changed files with 16 additions and 4 deletions

View File

@@ -244,7 +244,7 @@ int main(int argc, char** argv) {
.rate = (unsigned int) r->rate_request, .rate = (unsigned int) r->rate_request,
.format = -1, .format = -1,
.terminate = 0, .terminate = 0,
.channels = 2, .channels = r->mirror_input ? 1 : 2,
.audio_out_r = b0, .audio_out_r = b0,
.audio_out_l = b1, .audio_out_l = b1,
.mutex = PTHREAD_MUTEX_INITIALIZER, .mutex = PTHREAD_MUTEX_INITIALIZER,

View File

@@ -299,7 +299,7 @@ static void* create_and_bind(const char* name, const char* class,
XFree(xvi); XFree(xvi);
} }
} }
if (best == -1) { if (best == -1) {
fprintf(stderr, "Could not find suitable format for FBConfig\n"); fprintf(stderr, "Could not find suitable format for FBConfig\n");
abort(); abort();

View File

@@ -168,7 +168,11 @@ void* input_pulse(void* data) {
int idx = (fsz - (ssz / 4)) + n; int idx = (fsz - (ssz / 4)) + n;
if (audio->channels == 1) bl[idx] = (buf[i] + buf[i + 1]) / 2; if (audio->channels == 1) {
float sample = (buf[i] + buf[i + 1]) / 2;
bl[idx] = sample;
br[idx] = sample;
}
/* stereo storing channels in buffer */ /* stereo storing channels in buffer */
if (audio->channels == 2) { if (audio->channels == 2) {

View File

@@ -685,6 +685,7 @@ struct renderer* rd_new(const char** paths, const char* entry,
renderer* r = malloc(sizeof(struct renderer)); renderer* r = malloc(sizeof(struct renderer));
*r = (struct renderer) { *r = (struct renderer) {
.alive = true, .alive = true,
.mirror_input = false,
.gl = malloc(sizeof(struct gl_data)), .gl = malloc(sizeof(struct gl_data)),
.bufsize_request = 8192, .bufsize_request = 8192,
.rate_request = 22000, .rate_request = 22000,
@@ -816,6 +817,10 @@ struct renderer* rd_new(const char** paths, const char* entry,
} }
}) })
}, },
{
.name = "setmirror", .fmt = "b",
.handler = RHANDLER(name, args, { r->mirror_input = *(bool*) args[0]; })
},
{ {
.name = "setbg", .fmt = "s", .name = "setbg", .fmt = "s",
.handler = RHANDLER(name, args, { .handler = RHANDLER(name, args, {

View File

@@ -5,7 +5,7 @@
struct gl_data; struct gl_data;
typedef struct renderer { typedef struct renderer {
bool alive; bool alive, mirror_input;
size_t bufsize_request, rate_request, samplesize_request; size_t bufsize_request, rate_request, samplesize_request;
char* audio_source_request; char* audio_source_request;
struct gl_data* gl; struct gl_data* gl;

View File

@@ -41,6 +41,9 @@
"none" - Disable window opacity completely. */ "none" - Disable window opacity completely. */
#request setopacity "native" #request setopacity "native"
/* Whether to mirror left and right audio input channels from PulseAudio.*/
#request setmirror true
/* OpenGL context and GLSL shader versions, do not change unless /* OpenGL context and GLSL shader versions, do not change unless
you *absolutely* know what you are doing. */ you *absolutely* know what you are doing. */
#request setversion 3 3 #request setversion 3 3