Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active April 29, 2019 01:03
Show Gist options
  • Save J3698/bd0be71270ed41e57b805f29b05637af to your computer and use it in GitHub Desktop.
Save J3698/bd0be71270ed41e57b805f29b05637af to your computer and use it in GitHub Desktop.
The process method for the audio visualizer
int process(jack_nframes_t nframes, void *arg) {
sample_t *outBufferLeft = (sample_t *) jack_port_get_buffer(output_port_l, nframes);
sample_t *outBufferRight = (sample_t *) jack_port_get_buffer(output_port_r, nframes);
sample_t *inBufferLeft = (sample_t *) jack_port_get_buffer(input_port_l, nframes);
sample_t *inBufferRight = (sample_t *) jack_port_get_buffer(input_port_r, nframes);
// copy input audio to output
memcpy(outBufferLeft, inBufferLeft, sizeof(sample_t) * nframes);
memcpy(outBufferRight, inBufferRight, sizeof(sample_t) * nframes);
// calculate an estimate for the volume of the data
double total = 0;
for (int i = 0; i < nframes; i++) {
total += pow(outBufferLeft[i], 2);
total += pow(outBufferRight[i], 2);
}
// print to the console based on the volume estimate
if (total > 0.3) {
printf("\n111111111111111111");
} else {
printf("\n000000000000000000");
}
// uncomment the following line for debugging
// printf("%f\n", total);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment