forked from W4D/soundcube-firmware
Compare commits
8 Commits
v0.1.0-sam
...
sampler
| Author | SHA1 | Date | |
|---|---|---|---|
| cef092f494 | |||
| d44210ce59 | |||
| 7418cdfd35 | |||
| ad035e69e2 | |||
| d5ea2377f9 | |||
| b9130dc0ae | |||
| b4f504b21d | |||
| 6bcc37d3ee |
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class RingBuffer{
|
class RingBuffer{
|
||||||
public:
|
public:
|
||||||
RingBuffer() {}
|
RingBuffer() {}
|
||||||
@ -11,10 +10,10 @@ class RingBuffer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void begin(){
|
void begin(){
|
||||||
buffer = new T[bufferSize];
|
buffer = new int16_t[bufferSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool push(T data){
|
bool push(int16_t data){
|
||||||
if(counter < bufferSize){
|
if(counter < bufferSize){
|
||||||
buffer[write] = data;
|
buffer[write] = data;
|
||||||
write++; // % bufferSize;
|
write++; // % bufferSize;
|
||||||
@ -25,8 +24,8 @@ class RingBuffer{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
T pop(){
|
int16_t pop(){
|
||||||
T retval = 0;
|
int16_t retval = 0;
|
||||||
if(counter > 0) {
|
if(counter > 0) {
|
||||||
counter--;
|
counter--;
|
||||||
retval = buffer[read];
|
retval = buffer[read];
|
||||||
@ -36,22 +35,72 @@ class RingBuffer{
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t* getReadPointer(){
|
||||||
|
return &buffer[read];
|
||||||
|
}
|
||||||
|
|
||||||
|
void pointerPop(int nbytes){
|
||||||
|
for(int i=0; i<nbytes / 2; ++i){
|
||||||
|
if(counter > 0) {
|
||||||
|
counter--;
|
||||||
|
read++;// % bufferSize;
|
||||||
|
if(read == bufferSize) read = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pushDMA(int32_t *source){
|
||||||
|
if(counter < bufferSize){
|
||||||
|
rp2040.memcpyDMA(&buffer[write], source, 4);
|
||||||
|
write += 2; // % bufferSize;
|
||||||
|
if(write == bufferSize) write = 0;
|
||||||
|
counter += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* getWritePointer(){
|
||||||
|
return &buffer[write];
|
||||||
|
}
|
||||||
|
|
||||||
|
void advance(int nbytes){
|
||||||
|
for(int i = 0; i < nbytes/2; ++i){
|
||||||
|
if(counter < (bufferSize-1)){
|
||||||
|
write++; // % bufferSize;
|
||||||
|
if(write == bufferSize) write = 0;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void popDMA(int32_t *target){
|
||||||
|
if(counter > 1) {
|
||||||
|
counter -= 2;
|
||||||
|
rp2040.memcpyDMA(target, &buffer[read], 4);
|
||||||
|
read += 2;
|
||||||
|
if(read >= bufferSize) read = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool isEmpty(){
|
bool isEmpty(){
|
||||||
return counter == 0;
|
return counter == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFull(){
|
bool isFull(){
|
||||||
return counter == bufferSize;
|
return counter == (bufferSize-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int size(){
|
int size(){
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int remains(){
|
||||||
|
return (bufferSize-2) - counter;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t bufferSize = 0;
|
size_t bufferSize = 0;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int write = 0;
|
int write = 0;
|
||||||
int read = 0;
|
int read = 0;
|
||||||
T *buffer;
|
int16_t *buffer;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,9 @@
|
|||||||
#include <AS5600.h>
|
#include <AS5600.h>
|
||||||
#include <DAC8552.h>
|
#include <DAC8552.h>
|
||||||
|
|
||||||
|
#define FASTLED_FORCE_SOFTWARE_SPI
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
|
|
||||||
#include <PWMAudio.h>
|
#include <PWMAudio.h>
|
||||||
#include <I2S.h>
|
#include <I2S.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
@ -13,19 +15,22 @@
|
|||||||
#include "codec.h"
|
#include "codec.h"
|
||||||
#include "wavestream.h"
|
#include "wavestream.h"
|
||||||
|
|
||||||
|
bool core1_separate_stack = true;
|
||||||
|
bool core1_disable_systick = true;
|
||||||
|
|
||||||
#define HAPTIC 1
|
#define HAPTIC 1
|
||||||
#define AURAL 1
|
#define AURAL 1
|
||||||
#define UI_SAMPLERATE 22050
|
#define UI_SAMPLERATE 22050
|
||||||
|
|
||||||
#define BUFFERSIZE 64
|
#define BUFFERSIZE 256
|
||||||
#define NSTREAMS 16
|
#define NSTREAMS 16
|
||||||
|
|
||||||
|
I2S i2s(INPUT_PULLUP);
|
||||||
|
|
||||||
int16_t buffer[BUFFERSIZE];
|
int16_t buffer[BUFFERSIZE];
|
||||||
|
|
||||||
WaveStream stream[NSTREAMS];
|
WaveStream stream[NSTREAMS];
|
||||||
|
|
||||||
I2S i2s(INPUT_PULLUP);
|
|
||||||
|
|
||||||
TLV320AIC3204 codec;
|
TLV320AIC3204 codec;
|
||||||
|
|
||||||
TCA9555 TCA(0x20, &Wire1);
|
TCA9555 TCA(0x20, &Wire1);
|
||||||
@ -35,6 +40,9 @@ DAC8552 dac(9, &SPI1);
|
|||||||
|
|
||||||
PWMAudio ui_snd(8);
|
PWMAudio ui_snd(8);
|
||||||
|
|
||||||
|
CRGB ui_leds[74];
|
||||||
|
CRGB edge_leds[11];
|
||||||
|
|
||||||
enum STATE {BANK, SAMPLE, SEQUENCE, CTEMPO};
|
enum STATE {BANK, SAMPLE, SEQUENCE, CTEMPO};
|
||||||
STATE state = BANK;
|
STATE state = BANK;
|
||||||
|
|
||||||
@ -43,6 +51,10 @@ enum BUTTON {MODE, LOOP, INL, INR, OUTR, OUTL, TEMPO, RESET, BACK, POWER, SELECT
|
|||||||
|
|
||||||
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_ring_cw_3[48] = {40,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};
|
||||||
|
int lut_ring_ccw_3[48] = {39,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};
|
||||||
|
|
||||||
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_banks[4] = {56,55,67,66};
|
||||||
@ -57,18 +69,25 @@ int selected_sample = 0;
|
|||||||
uint32_t lastTime = 0;
|
uint32_t lastTime = 0;
|
||||||
int32_t position = 0;
|
int32_t position = 0;
|
||||||
|
|
||||||
CRGB ui_leds[74];
|
volatile bool setup0_finished = false;
|
||||||
CRGB edge_leds[11];
|
volatile bool setup1_finished = false;
|
||||||
|
|
||||||
volatile bool buttonChanged = false;
|
volatile bool buttonChanged = false;
|
||||||
|
volatile bool sdInitialized = false;
|
||||||
|
|
||||||
bool ui_click = false;
|
volatile bool wire_ready = false;
|
||||||
bool ui_beep = false;
|
|
||||||
|
volatile bool ui_click = false;
|
||||||
|
volatile bool ui_beep = false;
|
||||||
bool amp = false;
|
bool amp = false;
|
||||||
bool streams_loaded = false;
|
volatile bool streams_loaded = false;
|
||||||
bool speakerToggle = false;
|
bool speakerToggle = false;
|
||||||
bool sd_card_detected = false;
|
bool sd_card_detected = false;
|
||||||
|
|
||||||
|
volatile bool i2s_ready = false;
|
||||||
|
volatile bool codec_ready = false;
|
||||||
|
volatile bool config_loaded = false;
|
||||||
|
|
||||||
bool buttons[16] = {false};
|
bool buttons[16] = {false};
|
||||||
int buttonsDir[16] = {0};
|
int buttonsDir[16] = {0};
|
||||||
|
|
||||||
@ -154,12 +173,29 @@ size_t count;
|
|||||||
size_t tape_write = 0;
|
size_t tape_write = 0;
|
||||||
|
|
||||||
void codec_transmit() {
|
void codec_transmit() {
|
||||||
for(int i = 0; i < count; i++){
|
for(int i = 0; i < count; i+=2){
|
||||||
int j = active % NSTREAMS;
|
if(streams_loaded){
|
||||||
for(int k = 0; k < NSTREAMS; k++){
|
for(int k = 0; k < NSTREAMS; k++){
|
||||||
int16_t sample = 0;
|
//int32_t twosamples;
|
||||||
sample = stream[k].get();
|
int16_t twosamples[2];
|
||||||
buffer[i] += sample >> 2;
|
if(stream[k].isPlaying()){
|
||||||
|
stream[k].getDMA((int32_t*)&twosamples);
|
||||||
|
|
||||||
|
int16_t sample_l = twosamples[0];// >> 16;
|
||||||
|
int16_t sample_r = twosamples[1];// & 0xFFFF;
|
||||||
|
|
||||||
|
// int16_t *sample_l = stream[k].wavefile.buffer.getReadPointer(); //twosamples >> 16;
|
||||||
|
// stream[k].wavefile.buffer.pointerPop(2);
|
||||||
|
// int16_t *sample_r = stream[k].wavefile.buffer.getReadPointer(); //twosamples & 0xFFFF;
|
||||||
|
// stream[k].wavefile.buffer.pointerPop(2);
|
||||||
|
|
||||||
|
// buffer[i] += (*sample_l / 16);
|
||||||
|
// buffer[i+1] += (*sample_r / 16);
|
||||||
|
|
||||||
|
buffer[i] += (sample_l / 16);
|
||||||
|
buffer[i+1] += (sample_r / 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||||
@ -309,101 +345,114 @@ struct Vibration{
|
|||||||
on = _on;
|
on = _on;
|
||||||
off = _off;
|
off = _off;
|
||||||
start = true;
|
start = true;
|
||||||
|
last = millis();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Vibration vibration;
|
Vibration vibration;
|
||||||
|
|
||||||
|
// -------------------------------------------- SETUP 0
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin();
|
//i2s.setSysClk(48000);
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
i2s.setFrequency(48000);
|
delay(500);
|
||||||
|
|
||||||
|
Serial.print("1: INIT WIRE: ");
|
||||||
|
Wire1.setSDA(2);
|
||||||
|
Wire1.setSCL(3);
|
||||||
|
Wire1.begin();
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
wire_ready = true;
|
||||||
|
|
||||||
|
Serial.print("1: INIT SPI: ");
|
||||||
SPI1.setSCK(10);
|
SPI1.setSCK(10);
|
||||||
SPI1.setTX(11);
|
SPI1.setTX(11);
|
||||||
SPI1.begin();
|
SPI1.begin();
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
Serial.print("1: ENABLE CODEC: ");
|
||||||
|
pinMode(20, OUTPUT); // CODEC reset (enable)
|
||||||
|
digitalWrite(20, HIGH);
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
Serial.print("1: ENABLE I2S MCLK: ");
|
||||||
|
pinMode(19, OUTPUT); // MCLK enable
|
||||||
|
digitalWrite(19, HIGH); // enable MCLK
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
Serial.print("1: STARTUP");
|
||||||
|
|
||||||
|
Serial.print("1: INIT TCA: ");
|
||||||
|
TCA.begin();
|
||||||
|
TCA.pinMode16(0xFFFF);
|
||||||
|
TCA.setPolarity16(0x0000);
|
||||||
|
Serial.println(" SUCCESS");
|
||||||
|
|
||||||
|
Serial.print("1: INIT TCA INTERRUPT: ");
|
||||||
|
pinMode(1, INPUT_PULLUP);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(1), tca_irq, FALLING);
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
Serial.print("1: INIT ROTARY ENCODER: ");
|
||||||
|
ENC.begin(); // set direction pin.
|
||||||
|
ENC.setDirection(AS5600_CLOCK_WISE);
|
||||||
|
ENC.resetCumulativePosition();
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
Serial.print("1: INIT DAC: ");
|
||||||
dac.begin();
|
dac.begin();
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
pinMode(6, OUTPUT); // Vibration Motor
|
||||||
|
pinMode(7, OUTPUT); // UI Amp Enable
|
||||||
|
|
||||||
|
//ui_snd.onTransmit(pwm_audio_callback);
|
||||||
|
//ui_snd.begin(UI_SAMPLERATE);
|
||||||
|
|
||||||
|
digitalWrite(7, LOW); // UI amp off
|
||||||
|
|
||||||
|
Serial.print("1: INIT LEDS: ");
|
||||||
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
|
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
|
||||||
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
|
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
pinMode(12, OUTPUT);
|
Serial.print("1: STARTUP COMPLETE");
|
||||||
pinMode(13, OUTPUT);
|
setup1_finished = true;
|
||||||
|
digitalWrite(6, HIGH);
|
||||||
|
delay(25);
|
||||||
|
digitalWrite(6, LOW);
|
||||||
|
Serial.begin();
|
||||||
|
|
||||||
|
Serial.print("0: INIT CODEC: ");
|
||||||
|
codec.begin(&Wire1);
|
||||||
|
Serial.println("SUCCESS");
|
||||||
|
|
||||||
|
codec_ready = true;
|
||||||
|
|
||||||
|
pinMode(12, OUTPUT); // speaker enable l
|
||||||
|
pinMode(13, OUTPUT); // speaker enable r
|
||||||
speaker(false);
|
speaker(false);
|
||||||
|
|
||||||
pinMode(21, INPUT_PULLUP);
|
pinMode(21, INPUT_PULLUP);
|
||||||
sd_card_detected = !digitalRead(21);
|
sd_card_detected = !digitalRead(21);
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
bool sdInitialized = SD.begin(22, 23, 24);
|
while(!sdInitialized){
|
||||||
delay(100);
|
sdInitialized = SD.begin(22, 23, 24);
|
||||||
if(!sdInitialized) sdInitialized = SD.begin(22, 23, 24); // hack to prevent SD card from not initializing after soft reset
|
delay(250);
|
||||||
|
Serial.println("0: Initializing SD Card");
|
||||||
|
}
|
||||||
|
|
||||||
if(sdInitialized) loadConfiguration(config);
|
if(sdInitialized) loadConfiguration(config);
|
||||||
|
|
||||||
if(sdInitialized){
|
if(sdInitialized){
|
||||||
load_ui_sounds("/ui/click.wav", ui_click_snd, click_length);
|
load_ui_sounds("/ui/click.wav", ui_click_snd, click_length);
|
||||||
load_ui_sounds("/ui/beep.wav", ui_beep_snd, beep_length);
|
load_ui_sounds("/ui/beep.wav", ui_beep_snd, beep_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("INIT WIRE");
|
config_loaded = true;
|
||||||
Wire1.setSDA(2);
|
|
||||||
Wire1.setSCL(3);
|
|
||||||
Wire1.begin();
|
|
||||||
Serial.println("SUCCESS");
|
|
||||||
|
|
||||||
Serial.println("INIT TCA");
|
|
||||||
TCA.begin();
|
|
||||||
TCA.pinMode16(0xFFFF);
|
|
||||||
TCA.setPolarity16(0x0000);
|
|
||||||
Serial.println("SUCCESS");
|
|
||||||
|
|
||||||
Serial.println("INIT INTERRUPT");
|
|
||||||
pinMode(1, INPUT_PULLUP);
|
|
||||||
attachInterrupt(digitalPinToInterrupt(1), tca_irq, FALLING);
|
|
||||||
Serial.println("SUCCESS");
|
|
||||||
|
|
||||||
// Rotary Encoder
|
|
||||||
ENC.begin(); // set direction pin.
|
|
||||||
ENC.setDirection(AS5600_CLOCK_WISE);
|
|
||||||
ENC.resetCumulativePosition();
|
|
||||||
|
|
||||||
pinMode(6, OUTPUT); // Vibration Motor
|
|
||||||
pinMode(7, OUTPUT); // UI Amp Enable
|
|
||||||
|
|
||||||
ui_snd.onTransmit(pwm_audio_callback);
|
|
||||||
ui_snd.begin(UI_SAMPLERATE);
|
|
||||||
|
|
||||||
digitalWrite(7, LOW); // UI amp off
|
|
||||||
|
|
||||||
pinMode(19, OUTPUT); // MCLK enable
|
|
||||||
digitalWrite(19, HIGH); // enable MCLK
|
|
||||||
|
|
||||||
pinMode(20, OUTPUT); // CODEC reset
|
|
||||||
digitalWrite(20, HIGH);
|
|
||||||
|
|
||||||
codec.begin(&Wire1);
|
|
||||||
|
|
||||||
i2s.onTransmit(codec_transmit);
|
|
||||||
i2s.onReceive(codec_receive);
|
|
||||||
|
|
||||||
i2s.setDOUT(15);
|
|
||||||
i2s.setDIN(14);
|
|
||||||
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
|
||||||
i2s.setMCLK(18);
|
|
||||||
i2s.setMCLKmult(512); // 256 = 12.288.000Hz 512 = 25Mhz
|
|
||||||
|
|
||||||
i2s.swapClocks();
|
|
||||||
i2s.setBitsPerSample(16);
|
|
||||||
|
|
||||||
i2s.setBuffers(6, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
|
||||||
|
|
||||||
if(!i2s.begin(48000)){
|
|
||||||
Serial.println("I2S error!");
|
|
||||||
while(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sdInitialized) {
|
if(sdInitialized) {
|
||||||
streams_loaded = load_samples();
|
streams_loaded = load_samples();
|
||||||
@ -415,18 +464,47 @@ void setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
i2s.onTransmit(codec_transmit);
|
||||||
|
i2s.onReceive(codec_receive);
|
||||||
|
|
||||||
|
i2s.setDOUT(15);
|
||||||
|
i2s.setDIN(14);
|
||||||
|
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
||||||
|
i2s.setMCLK(18);
|
||||||
|
i2s.setMCLKmult(512); // 256 = 12.288.000Hz 512 = 25MHz
|
||||||
|
i2s.swapClocks();
|
||||||
|
|
||||||
|
// i2s.setFrequency(48000);
|
||||||
|
i2s.setBitsPerSample(16);
|
||||||
|
|
||||||
|
i2s.setBuffers(4, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||||
|
|
||||||
|
if(!i2s.begin(48000)){
|
||||||
|
Serial.println("0: I2S error!");
|
||||||
|
while(100);
|
||||||
|
}
|
||||||
|
Serial.println("0: I2S OK");
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
i2s_ready = true;
|
||||||
|
|
||||||
|
Serial.print("0: STARTUP COMPLETE");
|
||||||
|
|
||||||
digitalWrite(6, HIGH);
|
digitalWrite(6, HIGH);
|
||||||
delay(25);
|
delay(25);
|
||||||
digitalWrite(6, LOW);
|
digitalWrite(6, LOW);
|
||||||
delay(50);
|
setup0_finished = true;
|
||||||
digitalWrite(6, HIGH);
|
setup1_finished = true;
|
||||||
delay(25);
|
}
|
||||||
digitalWrite(6, LOW);
|
|
||||||
|
void setup1(){
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t last = 0;
|
uint32_t last = 0;
|
||||||
int bar = 0;
|
volatile int bar = 0;
|
||||||
int bar_old = -1;
|
volatile int bar_old = -1;
|
||||||
int set_bar = 0;
|
int set_bar = 0;
|
||||||
int16_t angle = 0;
|
int16_t angle = 0;
|
||||||
int32_t position_last = 0;
|
int32_t position_last = 0;
|
||||||
@ -434,259 +512,292 @@ int32_t position_last = 0;
|
|||||||
int16_t encdelta_raw = 0;
|
int16_t encdelta_raw = 0;
|
||||||
int16_t encdeltadiv = 512;
|
int16_t encdeltadiv = 512;
|
||||||
|
|
||||||
void loop() {
|
void loop1() {
|
||||||
position = ENC.getCumulativePosition();
|
if(setup0_finished && setup1_finished){
|
||||||
angle = ENC.readAngle();
|
position = ENC.getCumulativePosition();
|
||||||
encdelta_raw += (position - position_last);
|
angle = ENC.readAngle();
|
||||||
|
encdelta_raw += (position - position_last);
|
||||||
|
|
||||||
// Serial.print(encdelta_raw);
|
// Serial.print(encdelta_raw);
|
||||||
// Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
|
|
||||||
int encdelta = 0;
|
int encdelta = 0;
|
||||||
if(abs(encdelta_raw) > encdeltadiv) {
|
if(abs(encdelta_raw) > encdeltadiv) {
|
||||||
encdelta = encdelta_raw > 0 ? 1 : -1;
|
encdelta = encdelta_raw > 0 ? 1 : -1;
|
||||||
encdelta_raw = 0;
|
encdelta_raw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serial.print(angle);
|
// Serial.print(angle);
|
||||||
// Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
// Serial.print(position);
|
// Serial.print(position);
|
||||||
// Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
// Serial.print(position_last);
|
// Serial.print(position_last);
|
||||||
// Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
// Serial.print(encdelta_raw);
|
// Serial.print(encdelta_raw);
|
||||||
// Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
// Serial.println(encdelta);
|
// Serial.println(encdelta);
|
||||||
|
|
||||||
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
sd_card_detected = !digitalRead(21);
|
||||||
|
edge_leds[8] = sd_card_detected ? CRGB(0,10,0) : CRGB(10,0,0);
|
||||||
|
|
||||||
if(millis() - last >= delta_bpm) {
|
// EDGE LEDs
|
||||||
bar = (bar + 1) % 16;
|
for (int i = 0; i < 8; i++) {
|
||||||
last = millis();
|
edge_leds[i] = CRGB(config.edge_color.r, config.edge_color.g, config.edge_color.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
sd_card_detected = !digitalRead(21);
|
// LED Ring leeren
|
||||||
edge_leds[8] = sd_card_detected ? CRGB(0,10,0) : CRGB(10,0,0);
|
for (int i = 0; i < 48; i++) {
|
||||||
|
ui_leds[i + 3] = CRGB(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// EDGE LEDs
|
// Rotary button LEDs
|
||||||
for (int i = 0; i < 8; i++) {
|
ui_leds[0] = CRGB(0, 0, 0);
|
||||||
edge_leds[i] = CRGB(config.edge_color.r, config.edge_color.g, config.edge_color.b);
|
ui_leds[1] = CRGB(0, 0, 0);
|
||||||
}
|
ui_leds[2] = CRGB(0, 0, 0);
|
||||||
|
|
||||||
// LED Ring leeren
|
// buttonChanged = true when a button is pushed
|
||||||
for (int i = 0; i < 48; i++) {
|
if (buttonChanged) {
|
||||||
ui_leds[i + 3] = CRGB(0, 0, 0);
|
int buttonValues = TCA.read16();
|
||||||
}
|
|
||||||
|
|
||||||
// Rotary button LEDs
|
bool buttonsNew[16] = {false};
|
||||||
ui_leds[0] = CRGB(0, 0, 0);
|
|
||||||
ui_leds[1] = CRGB(0, 0, 0);
|
|
||||||
ui_leds[2] = CRGB(0, 0, 0);
|
|
||||||
|
|
||||||
// buttonChanged = true when a button is pushed
|
bool buttonUp = false;
|
||||||
if (buttonChanged) {
|
bool buttonDown = false;
|
||||||
int buttonValues = TCA.read16();
|
|
||||||
|
|
||||||
bool buttonsNew[16] = {false};
|
for(int i = 0; i < 16; i++){
|
||||||
|
buttonsNew[i] = ~(buttonValues >> i) & 0x01;
|
||||||
bool buttonUp = false;
|
if(buttonsNew[i] == true && buttons[i] == false) {
|
||||||
bool buttonDown = false;
|
buttonsDir[i] = -1;
|
||||||
|
buttonDown = true;
|
||||||
for(int i = 0; i < 16; i++){
|
}
|
||||||
buttonsNew[i] = ~(buttonValues >> i) & 0x01;
|
if(buttonsNew[i] == false && buttons[i] == true) {
|
||||||
if(buttonsNew[i] == true && buttons[i] == false) {
|
buttonsDir[i] = 1;
|
||||||
buttonsDir[i] = -1;
|
buttonUp = true;
|
||||||
buttonDown = true;
|
}
|
||||||
|
buttons[i] = buttonsNew[i];
|
||||||
}
|
}
|
||||||
if(buttonsNew[i] == false && buttons[i] == true) {
|
|
||||||
buttonsDir[i] = 1;
|
// Make vibration
|
||||||
buttonUp = true;
|
if(HAPTIC && buttonDown) {
|
||||||
|
vibration.trigger(1, 25, 25);
|
||||||
}
|
}
|
||||||
buttons[i] = buttonsNew[i];
|
|
||||||
|
// Make beep
|
||||||
|
if(AURAL && buttonDown) {
|
||||||
|
digitalWrite(7, HIGH);
|
||||||
|
ui_click = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttons[TEMPO] && buttonDown){
|
||||||
|
state = CTEMPO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(state){
|
||||||
|
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[DEBUG1]) {
|
||||||
|
Serial.println("vol down");
|
||||||
|
codec.volumeDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttons[DEBUG3]) {
|
||||||
|
Serial.println("vol up");
|
||||||
|
codec.volumeUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttons[DEBUG2]) {
|
||||||
|
speakerToggle = !speakerToggle;
|
||||||
|
speaker(speakerToggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Serial.println(codec.getVolumeL());
|
||||||
|
|
||||||
|
buttonChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make vibration
|
// if(position < 0) position += 4096;
|
||||||
if(HAPTIC && buttonDown) {
|
|
||||||
vibration.trigger(1, 25, 25);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make beep
|
|
||||||
if(AURAL && buttonDown) {
|
|
||||||
digitalWrite(7, HIGH);
|
|
||||||
ui_click = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(buttons[TEMPO] && buttonDown){
|
|
||||||
state = CTEMPO;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(buttons[BACK] && buttonDown){
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(state){
|
switch(state){
|
||||||
case BANK:
|
case BANK:
|
||||||
encdeltadiv = 512;
|
selected_bank += encdelta;
|
||||||
encdelta_raw = 0;
|
if(selected_bank == 4) selected_bank = 0;
|
||||||
encdelta = 0;
|
if(selected_bank == -1) selected_bank = 3;
|
||||||
if(buttons[SELECT] && buttonDown){
|
|
||||||
state = SAMPLE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SAMPLE:
|
case SAMPLE:
|
||||||
encdeltadiv = 512;
|
selected_sample += encdelta;
|
||||||
encdelta_raw = 0;
|
if(selected_sample == 4) selected_sample = 0;
|
||||||
encdelta = 0;
|
if(selected_sample == -1) selected_sample = 3;
|
||||||
if(buttons[SELECT] && buttonDown){
|
|
||||||
state = SEQUENCE;
|
|
||||||
}
|
|
||||||
if(buttons[BACK] && buttonDown){
|
|
||||||
state = BANK;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SEQUENCE:
|
case SEQUENCE:
|
||||||
encdeltadiv = 256;
|
set_bar += encdelta;
|
||||||
encdelta_raw = 0;
|
if(set_bar == 16) set_bar = 0;
|
||||||
encdelta = 0;
|
if(set_bar == -1) set_bar = 15;
|
||||||
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;
|
break;
|
||||||
case CTEMPO:
|
case CTEMPO:
|
||||||
encdeltadiv = 64;
|
config.bpm += encdelta;
|
||||||
encdelta_raw = 0;
|
if(config.bpm < 15) config.bpm = 15;
|
||||||
encdelta = 0;
|
if(config.bpm > 300) config.bpm = 300;
|
||||||
if(buttons[SELECT] && buttonDown){
|
|
||||||
state = BANK;
|
|
||||||
}
|
|
||||||
if(buttons[BACK] && buttonDown){
|
|
||||||
state = BANK;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set bar
|
|
||||||
// if(buttons[BACK]) set_bar++;
|
|
||||||
// if(buttons[POWER]) set_bar--;
|
|
||||||
|
|
||||||
if(buttons[SELECT]){
|
//dac.setValue(0, dactest ? 0 : sin((float)millis() / 100.0f) * 32768 + 32768);
|
||||||
// Flash encoder leds
|
|
||||||
ui_leds[0] = CRGB(0, 100, 50);
|
// empty LED matrix
|
||||||
ui_leds[1] = CRGB(0, 100, 50);
|
for (int i = 0; i < 4; i++) {
|
||||||
ui_leds[2] = CRGB(0, 100, 50);
|
ui_leds[lut_banks[i]] = CRGB(0, 0, 0);
|
||||||
|
ui_leds[lut_samples[i]] = CRGB(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[DEBUG1]) {
|
// set active LED matrix LED
|
||||||
Serial.println("vol down");
|
ui_leds[lut_banks[selected_bank]] = CRGB(100, 50, 50);
|
||||||
codec.volumeDown();
|
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_3[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_3[i]] = CRGB(config.ring_color.r, config.ring_color.g, config.ring_color.b);
|
||||||
|
}
|
||||||
|
if(steps[step].len > 0) {
|
||||||
|
ui_leds[lut_ring_cw_3[i]] = CRGB(0, 10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[DEBUG3]) {
|
FastLED.show();
|
||||||
Serial.println("vol up");
|
|
||||||
codec.volumeUp();
|
if(buttonChanged){
|
||||||
|
for(int i = 0; i < 16; i++){
|
||||||
|
if(buttonsDir[i] == 1) buttonsDir[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[DEBUG2]) {
|
vibration.update();
|
||||||
speakerToggle = !speakerToggle;
|
position_last = position;
|
||||||
speaker(speakerToggle);
|
delay(1);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Serial.println(codec.getVolumeL());
|
|
||||||
|
|
||||||
buttonChanged = false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//int sc = 0;
|
||||||
|
int streamcnt = 0;
|
||||||
|
void loop(){
|
||||||
|
if(setup1_finished && setup0_finished){
|
||||||
|
|
||||||
// if(position < 0) position += 4096;
|
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
||||||
|
uint32_t delta = millis() - last;
|
||||||
|
|
||||||
switch(state){
|
if(delta >= delta_bpm) {
|
||||||
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);
|
bar = (bar + 1) % 16;
|
||||||
|
if(steps[bar].len > 0) {
|
||||||
|
steps[bar].trigger();
|
||||||
|
}
|
||||||
|
|
||||||
// empty LED matrix
|
if(streams_loaded) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
ui_leds[lut_banks[i]] = CRGB(0, 0, 0);
|
Serial.print(stream[i].wavefile.buffer.size());
|
||||||
ui_leds[lut_samples[i]] = CRGB(0,0,0);
|
Serial.print("\t");
|
||||||
}
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
// set active LED matrix LED
|
// Serial.print(delta_bpm);
|
||||||
ui_leds[lut_banks[selected_bank]] = CRGB(100, 50, 50);
|
// Serial.print(" ");
|
||||||
ui_leds[lut_samples[selected_sample]] = CRGB(100, 0, 50);
|
// Serial.println(delta);
|
||||||
|
|
||||||
for(int i = 0; i < 48; i++){
|
last = millis();
|
||||||
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(streams_loaded) {
|
||||||
}
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
if(steps[step].len > 0) {
|
stream[i].streamChunk();
|
||||||
ui_leds[lut_ring_cw[i]] = CRGB(0, 10, 0);
|
}
|
||||||
}
|
}
|
||||||
|
streamcnt = (streamcnt + 1) % 16;
|
||||||
|
|
||||||
|
// int16_t sample_l = 0;
|
||||||
|
// int16_t sample_r = 0;
|
||||||
|
//
|
||||||
|
// if(streams_loaded){
|
||||||
|
// for(int k = 0; k < NSTREAMS; k++){
|
||||||
|
// sample_l += stream[k].get() >> 2;
|
||||||
|
// sample_r += stream[k].get() >> 2;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// int16_t l = 0, r = 0;
|
||||||
|
// i2s.read16(&l, &r);
|
||||||
|
// l += sample_l;
|
||||||
|
// r += sample_r;
|
||||||
|
// i2s.write16(l, r);
|
||||||
|
|
||||||
|
if(i2s.getOverflow()) Serial.println("overflow");
|
||||||
|
if(i2s.getUnderflow()) Serial.println("underflow");
|
||||||
|
|
||||||
|
bar_old = bar;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
if(streams_loaded) {
|
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
|
||||||
stream[i].stream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(buttonChanged){
|
|
||||||
for(int i = 0; i < 16; i++){
|
|
||||||
if(buttonsDir[i] == 1) buttonsDir[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i2s.getOverflow()) Serial.println("overflow");
|
|
||||||
if(i2s.getUnderflow()) Serial.println("underflow");
|
|
||||||
|
|
||||||
//delay(20); // wait 1ms
|
|
||||||
bar_old = bar;
|
|
||||||
vibration.update();
|
|
||||||
position_last = position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -78,6 +78,7 @@ struct WaveFile{
|
|||||||
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) {
|
if(!file.available() && !loop) {
|
||||||
file.seek(44, SeekSet);
|
file.seek(44, SeekSet);
|
||||||
@ -91,6 +92,37 @@ struct WaveFile{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool readblockDMA(){
|
||||||
|
void *bufferStart = buffer.getWritePointer();
|
||||||
|
|
||||||
|
file.read((uint8_t*)bufferStart, 4);
|
||||||
|
buffer.advance(4);
|
||||||
|
|
||||||
|
if(!file.available() && loop) file.seek(44, SeekSet);
|
||||||
|
if(!file.available() && !loop) {
|
||||||
|
file.seek(44, SeekSet);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readblockSD(){
|
||||||
|
void *bufferStart = buffer.getWritePointer();
|
||||||
|
remains = buffer.remains();
|
||||||
|
|
||||||
|
if(remains > 512){
|
||||||
|
adv = file.readBytes((char*)bufferStart, 512);
|
||||||
|
buffer.advance(adv);
|
||||||
|
|
||||||
|
if(!file.available() && loop) file.seek(44, SeekSet);
|
||||||
|
if(!file.available() && !loop) {
|
||||||
|
file.seek(44, SeekSet);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int16_t get(){
|
int16_t get(){
|
||||||
return buffer.pop();
|
return buffer.pop();
|
||||||
}
|
}
|
||||||
@ -111,7 +143,10 @@ struct WaveFile{
|
|||||||
uint16_t blockalign = 0;
|
uint16_t blockalign = 0;
|
||||||
uint16_t bitspersample = 0;
|
uint16_t bitspersample = 0;
|
||||||
|
|
||||||
RingBuffer<int16_t> buffer;
|
int adv = 0;
|
||||||
|
int remains = 0;
|
||||||
|
|
||||||
|
RingBuffer buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WaveStream{
|
class WaveStream{
|
||||||
@ -119,7 +154,7 @@ class WaveStream{
|
|||||||
WaveStream(){}
|
WaveStream(){}
|
||||||
|
|
||||||
void begin(){
|
void begin(){
|
||||||
wavefile.buffer.setSize(8000);
|
wavefile.buffer.setSize(2048);
|
||||||
wavefile.buffer.begin();
|
wavefile.buffer.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,13 +178,18 @@ class WaveStream{
|
|||||||
void pause(){playing = false;}
|
void pause(){playing = false;}
|
||||||
|
|
||||||
void stream(){
|
void stream(){
|
||||||
if(!wavefile.buffer.isFull() && playing){
|
int cnt = 0;
|
||||||
int cnt = 0;
|
while (!wavefile.buffer.isFull() && cnt < 1024) {
|
||||||
while (!wavefile.buffer.isFull() && cnt < 6000) {
|
bool ok = wavefile.readblockDMA();
|
||||||
bool ok = wavefile.readblock();
|
if(!ok) playing = false;
|
||||||
if(!ok) playing = false;
|
cnt += 2;
|
||||||
cnt++;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void streamChunk(){
|
||||||
|
if(!wavefile.buffer.isFull()){
|
||||||
|
bool ok = wavefile.readblockSD();
|
||||||
|
if(!ok) playing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +197,16 @@ class WaveStream{
|
|||||||
return playing ? wavefile.get() : 0;
|
return playing ? wavefile.get() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t* getPointer(){
|
||||||
|
int16_t* p = wavefile.buffer.getReadPointer();
|
||||||
|
wavefile.buffer.pointerPop(2);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getDMA(int32_t *samples){
|
||||||
|
if(playing) wavefile.buffer.popDMA(samples);
|
||||||
|
}
|
||||||
|
|
||||||
bool isPlaying(){
|
bool isPlaying(){
|
||||||
return playing;
|
return playing;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user