forked from W4D/soundcube-firmware
Compare commits
7 Commits
v.0.0.5
...
v0.1.0-sam
| Author | SHA1 | Date | |
|---|---|---|---|
| 8858d41806 | |||
| ffdbe9fa6d | |||
| 6ef94390a5 | |||
| 6dd3acac2f | |||
| 4a04e95757 | |||
| 06642bd570 | |||
| 07323ec068 |
70
README.md
70
README.md
@ -13,9 +13,8 @@
|
|||||||
## SD Card contents
|
## SD Card contents
|
||||||
|
|
||||||
|
|
||||||
´´´
|
```
|
||||||
config.txt
|
config.txt
|
||||||
click.wav
|
|
||||||
sound/
|
sound/
|
||||||
├─ 1.wav
|
├─ 1.wav
|
||||||
├─ 2.wav
|
├─ 2.wav
|
||||||
@ -25,8 +24,11 @@ sound/
|
|||||||
├─ 6.wav
|
├─ 6.wav
|
||||||
├─ 7.wav
|
├─ 7.wav
|
||||||
├─ 8.wav
|
├─ 8.wav
|
||||||
|
ui/
|
||||||
|
├─ click.wav
|
||||||
|
├─ beep.wav
|
||||||
|
|
||||||
´´´
|
```
|
||||||
|
|
||||||
### config.txt
|
### config.txt
|
||||||
|
|
||||||
@ -34,45 +36,89 @@ Json formatted config file. For now only edge led color working.
|
|||||||
|
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
|
"boxid":"",
|
||||||
"edge": {
|
"edge": {
|
||||||
"color":{
|
"color":{
|
||||||
"r":50,
|
"idle":{
|
||||||
"g":0,
|
"r":50,
|
||||||
"b":0
|
"g":0,
|
||||||
|
"b":50
|
||||||
|
},
|
||||||
|
"active":{
|
||||||
|
"r":0,
|
||||||
|
"g":50,
|
||||||
|
"b":50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ring": {
|
||||||
|
"color":{
|
||||||
|
"idle":{
|
||||||
|
"r":0,
|
||||||
|
"g":50,
|
||||||
|
"b":50
|
||||||
|
},
|
||||||
|
"active":{
|
||||||
|
"r":0,
|
||||||
|
"g":80,
|
||||||
|
"b":50
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### click.wav
|
## Sound
|
||||||
|
|
||||||
Put a file called `click.wav` (not longer than a few seconds) in the root of the SD card and it will play when you press a button.
|
### UI
|
||||||
|
|
||||||
|
There are two UI sounds - `click.wav` and `beep.wav`.
|
||||||
|
|
||||||
|
- `click.wav` is played when a button is pressed other than the select button
|
||||||
|
- `beep.wav` is played when the rotary encoder select button is pressed
|
||||||
|
|
||||||
|
Put these files in the subfolder `ui` on the SD card.
|
||||||
|
|
||||||
|
#### Wave File Format for UI Sounds
|
||||||
|
|
||||||
|
`click.wav` needs to be **22050Hz (22kHz) 16bit Mono**
|
||||||
|
|
||||||
|
|
||||||
### Sounds
|
### Audio Out or Speakers
|
||||||
|
|
||||||
Put all sounds into the ´/sound´ subfolder. Name them ´1.wav, 2.wav, 3.wav...´
|
Put all sounds into the `/sound` subfolder. Name them `1.wav, 2.wav, 3.wav...`
|
||||||
|
|
||||||
|
|
||||||
## Wave File Format
|
#### Wave File Format for Audio Out and Speakers
|
||||||
|
|
||||||
|
Export all sounds as **48000Hz (48kHz) 16bit Stereo**.
|
||||||
|
|
||||||
Export all sounds except ´click.wav´ as **48000Hz (48kHz) 16bit Stereo**.
|
|
||||||
|
|
||||||
### Audacity
|
### Audacity
|
||||||
|
|
||||||
You can use Audacity to export all soundfiles to WAV format.
|
You can use Audacity to export all soundfiles to WAV format.
|
||||||
|
|
||||||
|
Download it here [Github](https://github.com/audacity/audacity/releases)
|
||||||
|
|
||||||
1. Load file into Audacity
|
1. Load file into Audacity
|
||||||
2. Select Track
|
2. Select Track
|
||||||
3. File -> Export Audio
|
3. File -> Export Audio
|
||||||
|
|
||||||
#### Format options in Audacity
|
#### Format options in Audacity
|
||||||
|
|
||||||
|
**Audio Out**
|
||||||
|
|
||||||
- WAV(Microsoft)
|
- WAV(Microsoft)
|
||||||
- Chanels: Stereo
|
- Chanels: Stereo
|
||||||
- Samplerate: 48000Hz
|
- Samplerate: 48000Hz
|
||||||
- Encoding: Signed 16-bit PCM
|
- Encoding: Signed 16-bit PCM
|
||||||
|
|
||||||
|
**UI**
|
||||||
|
|
||||||
|
- WAV(Microsoft)
|
||||||
|
- Channels: Mono
|
||||||
|
- Samplerate: 22050Hz
|
||||||
|
- Encoding: Signed 16-bit PCM
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoJson.hpp>
|
#include <ArduinoJson.hpp>
|
||||||
|
|
||||||
@ -19,14 +18,12 @@
|
|||||||
#define UI_SAMPLERATE 22050
|
#define UI_SAMPLERATE 22050
|
||||||
|
|
||||||
#define BUFFERSIZE 64
|
#define BUFFERSIZE 64
|
||||||
#define NSTREAMS 8
|
#define NSTREAMS 16
|
||||||
|
|
||||||
int16_t buffer[BUFFERSIZE];
|
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,16 +35,24 @@ DAC8552 dac(9, &SPI1);
|
|||||||
|
|
||||||
PWMAudio ui_snd(8);
|
PWMAudio ui_snd(8);
|
||||||
|
|
||||||
enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
enum STATE {BANK, SAMPLE, SEQUENCE, CTEMPO};
|
||||||
|
STATE state = BANK;
|
||||||
|
|
||||||
|
//enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
|
enum BUTTON {MODE, LOOP, INL, INR, OUTR, OUTL, TEMPO, RESET, BACK, POWER, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
|
|
||||||
int lut_ring_cw[48] = {39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,50,49,48,47,46,45,44,43,42,41,40};
|
int lut_ring_cw[48] = {39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,50,49,48,47,46,45,44,43,42,41,40};
|
||||||
int lut_ring_ccw[48] = {40,41,42,43,44,45,46,47,48,49,50,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
|
int lut_ring_ccw[48] = {40,41,42,43,44,45,46,47,48,49,50,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
|
||||||
int lut_matrix[13] = {56,55,57,58,59,62,61,60,63,64,65,67,66};
|
int lut_matrix[13] = {56,55,57,58,59,62,61,60,63,64,65,67,66};
|
||||||
|
|
||||||
|
int lut_banks[4] = {56,55,67,66};
|
||||||
|
int lut_samples[4] = {62,58,60,64};
|
||||||
|
|
||||||
int active = 0;
|
int active = 0;
|
||||||
int active_led_ring = 0;
|
int active_led_ring = 0;
|
||||||
|
|
||||||
bool speakerToggle = false;
|
int selected_bank = 0;
|
||||||
|
int selected_sample = 0;
|
||||||
|
|
||||||
uint32_t lastTime = 0;
|
uint32_t lastTime = 0;
|
||||||
int32_t position = 0;
|
int32_t position = 0;
|
||||||
@ -56,26 +61,63 @@ CRGB ui_leds[74];
|
|||||||
CRGB edge_leds[11];
|
CRGB edge_leds[11];
|
||||||
|
|
||||||
volatile bool buttonChanged = false;
|
volatile bool buttonChanged = false;
|
||||||
volatile bool click = false;
|
|
||||||
volatile bool amp = false;
|
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};
|
||||||
|
int buttonsDir[16] = {0};
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
bool buttons[16] = {false};
|
int16_t ui_click_snd[UI_SAMPLERATE];
|
||||||
|
uint16_t click_length = 0;
|
||||||
|
|
||||||
int16_t beep[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 {
|
||||||
|
int r;
|
||||||
|
int g;
|
||||||
|
int b;
|
||||||
|
int r_active;
|
||||||
|
int g_active;
|
||||||
|
int b_active;
|
||||||
|
};
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
int edge_color_r = 0;
|
String boxid = "";
|
||||||
int edge_color_g = 0;
|
Color edge_color = {0,0,50,0,50,0};
|
||||||
int edge_color_b = 50;
|
Color ring_color = {0,50,50,0,80,50};
|
||||||
|
String sampleFiles[16];
|
||||||
|
int bpm = 90;
|
||||||
};
|
};
|
||||||
|
|
||||||
Config config;
|
Config config;
|
||||||
|
|
||||||
|
struct Sample{
|
||||||
|
float volume = 1.0;
|
||||||
|
WaveStream *file;
|
||||||
|
};
|
||||||
|
|
||||||
|
Sample samples[NSTREAMS];
|
||||||
|
|
||||||
|
struct SequenceStep{
|
||||||
|
int len = 0;
|
||||||
|
Sample *samples[4];
|
||||||
|
void trigger(){
|
||||||
|
for(int i = 0; i < len; i++){
|
||||||
|
samples[i]->file->play(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SequenceStep steps[16];
|
||||||
|
|
||||||
void loadConfiguration(Config& config) {
|
void loadConfiguration(Config& config) {
|
||||||
File file = SD.open("/config.txt");
|
File file = SD.open("/config.txt");
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
@ -83,11 +125,27 @@ void loadConfiguration(Config& config) {
|
|||||||
DeserializationError error = deserializeJson(doc, file);
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
if(error) Serial.println(F("Failed to read file, using default configuration"));
|
if(error) Serial.println(F("Failed to read file, using default configuration"));
|
||||||
|
|
||||||
config.edge_color_r = doc["edge"]["color"]["r"] | 0;
|
config.edge_color.r = doc["edge"]["color"]["idle"]["r"] | 0;
|
||||||
config.edge_color_g = doc["edge"]["color"]["g"] | 0;
|
config.edge_color.g = doc["edge"]["color"]["idle"]["g"] | 0;
|
||||||
config.edge_color_b = doc["edge"]["color"]["b"] | 50;
|
config.edge_color.b = doc["edge"]["color"]["idle"]["b"] | 50;
|
||||||
|
config.edge_color.r_active = doc["edge"]["color"]["active"]["r"] | 0;
|
||||||
|
config.edge_color.g_active = doc["edge"]["color"]["active"]["g"] | 50;
|
||||||
|
config.edge_color.b_active = doc["edge"]["color"]["active"]["b"] | 0;
|
||||||
|
|
||||||
//strlcpy(config.hostname, doc["hostname"] | "example.com", sizeof(config.hostname));
|
config.ring_color.r = doc["ring"]["color"]["idle"]["r"] | 0;
|
||||||
|
config.ring_color.g = doc["ring"]["color"]["idle"]["g"] | 50;
|
||||||
|
config.ring_color.b = doc["ring"]["color"]["idle"]["b"] | 50;
|
||||||
|
config.ring_color.r_active = doc["ring"]["color"]["active"]["r"] | 0;
|
||||||
|
config.ring_color.g_active = doc["ring"]["color"]["active"]["g"] | 80;
|
||||||
|
config.ring_color.b_active = doc["ring"]["color"]["active"]["b"] | 50;
|
||||||
|
|
||||||
|
JsonArray _sampleFiles = doc["samples"];
|
||||||
|
config.boxid = doc["boxid"].as<String>();
|
||||||
|
int i = 0;
|
||||||
|
for(JsonVariant item : _sampleFiles){
|
||||||
|
config.sampleFiles[i] = item.as<String>();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@ -116,13 +174,24 @@ void codec_receive(){
|
|||||||
|
|
||||||
void pwm_audio_callback() {
|
void pwm_audio_callback() {
|
||||||
while (ui_snd.availableForWrite()) {
|
while (ui_snd.availableForWrite()) {
|
||||||
if(click) {
|
if(ui_click || ui_beep) {
|
||||||
ui_snd.write(beep[counter]);
|
if(ui_beep) {
|
||||||
counter++;
|
ui_snd.write(ui_beep_snd[counter]);
|
||||||
if(counter == beep_length) {
|
counter++;
|
||||||
counter = 0;
|
if(counter == beep_length) {
|
||||||
click = false;
|
counter = 0;
|
||||||
|
ui_beep = false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if(ui_click) {
|
||||||
|
ui_snd.write(ui_click_snd[counter]);
|
||||||
|
counter++;
|
||||||
|
if(counter == click_length) {
|
||||||
|
counter = 0;
|
||||||
|
ui_click = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(7, LOW);
|
digitalWrite(7, LOW);
|
||||||
ui_snd.write(0);
|
ui_snd.write(0);
|
||||||
@ -131,6 +200,70 @@ void pwm_audio_callback() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool load_ui_sounds(const char* file, int16_t *buffer, uint16_t &length){
|
||||||
|
if(SD.exists(file)) {
|
||||||
|
File f_click = SD.open(file);
|
||||||
|
f_click.seek(44, SeekSet);
|
||||||
|
int click_bytes = 0;
|
||||||
|
while (f_click.available() && click_bytes < UI_SAMPLERATE) {
|
||||||
|
uint8_t samplebyte[2];
|
||||||
|
f_click.read(samplebyte, 2);
|
||||||
|
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
|
||||||
|
buffer[click_bytes] = sample;
|
||||||
|
click_bytes++;
|
||||||
|
}
|
||||||
|
f_click.close();
|
||||||
|
length = click_bytes;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
for(int i = 0; i < UI_SAMPLERATE; i++){
|
||||||
|
float sine_pos = (2.0f * M_PI * 3000.0f * (float)i) / (float)UI_SAMPLERATE;
|
||||||
|
buffer[i] = (int16_t)(sin(sine_pos) * 8000.0f);
|
||||||
|
}
|
||||||
|
Serial.println("Synthesized 8kHz sine into beep array.");
|
||||||
|
length = UI_SAMPLERATE;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool load_samples(){
|
||||||
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
|
stream[i].begin();
|
||||||
|
char filename[64];
|
||||||
|
sprintf(filename, "/sound/%s/%s", config.boxid.c_str(), config.sampleFiles[i].c_str());
|
||||||
|
Serial.println(filename);
|
||||||
|
|
||||||
|
if(SD.exists(filename)){
|
||||||
|
bool loaded = stream[i].load(SD.open(filename));
|
||||||
|
if(loaded) {
|
||||||
|
Serial.print("file read: ");
|
||||||
|
Serial.print(stream[i].wavefile.length);
|
||||||
|
Serial.print(" bytes | ");
|
||||||
|
Serial.print(stream[i].wavefile.samplerate);
|
||||||
|
Serial.print(" kHz | ");
|
||||||
|
Serial.print(stream[i].wavefile.bitspersample);
|
||||||
|
Serial.print(" bits | ");
|
||||||
|
Serial.print(stream[i].wavefile.channels);
|
||||||
|
Serial.print(" channels | ");
|
||||||
|
Serial.print(stream[i].wavefile.blockalign);
|
||||||
|
Serial.println(" bytes");
|
||||||
|
//stream[i].wavefile.loop = true;
|
||||||
|
} else {
|
||||||
|
Serial.println("file loading error");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(int k = 0; k < 3; k++){
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
delay(20);
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
delay(25);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void tca_irq() {
|
void tca_irq() {
|
||||||
buttonChanged = true;
|
buttonChanged = true;
|
||||||
}
|
}
|
||||||
@ -140,6 +273,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);
|
||||||
@ -170,27 +343,9 @@ void setup() {
|
|||||||
|
|
||||||
if(sdInitialized) loadConfiguration(config);
|
if(sdInitialized) loadConfiguration(config);
|
||||||
|
|
||||||
if(sdInitialized && SD.exists("/click.wav")) {
|
if(sdInitialized){
|
||||||
File click = SD.open("/click.wav");
|
load_ui_sounds("/ui/click.wav", ui_click_snd, click_length);
|
||||||
click.seek(44, SeekSet);
|
load_ui_sounds("/ui/beep.wav", ui_beep_snd, beep_length);
|
||||||
int click_bytes = 0;
|
|
||||||
while (click.available() || click_bytes == UI_SAMPLERATE-1) {
|
|
||||||
uint8_t samplebyte[2];
|
|
||||||
click.read(samplebyte, 2);
|
|
||||||
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
|
|
||||||
beep[click_bytes] = sample;
|
|
||||||
click_bytes++;
|
|
||||||
}
|
|
||||||
click.close();
|
|
||||||
beep_length = click_bytes;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
for(int i = 0; i < UI_SAMPLERATE; i++){
|
|
||||||
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
|
|
||||||
beep[i] = (int16_t)(sin(sine_pos) * 8000.0f);
|
|
||||||
}
|
|
||||||
Serial.println("Synthesized 8kHz sine into beep array.");
|
|
||||||
beep_length = UI_SAMPLERATE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("INIT WIRE");
|
Serial.println("INIT WIRE");
|
||||||
@ -212,7 +367,8 @@ void setup() {
|
|||||||
|
|
||||||
// Rotary Encoder
|
// Rotary Encoder
|
||||||
ENC.begin(); // set direction pin.
|
ENC.begin(); // set direction pin.
|
||||||
ENC.setDirection(AS5600_COUNTERCLOCK_WISE);
|
ENC.setDirection(AS5600_CLOCK_WISE);
|
||||||
|
ENC.resetCumulativePosition();
|
||||||
|
|
||||||
pinMode(6, OUTPUT); // Vibration Motor
|
pinMode(6, OUTPUT); // Vibration Motor
|
||||||
pinMode(7, OUTPUT); // UI Amp Enable
|
pinMode(7, OUTPUT); // UI Amp Enable
|
||||||
@ -220,7 +376,7 @@ void setup() {
|
|||||||
ui_snd.onTransmit(pwm_audio_callback);
|
ui_snd.onTransmit(pwm_audio_callback);
|
||||||
ui_snd.begin(UI_SAMPLERATE);
|
ui_snd.begin(UI_SAMPLERATE);
|
||||||
|
|
||||||
digitalWrite(7, LOW);
|
digitalWrite(7, LOW); // UI amp off
|
||||||
|
|
||||||
pinMode(19, OUTPUT); // MCLK enable
|
pinMode(19, OUTPUT); // MCLK enable
|
||||||
digitalWrite(19, HIGH); // enable MCLK
|
digitalWrite(19, HIGH); // enable MCLK
|
||||||
@ -250,41 +406,13 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(sdInitialized) {
|
if(sdInitialized) {
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
streams_loaded = load_samples();
|
||||||
stream[i].begin();
|
}
|
||||||
char filename[40];
|
|
||||||
sprintf(filename, "/sound/%d.wav", i+1);
|
|
||||||
if(SD.exists(filename)){
|
|
||||||
bool loaded = stream[i].load(SD.open(filename));
|
|
||||||
|
|
||||||
if(loaded) {
|
|
||||||
Serial.print("file read: ");
|
|
||||||
Serial.print(stream[i].wavefile.length);
|
|
||||||
Serial.print(" bytes | ");
|
|
||||||
Serial.print(stream[i].wavefile.samplerate);
|
|
||||||
Serial.print(" kHz | ");
|
|
||||||
Serial.print(stream[i].wavefile.bitspersample);
|
|
||||||
Serial.print(" bits | ");
|
|
||||||
Serial.print(stream[i].wavefile.channels);
|
|
||||||
Serial.print(" channels | ");
|
|
||||||
Serial.print(stream[i].wavefile.blockalign);
|
|
||||||
Serial.println(" bytes");
|
|
||||||
|
|
||||||
//stream[i].play();
|
if(streams_loaded) {
|
||||||
stream[i].wavefile.loop = true;
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
} else {
|
samples[i].file = &stream[i];
|
||||||
Serial.println("file loading error");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(int k = 0; k < 3; k++){
|
|
||||||
digitalWrite(6, HIGH);
|
|
||||||
delay(100);
|
|
||||||
digitalWrite(6, LOW);
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
streams_loaded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(6, HIGH);
|
digitalWrite(6, HIGH);
|
||||||
@ -294,21 +422,55 @@ void setup() {
|
|||||||
digitalWrite(6, HIGH);
|
digitalWrite(6, HIGH);
|
||||||
delay(25);
|
delay(25);
|
||||||
digitalWrite(6, LOW);
|
digitalWrite(6, LOW);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dactest = false;
|
uint32_t last = 0;
|
||||||
|
int bar = 0;
|
||||||
|
int bar_old = -1;
|
||||||
|
int set_bar = 0;
|
||||||
|
int16_t angle = 0;
|
||||||
|
int32_t position_last = 0;
|
||||||
|
|
||||||
|
int16_t encdelta_raw = 0;
|
||||||
|
int16_t encdeltadiv = 512;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
position = ENC.getCumulativePosition();
|
position = ENC.getCumulativePosition();
|
||||||
|
angle = ENC.readAngle();
|
||||||
|
encdelta_raw += (position - position_last);
|
||||||
|
|
||||||
|
// Serial.print(encdelta_raw);
|
||||||
|
// Serial.print(" \t");
|
||||||
|
|
||||||
|
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(position_last);
|
||||||
|
// Serial.print(" \t");
|
||||||
|
// Serial.print(encdelta_raw);
|
||||||
|
// Serial.print(" \t");
|
||||||
|
// Serial.println(encdelta);
|
||||||
|
|
||||||
|
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
||||||
|
|
||||||
|
if(millis() - last >= delta_bpm) {
|
||||||
|
bar = (bar + 1) % 16;
|
||||||
|
last = millis();
|
||||||
|
}
|
||||||
|
|
||||||
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++) {
|
||||||
edge_leds[i] = CRGB(config.edge_color_r, config.edge_color_g, config.edge_color_b);
|
edge_leds[i] = CRGB(config.edge_color.r, config.edge_color.g, config.edge_color.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LED Ring leeren
|
// LED Ring leeren
|
||||||
@ -326,101 +488,185 @@ 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
if (AURAL && buttonDown) {
|
if(AURAL && buttonDown) {
|
||||||
digitalWrite(7, HIGH);
|
digitalWrite(7, HIGH);
|
||||||
click = true;
|
ui_click = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flash encoder leds
|
if(buttons[TEMPO] && buttonDown){
|
||||||
ui_leds[0] = CRGB(0, 100, 50);
|
state = CTEMPO;
|
||||||
ui_leds[1] = CRGB(0, 100, 50);
|
}
|
||||||
ui_leds[2] = CRGB(0, 100, 50);
|
|
||||||
|
|
||||||
// Switch through LED matrix
|
if(buttons[BACK] && buttonDown){
|
||||||
if(buttons[RIGHT]) active++;
|
}
|
||||||
if(buttons[LEFT]) active--;
|
|
||||||
if(active == 13) active = 0;
|
switch(state){
|
||||||
if(active == -1) active = 12;
|
case BANK:
|
||||||
|
encdeltadiv = 512;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
state = SAMPLE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SAMPLE:
|
||||||
|
encdeltadiv = 512;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
state = SEQUENCE;
|
||||||
|
}
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
state = BANK;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SEQUENCE:
|
||||||
|
encdeltadiv = 256;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
int n = steps[set_bar].len;
|
||||||
|
steps[set_bar].samples[n] = &samples[selected_bank*4 + selected_sample];
|
||||||
|
steps[set_bar].len = (steps[set_bar].len + 1) % 4;
|
||||||
|
}
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
state = SAMPLE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CTEMPO:
|
||||||
|
encdeltadiv = 64;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
state = BANK;
|
||||||
|
}
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
state = BANK;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set bar
|
||||||
|
// if(buttons[BACK]) 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[CVINL]) {
|
if(buttons[DEBUG1]) {
|
||||||
Serial.println("vol down");
|
Serial.println("vol down");
|
||||||
codec.volumeDown();
|
codec.volumeDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[CVOUTL]) {
|
if(buttons[DEBUG3]) {
|
||||||
Serial.println("vol up");
|
Serial.println("vol up");
|
||||||
codec.volumeUp();
|
codec.volumeUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[DEBUG3]) {
|
if(buttons[DEBUG2]) {
|
||||||
speakerToggle = !speakerToggle;
|
speakerToggle = !speakerToggle;
|
||||||
speaker(speakerToggle);
|
speaker(speakerToggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[DEBUG2]) {
|
|
||||||
dactest = !dactest;
|
|
||||||
dac.setValue(0, dactest ? 0 : 32768);
|
|
||||||
dac.setValue(1, !dactest ? 0 : 65535);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(buttons[SELECT]){
|
|
||||||
stream[active % NSTREAMS].toggle();
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(codec.getVolumeL());
|
Serial.println(codec.getVolumeL());
|
||||||
|
|
||||||
//for(int i = 0; i < NSTREAMS; i++){
|
|
||||||
// stream[i].pause();
|
|
||||||
// }
|
|
||||||
//stream[active % NSTREAMS].play();
|
|
||||||
|
|
||||||
buttonChanged = false;
|
buttonChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if(position < 0) position += 4096;
|
||||||
|
|
||||||
|
switch(state){
|
||||||
|
case BANK:
|
||||||
|
selected_bank += encdelta;
|
||||||
|
if(selected_bank == 4) selected_bank = 0;
|
||||||
|
if(selected_bank == -1) selected_bank = 3;
|
||||||
|
break;
|
||||||
|
case SAMPLE:
|
||||||
|
selected_sample += encdelta;
|
||||||
|
if(selected_sample == 4) selected_sample = 0;
|
||||||
|
if(selected_sample == -1) selected_sample = 3;
|
||||||
|
break;
|
||||||
|
case SEQUENCE:
|
||||||
|
set_bar += encdelta;
|
||||||
|
if(set_bar == 16) set_bar = 0;
|
||||||
|
if(set_bar == -1) set_bar = 15;
|
||||||
|
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);
|
||||||
|
|
||||||
// empty LED matrix
|
// empty LED matrix
|
||||||
for (int i = 0; i < 13; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
ui_leds[lut_matrix[i]] = CRGB(0, 0, 0);
|
ui_leds[lut_banks[i]] = CRGB(0, 0, 0);
|
||||||
if(stream[i % NSTREAMS].isPlaying()) ui_leds[lut_matrix[i % NSTREAMS]] = CRGB(0, 50, 0);
|
ui_leds[lut_samples[i]] = CRGB(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set active LED matrix LED
|
// set active LED matrix LED
|
||||||
ui_leds[lut_matrix[active]] = CRGB(100, 100, 100);
|
ui_leds[lut_banks[selected_bank]] = CRGB(100, 50, 50);
|
||||||
|
ui_leds[lut_samples[selected_sample]] = CRGB(100, 0, 50);
|
||||||
|
|
||||||
|
for(int i = 0; i < 48; i++){
|
||||||
|
int step = floor(i/3);
|
||||||
|
if(step == set_bar){
|
||||||
|
ui_leds[lut_ring_cw[i]] = CRGB(config.ring_color.r_active, config.ring_color.g_active, config.ring_color.b_active);
|
||||||
|
}
|
||||||
|
if(step == bar){
|
||||||
|
ui_leds[lut_ring_cw[i]] = CRGB(config.ring_color.r, config.ring_color.g, config.ring_color.b);
|
||||||
|
}
|
||||||
|
if(steps[step].len > 0) {
|
||||||
|
ui_leds[lut_ring_cw[i]] = CRGB(0, 10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if(position < 0) position += 4096;
|
|
||||||
active_led_ring = (position / 32) % 48;
|
|
||||||
|
|
||||||
// set active LED ring LED
|
|
||||||
for(int i = 0; i < active_led_ring; i++){
|
|
||||||
ui_leds[lut_ring_ccw[i]] = CRGB(50, 0, 25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(bar != bar_old){
|
||||||
|
if(steps[bar].len > 0) {
|
||||||
|
steps[bar].trigger();
|
||||||
|
Serial.print("trigger ");
|
||||||
|
Serial.println(bar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// // set active LED ring LED
|
||||||
|
// for(int i = 0; i < active_led_ring; i++){
|
||||||
|
// ui_leds[lut_ring_ccw[i]] = CRGB(config.ring_color.r, config.ring_color.g, config.ring_color.b);
|
||||||
|
// }
|
||||||
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
if(streams_loaded) {
|
if(streams_loaded) {
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
@ -428,9 +674,19 @@ 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;
|
||||||
|
vibration.update();
|
||||||
|
position_last = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -74,16 +74,21 @@ struct WaveFile{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void readblock(){
|
bool readblock(){
|
||||||
uint8_t samplebyte[blockalign];
|
uint8_t samplebyte[blockalign];
|
||||||
|
|
||||||
file.read(samplebyte, blockalign);
|
file.read(samplebyte, blockalign);
|
||||||
if(!file.available() && loop) file.seek(44, SeekSet);
|
if(!file.available() && loop) file.seek(44, SeekSet);
|
||||||
|
if(!file.available() && !loop) {
|
||||||
|
file.seek(44, SeekSet);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < blockalign; i+=2){
|
for(int i = 0; i < blockalign; i+=2){
|
||||||
int16_t sample = (samplebyte[i+1] << 8) + samplebyte[i];
|
int16_t sample = (samplebyte[i+1] << 8) + samplebyte[i];
|
||||||
buffer.push(sample);
|
buffer.push(sample);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t get(){
|
int16_t get(){
|
||||||
@ -94,6 +99,10 @@ struct WaveFile{
|
|||||||
file.seek(44, SeekSet);
|
file.seek(44, SeekSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset(){
|
||||||
|
file.seek(44, SeekSet);
|
||||||
|
}
|
||||||
|
|
||||||
bool loop = false;
|
bool loop = false;
|
||||||
uint16_t format = 0;
|
uint16_t format = 0;
|
||||||
uint32_t length = 0;
|
uint32_t length = 0;
|
||||||
@ -110,7 +119,7 @@ class WaveStream{
|
|||||||
WaveStream(){}
|
WaveStream(){}
|
||||||
|
|
||||||
void begin(){
|
void begin(){
|
||||||
wavefile.buffer.setSize(24000);
|
wavefile.buffer.setSize(8000);
|
||||||
wavefile.buffer.begin();
|
wavefile.buffer.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +130,10 @@ class WaveStream{
|
|||||||
|
|
||||||
void toggle(){playing = !playing;}
|
void toggle(){playing = !playing;}
|
||||||
|
|
||||||
void play(){playing = true;}
|
void play(bool reset = false){
|
||||||
|
if(reset) wavefile.reset();
|
||||||
|
playing = true;
|
||||||
|
}
|
||||||
|
|
||||||
void stop(){
|
void stop(){
|
||||||
playing = false;
|
playing = false;
|
||||||
@ -134,7 +146,8 @@ class WaveStream{
|
|||||||
if(!wavefile.buffer.isFull() && playing){
|
if(!wavefile.buffer.isFull() && playing){
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (!wavefile.buffer.isFull() && cnt < 6000) {
|
while (!wavefile.buffer.isFull() && cnt < 6000) {
|
||||||
wavefile.readblock();
|
bool ok = wavefile.readblock();
|
||||||
|
if(!ok) playing = false;
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user