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 <stdlib.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <math.h> | |
#include <getopt.h> | |
#include <string.h> | |
#include <wchar.h> | |
#include <locale.h> |
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
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); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>My Site</title> | |
<meta charset="UTF-8"> | |
<style> | |
#header { | |
position: absolute; | |
top: 0; left: 0; | |
width: 100%; |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>My Site</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"</meta> | |
<style> | |
#header { | |
position: absolute; | |
top: 0; left: 0; |
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 <stdlib.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <math.h> | |
#include <string.h> | |
#include "moving_average.h" | |
// for audio |
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
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); |
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
void update_lights(bool beat_detected) { | |
static uint8_t blueness = 0; | |
if (beat_detected) { | |
blueness = MAX_BRIGHTNESS; | |
} else if (blueness >= BRIGHTNESS_DECAY) { | |
blueness = blueness - BRIGHTNESS_DECAY; | |
} else { | |
blueness = 0; | |
} |
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
bool has_beat(sample_t *audio_left, sample_t *audio_right, jack_nframes_t num_samples) { | |
static movingAverage_t *moving_avg = NULL; | |
if (moving_avg == NULL) { | |
moving_avg = movingAverage_new(FILTER_SAMPLES); | |
} | |
// beat detected if volume much higher than moving avg | |
double volume = calc_volume(audio_left, audio_right, num_samples); | |
bool beat_detected = | |
volume * FILTER_SAMPLES > BEAT_FACTOR * moving_avg->average; |
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
typedef struct { | |
double average; | |
size_t oldest_index; | |
double *samples; | |
size_t num_samples; | |
} movingAverage_t; | |
void movingAverage_update(movingAverage_t *ma, double new_sample) { | |
ma->average -= ma->samples[ma->oldest_index]; | |
ma->samples[ma->oldest_index] = new_sample; |
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 <stdlib.h> | |
#include "moving_average.h" | |
movingAverage_t* movingAverage_new(size_t num_samples) { | |
movingAverage_t *ma = malloc(sizeof(movingAverage_t)); | |
ma->samples = malloc(num_samples * sizeof(double)); | |
ma->oldest_index = 0; | |
ma->num_samples = num_samples; | |
} | |