forked from W4D/soundcube-firmware
ringbuffer skeleton added
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
#include <RingBuf.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoJson.hpp>
|
||||
|
||||
@ -10,16 +11,20 @@
|
||||
#include <SD.h>
|
||||
#include "codec.h"
|
||||
|
||||
|
||||
#define HAPTIC 1
|
||||
#define AURAL 1
|
||||
#define UI_SAMPLERATE 22050
|
||||
|
||||
#define SIZE 256
|
||||
#define RINGBUFFER 1024
|
||||
#define ECHO 96000
|
||||
int16_t buffer[SIZE];
|
||||
int16_t buffer2[ECHO];
|
||||
|
||||
RingBuf<int16_t, RINGBUFFER> ringbuffer;
|
||||
|
||||
File stream1;
|
||||
|
||||
I2S i2s(INPUT_PULLUP);
|
||||
|
||||
TLV320AIC3204 codec;
|
||||
@ -88,6 +93,11 @@ void codec_transmit() {
|
||||
// if(tape_read < 0) tape_read += ECHO;
|
||||
// buffer[i] += buffer2[tape_read % ECHO];
|
||||
// }
|
||||
|
||||
for(int i = 0; i < count; i++){
|
||||
buffer[i] += ringbuffer.pop();
|
||||
}
|
||||
|
||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||
}
|
||||
|
||||
@ -126,6 +136,12 @@ void setup() {
|
||||
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
|
||||
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
|
||||
|
||||
pinMode(12, OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
|
||||
digitalWrite(12, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
pinMode(21, INPUT_PULLUP);
|
||||
sd_card_detected = !digitalRead(21);
|
||||
delay(500);
|
||||
@ -218,6 +234,10 @@ void setup() {
|
||||
while(100);
|
||||
}
|
||||
|
||||
if(sdInitialized && SD.exists("/piano.wav")) {
|
||||
stream1 = SD.open("/piano.wav");
|
||||
}
|
||||
|
||||
digitalWrite(6, HIGH);
|
||||
delay(50);
|
||||
digitalWrite(6, LOW);
|
||||
@ -236,6 +256,14 @@ void loop() {
|
||||
if(sd_card_detected) edge_leds[8] = CRGB(0,10,0);
|
||||
if(!sd_card_detected) edge_leds[8] = CRGB(10,0,0);
|
||||
|
||||
if(!ringbuffer.isFull()){
|
||||
while (!ringbuffer.isFull()) {
|
||||
int16_t sample = stream1.read();
|
||||
ringbuffer.push(sample);
|
||||
if(!stream1.available()) stream1.seek(0, SeekSet);
|
||||
}
|
||||
}
|
||||
|
||||
// EDGE LEDs
|
||||
for (int i = 0; i < 8; i++) {
|
||||
edge_leds[i] = CRGB(config.edge_color_r, config.edge_color_g, config.edge_color_b);
|
||||
@ -294,6 +322,14 @@ void loop() {
|
||||
// set active LED matrix LED
|
||||
ui_leds[lut_matrix[active]] = CRGB(100, 100, 100);
|
||||
|
||||
if(active == 1) {
|
||||
digitalWrite(12, HIGH);
|
||||
digitalWrite(13, HIGH);
|
||||
} else {
|
||||
digitalWrite(12, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
|
||||
if(position < 0) position += 4096;
|
||||
active_led_ring = (position / 32) % 48;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user