|
@@ -65,12 +65,15 @@ float freqs[NSAMP];
|
|
|
float freqsInLog[NSAMP];
|
|
float freqsInLog[NSAMP];
|
|
|
float power[NSAMP / 2];
|
|
float power[NSAMP / 2];
|
|
|
float powerInLog[NUM_PIXELS];
|
|
float powerInLog[NUM_PIXELS];
|
|
|
|
|
+float powerBuffer[NUM_PIXELS];
|
|
|
|
|
|
|
|
uint8_t cap_buf[NSAMP];
|
|
uint8_t cap_buf[NSAMP];
|
|
|
uint8_t cap_res[NSAMP];
|
|
uint8_t cap_res[NSAMP];
|
|
|
|
|
|
|
|
uint64_t lastColorChange;
|
|
uint64_t lastColorChange;
|
|
|
|
|
|
|
|
|
|
+double soundVolume = 1;
|
|
|
|
|
+
|
|
|
void setup();
|
|
void setup();
|
|
|
|
|
|
|
|
void sample(uint8_t *capture_buf);
|
|
void sample(uint8_t *capture_buf);
|
|
@@ -80,7 +83,8 @@ void startSample();
|
|
|
rgb hsv2rgb(double h, double s, double v);
|
|
rgb hsv2rgb(double h, double s, double v);
|
|
|
|
|
|
|
|
int main() {
|
|
int main() {
|
|
|
-
|
|
|
|
|
|
|
+ stdio_init_all();
|
|
|
|
|
+ printf("Boot");
|
|
|
|
|
|
|
|
kiss_fft_scalar fft_in[NSAMP]; // kiss_fft_scalar is a float
|
|
kiss_fft_scalar fft_in[NSAMP]; // kiss_fft_scalar is a float
|
|
|
kiss_fft_cpx fft_out[NSAMP];
|
|
kiss_fft_cpx fft_out[NSAMP];
|
|
@@ -112,7 +116,7 @@ int main() {
|
|
|
|
|
|
|
|
// any frequency bin over NSAMP/2 is aliased (nyquist sampling theorum)
|
|
// any frequency bin over NSAMP/2 is aliased (nyquist sampling theorum)
|
|
|
for (int i = 0; i < NSAMP / 2; i++) {
|
|
for (int i = 0; i < NSAMP / 2; i++) {
|
|
|
- power[i] = fft_out[i].r * fft_out[i].r + fft_out[i].i * fft_out[i].i;
|
|
|
|
|
|
|
+ power[i] = (fft_out[i].r * fft_out[i].r + fft_out[i].i * fft_out[i].i) * soundVolume;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
float f_max = FSAMP;
|
|
float f_max = FSAMP;
|
|
@@ -146,12 +150,20 @@ int main() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < NUM_PIXELS; i++) {
|
|
for (int i = 0; i < NUM_PIXELS; i++) {
|
|
|
- //uint32_t value = (uint32_t)(fmin(255, powerInLog[i]/400.0 * 255));
|
|
|
|
|
- rgb color = hsv2rgb(359 - fmin(359, powerInLog[i]/200.0 * 359), 1, fmin(0.5, powerInLog[i]/100.0));
|
|
|
|
|
- //printf("power = %f, color = %f, %f, %f\n", powerInLog[i]/200.0, color.r, color.g, color.b);
|
|
|
|
|
- uint32_t value = ((uint32_t)(fmin(color.r, 1) * 255) << 8) | ((uint32_t)(fmin(color.g, 1) * 255) << 16) | (uint32_t)(fmin(color.b, 1) * 255);
|
|
|
|
|
- //printf("b = %f\n", color.b*255);
|
|
|
|
|
- //printf("Color = %lu, pixel = %d\n", value, i);
|
|
|
|
|
|
|
+ //rgb color = hsv2rgb(359 - fmin(359, powerInLog[i]/200.0 * 359), 1, fmin(0.5, powerInLog[i]/100.0));
|
|
|
|
|
+ //uint32_t value = ((uint32_t)(fmin(color.r, 1) * 255) << 8) | ((uint32_t)(fmin(color.g, 1) * 255) << 16) | (uint32_t)(fmin(color.b, 1) * 255);
|
|
|
|
|
+ float newPower = powerInLog[i] * pow(fmax(fmax(i, 100)-99, 1), 1.05); //frequencyAmplitudeBias for top 50 pixels
|
|
|
|
|
+ float power = newPower;
|
|
|
|
|
+ if (newPower < powerBuffer[i]) {
|
|
|
|
|
+ power = (newPower + powerBuffer[i])/2;
|
|
|
|
|
+ }
|
|
|
|
|
+ powerBuffer[i] = power;
|
|
|
|
|
+ uint8_t r = fmin(255, ((power-50)/60.0) * 255);
|
|
|
|
|
+ uint8_t g = fmin(1, power/100.0)*255 - r;
|
|
|
|
|
+ uint8_t b = fmax(0, (power-250)/10)*255; //Blue has very high threshold
|
|
|
|
|
+
|
|
|
|
|
+ uint32_t value = (uint32_t) r << 8 | (uint32_t) g << 16 | (uint32_t) b;
|
|
|
|
|
+
|
|
|
put_pixel(value);
|
|
put_pixel(value);
|
|
|
put_pixel(value);
|
|
put_pixel(value);
|
|
|
}
|
|
}
|
|
@@ -239,28 +251,34 @@ void sample(uint8_t *capture_buf) {
|
|
|
|
|
|
|
|
void startSample() {
|
|
void startSample() {
|
|
|
while(1) {
|
|
while(1) {
|
|
|
- adc_fifo_drain();
|
|
|
|
|
- adc_run(false);
|
|
|
|
|
-
|
|
|
|
|
- dma_channel_configure(dma_chan, &cfg,
|
|
|
|
|
- cap_buf, // dst
|
|
|
|
|
- &adc_hw->fifo, // src
|
|
|
|
|
- NSAMP, // transfer count
|
|
|
|
|
- true // start immediately
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- gpio_put(LED_PIN, 1);
|
|
|
|
|
- adc_run(true);
|
|
|
|
|
- dma_channel_wait_for_finish_blocking(dma_chan);
|
|
|
|
|
- gpio_put(LED_PIN, 0);
|
|
|
|
|
-
|
|
|
|
|
- memcpy(cap_res, cap_buf, sizeof cap_res);
|
|
|
|
|
|
|
+ for (int i = 0; i < 20; i++) {
|
|
|
|
|
+ adc_select_input(CAPTURE_CHANNEL);
|
|
|
|
|
+ adc_fifo_drain();
|
|
|
|
|
+ adc_run(false);
|
|
|
|
|
+
|
|
|
|
|
+ dma_channel_configure(dma_chan, &cfg,
|
|
|
|
|
+ cap_buf, // dst
|
|
|
|
|
+ &adc_hw->fifo, // src
|
|
|
|
|
+ NSAMP, // transfer count
|
|
|
|
|
+ true // start immediately
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ gpio_put(LED_PIN, 1);
|
|
|
|
|
+ adc_run(true);
|
|
|
|
|
+ dma_channel_wait_for_finish_blocking(dma_chan);
|
|
|
|
|
+ gpio_put(LED_PIN, 0);
|
|
|
|
|
+
|
|
|
|
|
+ memcpy(cap_res, cap_buf, sizeof cap_res);
|
|
|
|
|
+ }
|
|
|
|
|
+ adc_select_input(1);
|
|
|
|
|
+ uint16_t volume = adc_read();
|
|
|
|
|
+ soundVolume = fmax(volume / 2048.0 - 0.2, 0);
|
|
|
|
|
+ //printf("Volume = %f, adc value = %d\n", soundVolume, volume);
|
|
|
|
|
+ sleep_us(100);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
|
void setup() {
|
|
|
- stdio_init_all();
|
|
|
|
|
-
|
|
|
|
|
// todo get free sm
|
|
// todo get free sm
|
|
|
PIO pio = pio0;
|
|
PIO pio = pio0;
|
|
|
int sm = 0;
|
|
int sm = 0;
|
|
@@ -270,6 +288,7 @@ void setup() {
|
|
|
//gpio_init(LED_PIN);
|
|
//gpio_init(LED_PIN);
|
|
|
//gpio_set_dir(LED_PIN, GPIO_OUT);
|
|
//gpio_set_dir(LED_PIN, GPIO_OUT);
|
|
|
|
|
|
|
|
|
|
+ adc_gpio_init(27); //For volume potentiometer
|
|
|
adc_gpio_init(26 + CAPTURE_CHANNEL);
|
|
adc_gpio_init(26 + CAPTURE_CHANNEL);
|
|
|
|
|
|
|
|
adc_init();
|
|
adc_init();
|