forked from W4D/soundcube-firmware
sampling in progress
This commit is contained in:
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoJson.hpp>
|
#include <ArduinoJson.hpp>
|
||||||
|
|
||||||
@ -25,8 +24,6 @@ int16_t buffer[BUFFERSIZE];
|
|||||||
|
|
||||||
WaveStream stream[NSTREAMS];
|
WaveStream stream[NSTREAMS];
|
||||||
|
|
||||||
bool streams_loaded = false;
|
|
||||||
|
|
||||||
I2S i2s(INPUT_PULLUP);
|
I2S i2s(INPUT_PULLUP);
|
||||||
|
|
||||||
TLV320AIC3204 codec;
|
TLV320AIC3204 codec;
|
||||||
@ -38,7 +35,7 @@ DAC8552 dac(9, &SPI1);
|
|||||||
|
|
||||||
PWMAudio ui_snd(8);
|
PWMAudio ui_snd(8);
|
||||||
|
|
||||||
enum STATE {IDLE, MODE_A, MODE_B, MODE_C};
|
enum STATE {IDLE, BANK_A, BANK_B, BANK_C, BANK_D, CTEMPO};
|
||||||
STATE state = IDLE;
|
STATE state = IDLE;
|
||||||
|
|
||||||
//enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
//enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
@ -51,8 +48,6 @@ int lut_matrix[13] = {56,55,57,58,59,62,61,60,63,64,65,67,66};
|
|||||||
int active = 0;
|
int active = 0;
|
||||||
int active_led_ring = 0;
|
int active_led_ring = 0;
|
||||||
|
|
||||||
bool speakerToggle = false;
|
|
||||||
|
|
||||||
uint32_t lastTime = 0;
|
uint32_t lastTime = 0;
|
||||||
int32_t position = 0;
|
int32_t position = 0;
|
||||||
|
|
||||||
@ -60,13 +55,18 @@ CRGB ui_leds[74];
|
|||||||
CRGB edge_leds[11];
|
CRGB edge_leds[11];
|
||||||
|
|
||||||
volatile bool buttonChanged = false;
|
volatile bool buttonChanged = false;
|
||||||
volatile bool ui_click = false;
|
|
||||||
volatile bool ui_beep = false;
|
|
||||||
volatile bool amp = false;
|
|
||||||
|
|
||||||
int counter = 0;
|
bool ui_click = false;
|
||||||
|
bool ui_beep = false;
|
||||||
|
bool amp = false;
|
||||||
|
bool streams_loaded = false;
|
||||||
|
bool speakerToggle = false;
|
||||||
|
bool sd_card_detected = false;
|
||||||
|
|
||||||
bool buttons[16] = {false};
|
bool buttons[16] = {false};
|
||||||
|
int buttonsDir[16] = {0};
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
int16_t ui_click_snd[UI_SAMPLERATE];
|
int16_t ui_click_snd[UI_SAMPLERATE];
|
||||||
uint16_t click_length = 0;
|
uint16_t click_length = 0;
|
||||||
@ -74,8 +74,6 @@ uint16_t click_length = 0;
|
|||||||
int16_t ui_beep_snd[UI_SAMPLERATE];
|
int16_t ui_beep_snd[UI_SAMPLERATE];
|
||||||
uint16_t beep_length = 0;
|
uint16_t beep_length = 0;
|
||||||
|
|
||||||
bool sd_card_detected = false;
|
|
||||||
|
|
||||||
struct Color {
|
struct Color {
|
||||||
int r;
|
int r;
|
||||||
int g;
|
int g;
|
||||||
@ -269,6 +267,46 @@ void speaker(bool state){
|
|||||||
digitalWrite(13, state ? HIGH : LOW);
|
digitalWrite(13, state ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Vibration{
|
||||||
|
int32_t last;
|
||||||
|
bool start = false;
|
||||||
|
bool wait = false;
|
||||||
|
uint16_t on = 0;
|
||||||
|
uint16_t off = 0;
|
||||||
|
int n = 1;
|
||||||
|
|
||||||
|
void update(){
|
||||||
|
int32_t delta = millis() - last;
|
||||||
|
|
||||||
|
if(start && !wait){
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
start = false;
|
||||||
|
wait = true;
|
||||||
|
last = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(delta >= on && wait){
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
wait = false;
|
||||||
|
n--;
|
||||||
|
last = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(delta >= off && n > 0){
|
||||||
|
start = true;
|
||||||
|
last = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void trigger(int _n, int _on, int _off){
|
||||||
|
n = _n;
|
||||||
|
on = _on;
|
||||||
|
off = _off;
|
||||||
|
start = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Vibration vibration;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin();
|
Serial.begin();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@ -380,29 +418,43 @@ void setup() {
|
|||||||
digitalWrite(6, LOW);
|
digitalWrite(6, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dactest = false;
|
|
||||||
uint32_t last = 0;
|
uint32_t last = 0;
|
||||||
bool tick = false;
|
|
||||||
int bar = 0;
|
int bar = 0;
|
||||||
int bar_old = -1;
|
int bar_old = -1;
|
||||||
int set_bar = 0;
|
int set_bar = 0;
|
||||||
|
int16_t angle = 0;
|
||||||
|
int32_t position_last = 0;
|
||||||
|
int16_t encdelta_raw = 0;
|
||||||
|
int16_t encdeltadiv = 1;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
position = ENC.getCumulativePosition();
|
position = ENC.getCumulativePosition();
|
||||||
|
angle = ENC.readAngle();
|
||||||
|
encdelta_raw += (position - position_last);
|
||||||
|
|
||||||
|
int encdelta = 0;
|
||||||
|
if(abs(encdelta_raw) > encdeltadiv) {
|
||||||
|
encdelta = encdelta_raw > 0 ? 1 : -1;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print(angle);
|
||||||
|
Serial.print(" \t");
|
||||||
|
Serial.print(position);
|
||||||
|
Serial.print(" \t");
|
||||||
|
Serial.print(encdelta_raw);
|
||||||
|
Serial.print(" \t");
|
||||||
|
Serial.println(encdelta);
|
||||||
|
|
||||||
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
||||||
|
|
||||||
if(millis() - last >= delta_bpm) {
|
if(millis() - last >= delta_bpm) {
|
||||||
tick = true;
|
bar = (bar + 1) % 16;
|
||||||
last = millis();
|
last = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tick) bar = (bar + 1) % 16;
|
|
||||||
tick = false;
|
|
||||||
|
|
||||||
sd_card_detected = !digitalRead(21);
|
sd_card_detected = !digitalRead(21);
|
||||||
if(sd_card_detected) edge_leds[8] = CRGB(0,10,0);
|
edge_leds[8] = sd_card_detected ? CRGB(0,10,0) : CRGB(10,0,0);
|
||||||
if(!sd_card_detected) edge_leds[8] = CRGB(10,0,0);
|
|
||||||
|
|
||||||
// EDGE LEDs
|
// EDGE LEDs
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
@ -424,18 +476,18 @@ void loop() {
|
|||||||
int buttonValues = TCA.read16();
|
int buttonValues = TCA.read16();
|
||||||
|
|
||||||
bool buttonsNew[16] = {false};
|
bool buttonsNew[16] = {false};
|
||||||
int buttonsDir[16] = {0};
|
|
||||||
|
|
||||||
bool buttonUp = false;
|
bool buttonUp = false;
|
||||||
bool buttonDown = false;
|
bool buttonDown = false;
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++){
|
for(int i = 0; i < 16; i++){
|
||||||
buttonsNew[i] = ~(buttonValues >> i) & 0x01;
|
buttonsNew[i] = ~(buttonValues >> i) & 0x01;
|
||||||
if(buttonsNew[i] == true && buttons[i] == false) {
|
if(buttonsNew[i] == true && buttons[i] == false) {
|
||||||
buttonsDir[i] = 1;
|
buttonsDir[i] = -1;
|
||||||
buttonDown = true;
|
buttonDown = true;
|
||||||
}
|
}
|
||||||
if(buttonsNew[i] == false && buttons[i] == true) {
|
if(buttonsNew[i] == false && buttons[i] == true) {
|
||||||
buttonsDir[i] = -1;
|
buttonsDir[i] = 1;
|
||||||
buttonUp = true;
|
buttonUp = true;
|
||||||
}
|
}
|
||||||
buttons[i] = buttonsNew[i];
|
buttons[i] = buttonsNew[i];
|
||||||
@ -443,9 +495,7 @@ void loop() {
|
|||||||
|
|
||||||
// Make vibration
|
// Make vibration
|
||||||
if(HAPTIC && buttonDown) {
|
if(HAPTIC && buttonDown) {
|
||||||
digitalWrite(6, HIGH);
|
vibration.trigger(1, 25, 25);
|
||||||
delay(50);
|
|
||||||
digitalWrite(6, LOW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make beep
|
// Make beep
|
||||||
@ -454,10 +504,47 @@ void loop() {
|
|||||||
ui_click = true;
|
ui_click = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(buttons[TEMPO]){
|
||||||
|
state = CTEMPO;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(state){
|
||||||
|
case IDLE:
|
||||||
|
break;
|
||||||
|
case BANK_A:
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
int n = steps[set_bar].len;
|
||||||
|
steps[set_bar].samples[n] = &samples[0];
|
||||||
|
steps[set_bar].len = (steps[set_bar].len + 1) % 4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BANK_B:
|
||||||
|
break;
|
||||||
|
case BANK_C:
|
||||||
|
break;
|
||||||
|
case BANK_D:
|
||||||
|
break;
|
||||||
|
case CTEMPO:
|
||||||
|
encdeltadiv = 64;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
state = IDLE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Set bar
|
// Set bar
|
||||||
// if(buttons[BACK]) set_bar++;
|
// if(buttons[BACK]) set_bar++;
|
||||||
// if(buttons[POWER]) set_bar--;
|
// if(buttons[POWER]) set_bar--;
|
||||||
|
|
||||||
|
if(buttons[SELECT]){
|
||||||
|
// Flash encoder leds
|
||||||
|
ui_leds[0] = CRGB(0, 100, 50);
|
||||||
|
ui_leds[1] = CRGB(0, 100, 50);
|
||||||
|
ui_leds[2] = CRGB(0, 100, 50);
|
||||||
|
}
|
||||||
|
|
||||||
if(buttons[DEBUG1]) {
|
if(buttons[DEBUG1]) {
|
||||||
Serial.println("vol down");
|
Serial.println("vol down");
|
||||||
codec.volumeDown();
|
codec.volumeDown();
|
||||||
@ -473,19 +560,6 @@ void loop() {
|
|||||||
speaker(speakerToggle);
|
speaker(speakerToggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[SELECT]){
|
|
||||||
//stream[active % NSTREAMS].toggle();
|
|
||||||
//ui_beep = true;
|
|
||||||
|
|
||||||
int n = steps[set_bar].len;
|
|
||||||
steps[set_bar].samples[n] = &samples[0];
|
|
||||||
steps[set_bar].len = (steps[set_bar].len + 1) % 4;
|
|
||||||
|
|
||||||
// Flash encoder leds
|
|
||||||
ui_leds[0] = CRGB(0, 100, 50);
|
|
||||||
ui_leds[1] = CRGB(0, 100, 50);
|
|
||||||
ui_leds[2] = CRGB(0, 100, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(codec.getVolumeL());
|
Serial.println(codec.getVolumeL());
|
||||||
|
|
||||||
@ -493,10 +567,26 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(position < 0) position += 4096;
|
if(position < 0) position += 4096;
|
||||||
set_bar = (position / 256) % 16;
|
|
||||||
|
|
||||||
// if(set_bar == 16) set_bar = 0;
|
switch(state){
|
||||||
// if(set_bar == -1) set_bar = 15;
|
case IDLE:
|
||||||
|
break;
|
||||||
|
case BANK_A:
|
||||||
|
set_bar = (position / 256) % 16;
|
||||||
|
break;
|
||||||
|
case BANK_B:
|
||||||
|
break;
|
||||||
|
case BANK_C:
|
||||||
|
break;
|
||||||
|
case BANK_D:
|
||||||
|
break;
|
||||||
|
case CTEMPO:
|
||||||
|
config.bpm += encdelta;
|
||||||
|
if(config.bpm < 15) config.bpm = 15;
|
||||||
|
if(config.bpm > 300) config.bpm = 300;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//dac.setValue(0, dactest ? 0 : sin((float)millis() / 100.0f) * 32768 + 32768);
|
//dac.setValue(0, dactest ? 0 : sin((float)millis() / 100.0f) * 32768 + 32768);
|
||||||
|
|
||||||
@ -545,9 +635,17 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(buttonChanged){
|
||||||
|
for(int i = 0; i < 16; i++){
|
||||||
|
if(buttonsDir[i] == 1) buttonsDir[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(i2s.getOverflow()) Serial.println("overflow");
|
if(i2s.getOverflow()) Serial.println("overflow");
|
||||||
if(i2s.getUnderflow()) Serial.println("underflow");
|
if(i2s.getUnderflow()) Serial.println("underflow");
|
||||||
|
|
||||||
//delay(20); // wait 1ms
|
//delay(20); // wait 1ms
|
||||||
bar_old = bar;
|
bar_old = bar;
|
||||||
|
vibration.update();
|
||||||
|
position_last = position;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user