diff --git a/src/WVR.cpp b/src/WVR.cpp index 6121e16..fbee975 100644 --- a/src/WVR.cpp +++ b/src/WVR.cpp @@ -6,15 +6,14 @@ WVR::WVR() { - // this->autoConfigPins = true; this->wifiIsOn = get_wifi_is_on(); - // this->mute = false; - // this->globalVolume = 127; + this->useFTDI = false; + this->useUsbMidi = false; } void WVR::begin() { - wvr_init(); + wvr_init(useFTDI, useUsbMidi); } void WVR::play(uint8_t voice, uint8_t note, uint8_t velocity) diff --git a/src/WVR.h b/src/WVR.h index caf48fd..3538e48 100644 --- a/src/WVR.h +++ b/src/WVR.h @@ -21,7 +21,8 @@ class WVR { // bool mute; // bool autoConfigPins; bool wifiIsOn; - + bool useFTDI; + bool useUsbMidi; }; #endif \ No newline at end of file diff --git a/src/boot.cpp b/src/boot.cpp index f560ca6..9da525a 100644 --- a/src/boot.cpp +++ b/src/boot.cpp @@ -110,7 +110,7 @@ void boot_into_recovery_mode(void) new_metadata->current_firmware_index = index; write_metadata(*new_metadata); // sdmmc_host_deinit(); - // feedLoopWDT(); + feedLoopWDT(); // delay(1000); ESP.restart(); } else { diff --git a/src/button.cpp b/src/button.cpp index 5f8b8dc..c764724 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -17,13 +17,12 @@ xQueueHandle gpio_queue_handle; xTaskHandle gpio_task_handle; - static void gpioTask(void* x) { button_event_t *event; uint32_t touch_reg = 0; for(;;) { if(xQueueReceive(gpio_queue_handle, &event, portMAX_DELAY)) { - log_i("gpio task pin:%d val:%d",event->pin, event->val); + log_d("gpio task pin:%d val:%d",event->pin, event->val); if(event->button->touch != 1) { // digital @@ -46,15 +45,15 @@ static void gpioTask(void* x) { void IRAM_ATTR isr(void *e){ button_event_t *event = (button_event_t*)e; event->val = digitalRead(event->pin); + isr_log_d("read %d",event->val); xQueueSendFromISR(gpio_queue_handle, &event, NULL); } void IRAM_ATTR touch_isr(void *e){ - // isr_log_i("touch isr"); button_event_t *event = (button_event_t*)e; uint32_t pad_intr = touch_pad_get_status(); touch_pad_clear_status(); - // send the whole register to the queue so the other pad interrupts can read it even though its bee cleared + // send the whole register to the queue so the other pad interrupts can read it even though its been cleared event->val = pad_intr; xQueueSendFromISR(gpio_queue_handle, &event, NULL); } @@ -67,6 +66,7 @@ Button::Button(int pin, int mode, int dbnc){ this->touch = false; this->handlePress = NULL; this->handleRelease = NULL; + this->pressed = false; event.pin = pin; event.button = this; // gpio_reset_pin(gpioNumToGpioNum_T(pin)); @@ -78,6 +78,7 @@ Button::Button(int pin, int mode, int dbnc, bool touch){ this->dbnc = dbnc; this->last = 0; this->touch = true; + this->pressed = false; this->handlePress = NULL; this->handleRelease = NULL; event.pin = pin; @@ -86,7 +87,7 @@ Button::Button(int pin, int mode, int dbnc, bool touch){ } Button::~Button(){ - log_i("destructor button on %u",pin); + log_d("destructor button on %u",pin); detachInterrupt(pin); } @@ -105,51 +106,67 @@ void Button::onPress(void(*handlePress)()){ } void Button::onRelease(void(*handleRelease)()){ - this->handleRelease=handleRelease; - attachInterruptArg(pin, isr, (void*)&event, CHANGE); + if(this->touch != 1) + { + // digital read mode + this->handleRelease=handleRelease; + attachInterruptArg(pin, isr, (void*)&event, CHANGE); + } + else + { + // capacitive touch mode has no onRelease() + return; + } } void Button::handleChange(int val){ + log_d("pin:%d val:%d",pin,val); // if EDGE_NONE then ignore - log_i("pin:%d val:%d",pin,val); if(mode != RISING && mode != FALLING) return; int now = millis(); if((now - last) > dbnc){ - last = now; + // last = now; if( - (val==0 && mode == FALLING) || - (val==1 && mode == RISING) + (val==0 && mode == FALLING && !pressed) || + (val==1 && mode == RISING && !pressed) ){ if(handlePress != NULL) { handlePress(); } + last = now; } - else - { - if(handleRelease != NULL) + else if( + (val==1 && mode == FALLING && pressed) || + (val==0 && mode == RISING && pressed) + ){ + if(handleRelease != NULL && pressed) { handleRelease(); } + last = now; } } + // make sure the pressed state updates even when debounced (this isr logic is annoying) + // touch pins have no such concept + if(!touch) + { + pressed = (val==0 && mode==FALLING) || (val==1 && mode==RISING); + log_d("pressed %d", pressed); + } } static bool touch_initialized = false; void init_touch(void) { - log_i("*"); touch_pad_init(); touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); - // touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); - // touch_initialized = true; } void init_touch_pad(int pin, void *event) { - log_i("*"); if(!touch_initialized) { init_touch(); @@ -161,7 +178,7 @@ void init_touch_pad(int pin, void *event) touch_pad_read_filtered( gpioNumToTPNum(pin), &touch_value); ESP_ERROR_CHECK(touch_pad_set_thresh( gpioNumToTPNum(pin), touch_value * 2 / 3)); - log_i("touch setup TPNUM:%d touchValue:%d",gpioNumToTPNum(pin),touch_value); + log_d("touch setup TPNUM:%d touchValue:%d",gpioNumToTPNum(pin),touch_value); touch_pad_isr_register(touch_isr, (void*)event); touch_pad_intr_enable(); } diff --git a/src/button.h b/src/button.h index a060b9d..93f3d80 100644 --- a/src/button.h +++ b/src/button.h @@ -10,6 +10,7 @@ class Button { int last; int mode; bool touch; + bool pressed; void (*handlePress)(); void (*handleRelease)(); button_event_t event; diff --git a/src/defines.h b/src/defines.h new file mode 100644 index 0000000..e20475a --- /dev/null +++ b/src/defines.h @@ -0,0 +1,7 @@ +#ifndef DEFINES_H +#define DEFINES_H + +// #define CONFIG_ASYNC_TCP_RUNNING_CORE 0 +// #define CONFIG_ASYNC_TCP_USE_WDT 0 + +#endif \ No newline at end of file diff --git a/src/emmc.c b/src/emmc.c index 4f84797..d0123a3 100644 --- a/src/emmc.c +++ b/src/emmc.c @@ -43,25 +43,13 @@ esp_err_t emmc_read(void *dst, size_t start_sector, size_t sector_count) void emmc_init(void) { - wlog_i("********************"); - wlog_i("hello from emmc"); - wlog_i("*********************"); sdmmc_host_t host = SDMMC_HOST_DEFAULT(); sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); - // slot_config.width = 4; -// slot_config.width = 1; host.flags = SDMMC_HOST_FLAG_4BIT; -// host.flags = SDMMC_HOST_FLAG_1BIT; - host.max_freq_khz = SDMMC_FREQ_52M; - // host.max_freq_khz = SDMMC_FREQ_HIGHSPEED; - // host.max_freq_khz = 80000; - // host.max_freq_khz = SDMMC_FREQ_DEFAULT; - // host.max_freq_khz = SDMMC_FREQ_PROBING; - ret = sdmmc_host_set_bus_ddr_mode(SDMMC_HOST_SLOT_1, true); if(ret != ESP_OK){ - log_i( "sdmmc_host_init : %s", esp_err_to_name(ret)); + log_e( "sdmmc_host_init : %s", esp_err_to_name(ret)); } gpio_set_pull_mode(15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes gpio_set_pull_mode(2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes diff --git a/src/file_system.c b/src/file_system.c index 4e19c5d..dd725c2 100644 --- a/src/file_system.c +++ b/src/file_system.c @@ -66,7 +66,7 @@ // char waver_tag[METADATA_TAG_LENGTH] = "wvr_magic_10"; -char waver_tag[METADATA_TAG_LENGTH] = "wvr_magic_11"; +char waver_tag[METADATA_TAG_LENGTH] = "wvr_magic_12"; static const char* TAG = "file_system"; // declare prototypes from emmc.c @@ -286,7 +286,7 @@ void init_rack_lut(void){ rack_lut[j] = blank; } struct rack_file_t *buf = (struct rack_file_t*)ps_malloc(RACK_DIRECTORY_BLOCKS * SECTOR_SIZE); - if(buf == NULL){log_i("failed to alloc rack_file_t buf");}; + if(buf == NULL){log_e("failed to alloc rack_file_t buf");}; for(int k=0; k < NUM_RACK_DIRECTORY_ENTRIES; k++){ buf[k] = blank_file; } @@ -318,7 +318,7 @@ void init_firmware_lut(void){ void write_firmware_lut_to_disk(void){ // log_i("writting firmware wav_lut to disk"); struct firmware_t *buf = (struct firmware_t*)ps_malloc(FIRMWARE_LUT_BLOCKS * SECTOR_SIZE); - if(buf == NULL){log_i("failed to alloc firmware_t buf");}; + if(buf == NULL){log_e("failed to alloc firmware_t buf");}; // log_i("allocated buffer of %u blocks for %u firmwares to write to disk", FIRMWARE_LUT_BLOCKS, MAX_FIRMWARES); for(int i=0; i< MAX_FIRMWARES; i++){ buf[i] = firmware_lut[i]; @@ -1147,7 +1147,7 @@ void log_pin_config(void) { for(int i=0;i<14;i++) { - log_i("pin %d action:%d edge:%d gpio:%d note:%d touch:%d velocity:%d dbnc:%d", + log_d("pin %d action:%d edge:%d gpio:%d note:%d touch:%d velocity:%d dbnc:%d", i, pin_config_lut[i].action, pin_config_lut[i].edge, diff --git a/src/file_system.h b/src/file_system.h index c5db5ff..7301067 100644 --- a/src/file_system.h +++ b/src/file_system.h @@ -168,17 +168,10 @@ struct rack_file_t { uint8_t free; }; -// static struct metadata_t metadata; -// static struct wav_lu_t **wav_lut; -// static struct firmware_t *firmware_lut; -// static struct website_t *website_lut; -// static struct rack_lu_t *rack_lut; -// static struct pin_config_t *pin_config_lut; - static struct pin_config_t default_pin_config_array[14] = { { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D0, .note = 40, .touch = -1, //no touch on this pin @@ -187,7 +180,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D1, .note = 41, .touch = -1, //no touch on this pin @@ -196,7 +189,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D2, .note = 42, .touch = -1, //no touch on this pin @@ -205,7 +198,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D3, .note = 43, .touch = -1, //no touch on this pin @@ -214,7 +207,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D4, .note = 44, .touch = -1, //no touch on this pin @@ -223,7 +216,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D5, .note = 45, .touch = -1, //no touch on this pin @@ -232,7 +225,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D6, .note = 46, .touch = 0, @@ -277,7 +270,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D11, .note = 51, .touch = 0, @@ -286,7 +279,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D12, .note = 52, .touch = 0, @@ -295,7 +288,7 @@ static struct pin_config_t default_pin_config_array[14] = { }, { .action = NOTE_ON, - .edge = EDGE_FALLING, + .edge = EDGE_NONE, .gpio_num = D13, .note = 53, .touch = 0, diff --git a/src/gpio.cpp b/src/gpio.cpp index 0dd5721..28ded1b 100644 --- a/src/gpio.cpp +++ b/src/gpio.cpp @@ -10,6 +10,7 @@ #include "WVR.h" #include "midi_in.h" #include "server.h" +#include "gpio.h" // extern "C" { // #include "wav_player.h" @@ -33,6 +34,17 @@ extern "C" { QueueHandle_t wav_player_queue; } +void on_release_per_config(int pin_num) +{ + uint8_t *channel_lut = get_channel_lut(); + struct pin_config_t pin = pin_config_lut[pin_num]; + wav_player_event.code = MIDI_NOTE_OFF; + wav_player_event.note = pin.note; + wav_player_event.velocity = pin.velocity; + wav_player_event.voice = channel_lut[0]; + xQueueSendToBack(wav_player_queue, (void *)&wav_player_event, portMAX_DELAY); +} + void on_press_per_config(int pin_num) { uint8_t *channel_lut = get_channel_lut(); @@ -93,9 +105,12 @@ void on_press_per_config(int pin_num) } } -void wvr_gpio_init(void) +void wvr_gpio_init(bool useFTDI, bool useUsbMidi) { - for(int i=2;i<14;i++) + log_i("useFTDI is %d",useFTDI); + int start = useFTDI ? useUsbMidi ? 3 : 2 : 0; + log_i("gpio start is %d",start); + for(int i=start;i<14;i++) { gpio_num_t gpio_num = gpio_pins[i]; int pin_num = wvr_pins[i]; @@ -115,7 +130,7 @@ void wvr_gpio_init(void) } else if(pin.edge == EDGE_RISING) { - pinMode(pin_num, INPUT_PULLDOWN); + pinMode(pin_num, INPUT_PULLUP); buttons[i] = new Button(pin_num, RISING, pin.debounce); } } @@ -126,17 +141,31 @@ void wvr_gpio_init(void) } } if(buttons[0] != NULL) buttons[0]->onPress([](){on_press_per_config(0);}); + if(buttons[0] != NULL) buttons[0]->onRelease([](){on_release_per_config(0);}); if(buttons[1] != NULL) buttons[1]->onPress([](){on_press_per_config(1);}); + if(buttons[1] != NULL) buttons[1]->onRelease([](){on_release_per_config(1);}); if(buttons[2] != NULL) buttons[2]->onPress([](){on_press_per_config(2);}); + if(buttons[2] != NULL) buttons[2]->onRelease([](){on_release_per_config(2);}); if(buttons[3] != NULL) buttons[3]->onPress([](){on_press_per_config(3);}); + if(buttons[3] != NULL) buttons[3]->onRelease([](){on_release_per_config(3);}); if(buttons[4] != NULL) buttons[4]->onPress([](){on_press_per_config(4);}); + if(buttons[4] != NULL) buttons[4]->onRelease([](){on_release_per_config(4);}); if(buttons[5] != NULL) buttons[5]->onPress([](){on_press_per_config(5);}); + if(buttons[5] != NULL) buttons[5]->onRelease([](){on_release_per_config(5);}); if(buttons[6] != NULL) buttons[6]->onPress([](){on_press_per_config(6);}); + if(buttons[6] != NULL) buttons[6]->onRelease([](){on_release_per_config(6);}); if(buttons[7] != NULL) buttons[7]->onPress([](){on_press_per_config(7);}); + if(buttons[7] != NULL) buttons[7]->onRelease([](){on_release_per_config(7);}); if(buttons[8] != NULL) buttons[8]->onPress([](){on_press_per_config(8);}); + if(buttons[8] != NULL) buttons[8]->onRelease([](){on_release_per_config(8);}); if(buttons[9] != NULL) buttons[9]->onPress([](){on_press_per_config(9);}); + if(buttons[9] != NULL) buttons[9]->onRelease([](){on_release_per_config(9);}); if(buttons[10] != NULL) buttons[10]->onPress([](){on_press_per_config(10);}); + if(buttons[10] != NULL) buttons[10]->onRelease([](){on_release_per_config(10);}); if(buttons[11] != NULL) buttons[11]->onPress([](){on_press_per_config(11);}); + if(buttons[11] != NULL) buttons[11]->onRelease([](){on_release_per_config(11);}); if(buttons[12] != NULL) buttons[12]->onPress([](){on_press_per_config(12);}); + if(buttons[12] != NULL) buttons[12]->onRelease([](){on_release_per_config(12);}); if(buttons[13] != NULL) buttons[13]->onPress([](){on_press_per_config(13);}); + if(buttons[13] != NULL) buttons[13]->onRelease([](){on_release_per_config(13);}); } \ No newline at end of file diff --git a/src/gpio.h b/src/gpio.h index 9df401d..b7ab770 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -1,7 +1,11 @@ #ifndef GPIO_H #define GPIO_H -void wvr_gpio_init(void); +#include "button.h" + +extern Button *buttons[14]; + +void wvr_gpio_init(bool useFTDI, bool useUsbMidi); void on_press(uint8_t i); void on_release(uint8_t pin); diff --git a/src/midi.cpp b/src/midi.cpp index 21c2601..518452e 100644 --- a/src/midi.cpp +++ b/src/midi.cpp @@ -16,22 +16,11 @@ extern "C" uint8_t* midi_parse(uint8_t in) { if ( midiParser.parse( in ) ) // Do we received a channel voice msg ? { - if ( midiParser.isMidiStatus(midiXparser::noteOnStatus) || midiParser.isMidiStatus(midiXparser::noteOffStatus) || midiParser.isMidiStatus(midiXparser::programChangeStatus) ) + if ( midiParser.isMidiStatus(midiXparser::noteOnStatus) || midiParser.isMidiStatus(midiXparser::noteOffStatus) || midiParser.isMidiStatus(midiXparser::programChangeStatus) || midiParser.isMidiStatus(midiXparser::controlChangeStatus) ) { - // if ( midiParser.isMidiStatus(midiXparser::noteOnStatus)){ - // log_i("on"); - // } - // if ( midiParser.isMidiStatus(midiXparser::noteOffStatus)){ - // log_i("off"); - // } msg = midiParser.getMidiMsg(); return msg; } - // if ( midiParser.isMidiStatus(midiXparser::noteOffStatus) || midiParser.isMidiStatus(midiXparser::noteOnStatus) ) { - // log_i("got message"); - // delay(200); - // Serial.write(midiParser1.getMidiMsg(),midiParser1.getMidiMsgLen()); - // Serial.write(midiParser1.getMidiMsg(),midiParser1.getMidiMsgLen()); } return NULL; } diff --git a/src/midi_in.c b/src/midi_in.c index f5e546c..e1961fc 100644 --- a/src/midi_in.c +++ b/src/midi_in.c @@ -10,13 +10,12 @@ #include "wav_player.h" #include "file_system.h" -// #define MIDI_UART_NUM UART_NUM_1 #define MIDI_UART_NUM UART_NUM_2 #define BUF_SIZE (1024) #define RD_BUF_SIZE (BUF_SIZE) -// #define RX_PIN 18 // opto test -#define RX_PIN 23 // wrv midi in +#define MIDI_RX_PIN 23 // wrv midi in +#define USB_MIDI_RX_PIN 21 static const char *TAG = "midi"; @@ -34,23 +33,56 @@ struct wav_player_event_t wav_player_event; int bytes_read; uint8_t *msg; -void init_gpio(void) +void init_gpio(bool useUsbMidi) { gpio_config_t io_conf; io_conf.mode = GPIO_MODE_INPUT; - io_conf.pull_up_en = GPIO_PULLUP_DISABLE; + io_conf.pull_up_en = GPIO_PULLUP_ENABLE; io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; - io_conf.pin_bit_mask = (1 << GPIO_NUM_23); // WVR MIDI IN -// io_conf.pin_bit_mask = (1 << GPIO_NUM_18); // opto tests -// io_conf.pin_bit_mask = (1 << GPIO_NUM_5); // USB MIDI -// io_conf.pin_bit_mask = (1 << GPIO_NUM_16); // ?? + if(useUsbMidi) + { + io_conf.pin_bit_mask = (1 << GPIO_NUM_21); // USB MIDI + } + else + { + io_conf.pin_bit_mask = (1 << GPIO_NUM_23); // WVR MIDI IN + } +// io_conf.pin_bit_mask = (1 << GPIO_NUM_23); // WVR MIDI IN +// io_conf.pin_bit_mask = (1 << GPIO_NUM_21); // USB MIDI io_conf.intr_type = GPIO_INTR_DISABLE; gpio_config(&io_conf); } +void init_uart(bool useUsbMidi) +{ + uart_config_t uart_config = { + .baud_rate = 31250, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE + }; + ESP_ERROR_CHECK(uart_param_config(MIDI_UART_NUM, &uart_config)); + if(useUsbMidi) + { + ESP_ERROR_CHECK(uart_set_pin(MIDI_UART_NUM, UART_PIN_NO_CHANGE, USB_MIDI_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); + } + else + { + ESP_ERROR_CHECK(uart_set_pin(MIDI_UART_NUM, UART_PIN_NO_CHANGE, MIDI_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); + } + // ESP_ERROR_CHECK(uart_set_pin(MIDI_UART_NUM, UART_PIN_NO_CHANGE, RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); + ESP_ERROR_CHECK(uart_driver_install(MIDI_UART_NUM,1024, 0, 1024, &uart_queue, 0)); + ESP_ERROR_CHECK(uart_set_rx_timeout(MIDI_UART_NUM, 1)); +} + #define MIDI_BUFFER_SIZE 256 uint8_t channel_lut[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +struct pan_t channel_pan[16] = {FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE,FX_NONE}; + +float eq_high; +float eq_low; uint8_t *get_channel_lut(void) { @@ -62,17 +94,17 @@ static void read_uart_task() uart_event_t event; uint8_t* tmp = (uint8_t*)malloc(MIDI_BUFFER_SIZE); - uart_config_t uart_config = { - .baud_rate = 31250, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE - }; - ESP_ERROR_CHECK(uart_param_config(MIDI_UART_NUM, &uart_config)); - ESP_ERROR_CHECK(uart_set_pin(MIDI_UART_NUM, UART_PIN_NO_CHANGE, RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); - ESP_ERROR_CHECK(uart_driver_install(MIDI_UART_NUM, 256, 0, 256, &uart_queue, 0)); - ESP_ERROR_CHECK(uart_set_rx_timeout(MIDI_UART_NUM, 1)); + // uart_config_t uart_config = { + // .baud_rate = 31250, + // .data_bits = UART_DATA_8_BITS, + // .parity = UART_PARITY_DISABLE, + // .stop_bits = UART_STOP_BITS_1, + // .flow_ctrl = UART_HW_FLOWCTRL_DISABLE + // }; + // ESP_ERROR_CHECK(uart_param_config(MIDI_UART_NUM, &uart_config)); + // ESP_ERROR_CHECK(uart_set_pin(MIDI_UART_NUM, UART_PIN_NO_CHANGE, RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); + // ESP_ERROR_CHECK(uart_driver_install(MIDI_UART_NUM,1024, 0, 1024, &uart_queue, 0)); + // ESP_ERROR_CHECK(uart_set_rx_timeout(MIDI_UART_NUM, 1)); if(tmp == NULL) { @@ -87,8 +119,13 @@ static void read_uart_task() if(event.type==UART_DATA) { bytes_read = uart_read_bytes(MIDI_UART_NUM, tmp, event.size, portMAX_DELAY); + // for(int i=0;i 64) + { + channel_pan[channel].right_vol = 127; + channel_pan[channel].left_vol = 127 - ((val - 64) * 2); + } + else if(val < 64) + { + channel_pan[channel].right_vol = 127 - ((64 - val) * 2); + channel_pan[channel].left_vol = 127; + } + break; + case MIDI_CC_EQ_BASS: + eq_low = ((val * 2.0) / 127) - 1; + break; + case MIDI_CC_EQ_TREBLE: + eq_high = ((val * 2.0) / 127); + break; + default: + break; + } + } default: break; } @@ -151,9 +241,10 @@ static void read_uart_task() } } -void midi_init(void) +void midi_init(bool useUsbMidi) { - init_gpio(); + init_gpio(useUsbMidi); + init_uart(useUsbMidi); xTaskCreatePinnedToCore(read_uart_task, "read_uart_task", 4096, NULL, 3, NULL, 0); // xTaskCreatePinnedToCore(read_uart_task, "read_uart_task", 4096, NULL, 3, NULL, 1); } \ No newline at end of file diff --git a/src/midi_in.h b/src/midi_in.h index da6429f..7ec372c 100644 --- a/src/midi_in.h +++ b/src/midi_in.h @@ -8,6 +8,10 @@ #define MIDI_NOTE_OFF 8 #define MIDI_NOTE_ON 9 #define MIDI_PROGRAM_CHANGE 12 +#define MIDI_CC 11 +#define MIDI_CC_PAN 10 +#define MIDI_CC_EQ_BASS 20 +#define MIDI_CC_EQ_TREBLE 21 struct midi_event_t { uint8_t code; diff --git a/src/rpc.c b/src/rpc.c index 51d9839..bddbd12 100644 --- a/src/rpc.c +++ b/src/rpc.c @@ -10,6 +10,7 @@ #include "midi_in.h" #include "rpc.h" #include "wav_player.h" +#include "file_system.h" // QueueHandle_t rpc_in_queue; QueueHandle_t rpc_out_queue; @@ -17,7 +18,7 @@ QueueHandle_t rpc_out_queue; TaskHandle_t rpc_out_task_handle; BaseType_t task_return; -#define NO_RPC_OUT 0 +#define NO_RPC_OUT 1 void sendWSMsg(char* msg); @@ -63,6 +64,8 @@ char* on_rpc_in(cJSON *json) } } +extern struct metadata_t metadata; + void rpc_out_task(void* pvParameters) { struct rpc_event_t event; @@ -70,7 +73,12 @@ void rpc_out_task(void* pvParameters) if(xQueueReceive(rpc_out_queue, (void *)&event, (portTickType)portMAX_DELAY)) { - log_v("rpc_out_task received event"); + log_d("rpc_out_task received event"); + if(metadata.wlog_verbosity == 0) + { + // dont do RPC if UI log level is "NONE" + continue; + } cJSON *rpc_root = cJSON_CreateObject(); switch(event.procedure){ case RPC_NOTE_ON: @@ -101,5 +109,5 @@ void rpc_init(void) // rpc_in_queue = xQueueCreate(20, sizeof(struct rpc_event_t)); rpc_out_queue = xQueueCreate(20, sizeof(struct rpc_event_t)); // task_return = xTaskCreate(rpc_in_task,"rpc_in_task", 1024, NULL, 1, rpc_in_task_handle); - task_return = xTaskCreatePinnedToCore(rpc_out_task,"rpc_out_task", 1024 * 4, NULL, 3, rpc_out_task_handle,0); + task_return = xTaskCreatePinnedToCore(rpc_out_task,"rpc_out_task", 1024 * 4, NULL, 2, rpc_out_task_handle,0); } \ No newline at end of file diff --git a/src/server.cpp b/src/server.cpp index 701c613..56f9e66 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,3 +1,7 @@ +// #define CONFIG_ASYNC_TCP_RUNNING_CORE 0 +// #define CONFIG_ASYNC_TCP_USE_WDT 0 + +#include "defines.h" #include "Arduino.h" #include @@ -29,7 +33,8 @@ extern "C" void updateMetadata(char* json); extern "C" char* on_rpc_in(cJSON* json); extern "C" char* write_recovery_firmware_to_emmc(uint8_t* source, size_t size); extern "C" char* close_recovery_firmware_to_emmc(size_t recovery_firmware_size); -// extern "C" size_t add_firmware_and_gui_to_file_system(char *gui_name,char *firmware_name,size_t gui_start_block,size_t firmware_start_block,size_t gui_size,size_t firmware_size); +extern "C" void wav_player_pause(void); +extern "C" void wav_player_resume(void); static struct metadata_t *metadata = get_metadata(); struct wav_lu_t **lut; @@ -37,7 +42,7 @@ struct firmware_t *firmware_lut; struct website_t *website_lut; void bootFromEmmc(int index); -void wifi_log_boot_stage(void); +void on_ws_connect(void); const char *ssid = "yourAP"; const char *password = "yourPassword"; @@ -63,92 +68,23 @@ cJSON *ws_root; void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ if(type == WS_EVT_CONNECT){ Serial.printf("ws[%s][%u] connect\n", server->url(), client->id()); - client->printf("Hello Client %u :) firmware v%s", client->id(), VERSION_CODE); - wifi_log_boot_stage(); + client->printf("ws_client %u", client->id()); + client->printf("firmware v%s", VERSION_CODE); + on_ws_connect(); client->ping(); } else if(type == WS_EVT_DISCONNECT){ Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id()); } else if(type == WS_EVT_ERROR){ Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data); } else if(type == WS_EVT_PONG){ - Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:""); + // Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:""); } else if(type == WS_EVT_DATA){ AwsFrameInfo * info = (AwsFrameInfo*)arg; String msg = ""; if(info->final && info->index == 0 && info->len == len){ //the whole message is in a single frame and we got all of it's data - - ///////////////// - // receive RPC // - ///////////////// - ws_root = cJSON_Parse((char *)data); - // int procedure = cJSON_GetObjectItem(ws_root,"procedure")->valueint; - // wlog_i("ws procedure: %d",procedure); on_rpc_in(ws_root); - // switch(procedure){ - // case(NOTE_ON): - // // play note - // break; - // default: - // wlog_i("RPC received unknown procedure code: %d", procedure); - // break; - // } - - ///////////////// - ////// end ////// - ///////////////// - - // Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len); - // if(info->opcode == WS_TEXT){ - // for(size_t i=0; i < info->len; i++) { - // msg += (char) data[i]; - // } - // } else { - // char buff[3]; - // for(size_t i=0; i < info->len; i++) { - // sprintf(buff, "%02x ", (uint8_t) data[i]); - // msg += buff ; - // } - // } - // Serial.printf("%s\n",msg.c_str()); - - // if(info->opcode == WS_TEXT) - // client->text("I got your text message"); - // else - // client->binary("I got your binary message"); - // } else { - // //message is comprised of multiple frames or the frame is split into multiple packets - // if(info->index == 0){ - // if(info->num == 0) - // Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); - // Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len); - // } - - // Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len); - - // if(info->opcode == WS_TEXT){ - // for(size_t i=0; i < len; i++) { - // msg += (char) data[i]; - // } - // } else { - // char buff[3]; - // for(size_t i=0; i < len; i++) { - // sprintf(buff, "%02x ", (uint8_t) data[i]); - // msg += buff ; - // } - // } - // Serial.printf("%s\n",msg.c_str()); - // if((info->index + len) == info->len){ - // Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len); - // if(info->final){ - // Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); - // if(info->message_opcode == WS_TEXT) - // client->text("I got your text message"); - // else - // client->binary("I got your binary message"); - // } - // } } } } @@ -165,11 +101,16 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, } } +int loop_num = 0; + void handleUpdate(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ if(!index){ + wav_player_pause(); + loop_num = 0; Update.begin(total); Serial.println("starting update"); } + feedLoopWDT(); size_t written = Update.write(data,len); if(written != len){ Serial.println("write failed"); @@ -177,8 +118,14 @@ void handleUpdate(AsyncWebServerRequest *request, uint8_t *data, size_t len, siz Update.abort(); return; } - Serial.print("."); + + if(loop_num++ % 20 == 0) + { + Serial.print("."); + } + if(index + len == total){ + feedLoopWDT(); Serial.println("."); if(Update.end()){ if(Update.isFinished()){ @@ -196,6 +143,7 @@ void handleUpdate(AsyncWebServerRequest *request, uint8_t *data, size_t len, siz Serial.println("failed"); } request->send(204); + wav_player_resume(); } } @@ -204,6 +152,7 @@ uint8_t *voice_config_json = NULL; void handleUpdateVoiceConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ if(index==0){ //start + wav_player_pause(); voice_config_json = (uint8_t*)ps_malloc(total + 1); if(!voice_config_json){ wlog_i("failed to malloc for json"); @@ -213,11 +162,14 @@ void handleUpdateVoiceConfig(AsyncWebServerRequest *request, uint8_t *data, size for(int i=0;isend(200, "text/plain", "all done voice config update"); + wav_player_resume(); } } @@ -226,6 +178,7 @@ uint8_t *pin_config_json = NULL; void handleUpdatePinConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ if(index==0){ //start + wav_player_pause(); pin_config_json = (uint8_t*)ps_malloc(total); if(!pin_config_json){ wlog_i("failed to malloc for json"); @@ -235,11 +188,13 @@ void handleUpdatePinConfig(AsyncWebServerRequest *request, uint8_t *data, size_t for(int i=0;isend(200, "text/plain", "all done pin config update"); + wav_player_resume(); } } @@ -248,6 +203,7 @@ uint8_t *metadata_json = NULL; void handleUpdateMetadata(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ if(index==0){ //start + wav_player_pause(); metadata_json = (uint8_t*)ps_malloc(total); if(!metadata_json){ wlog_i("failed to malloc for metadata json"); @@ -257,11 +213,13 @@ void handleUpdateMetadata(AsyncWebServerRequest *request, uint8_t *data, size_t for(int i=0;isend(200, "text/plain", "all done pin config update"); + wav_player_resume(); } } @@ -275,6 +233,7 @@ size_t w_start_block; void handleWav(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ if(index==0){ //start + wav_player_pause(); AsyncWebHeader* size_string = request->getHeader("size"); sscanf(size_string->value().c_str(), "%d", &w_size); AsyncWebHeader* name = request->getHeader("name"); @@ -286,6 +245,7 @@ void handleWav(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t w_start_block = find_gap_in_file_system(w_size); } //always + feedLoopWDT(); write_wav_to_emmc(data, w_start_block, len); w_bytes_read += len; if(index + len == total){ @@ -293,6 +253,7 @@ void handleWav(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t close_wav_to_emmc(); add_wav_to_file_system(&w_name[0],w_voice,w_note,w_start_block,total); request->send(200, "text/plain", "done upload wav"); + wav_player_resume(); } } @@ -306,6 +267,7 @@ size_t r_start_block; void handleRack(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ if(index==0){ //start + wav_player_pause(); strcpy(&r_name[0], request->getHeader("name")->value().c_str()); sscanf(request->getHeader("voice")->value().c_str(), "%d", &r_voice); sscanf(request->getHeader("note")->value().c_str(), "%d", &r_note); @@ -315,6 +277,7 @@ void handleRack(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_ r_start_block = find_gap_in_file_system(total); } //always + feedLoopWDT(); write_wav_to_emmc(data, r_start_block, len); w_bytes_read += len; if(index + len == total){ @@ -322,6 +285,7 @@ void handleRack(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_ close_wav_to_emmc(); add_rack_to_file_system(&r_name[0],r_voice,r_note,r_start_block,total,r_layer,r_rack_json); free(r_rack_json); + wav_player_resume(); } } @@ -336,6 +300,7 @@ char f_firmware_name[24]; void handleNewFirmware(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ //once if(index==0){ + wav_player_pause(); AsyncWebHeader* firmware_slot_string = request->getHeader("slot-index"); sscanf(firmware_slot_string->value().c_str(), "%d", &f_firmware_slot); AsyncWebHeader* firmware_size_string = request->getHeader("firmware-size"); @@ -355,16 +320,19 @@ void handleNewFirmware(AsyncWebServerRequest *request, uint8_t *data, size_t len } Serial.print("."); + feedLoopWDT(); write_firmware_to_emmc(f_firmware_slot, data, len); f_bytes_read += len; //done if(index + len == total){ + feedLoopWDT(); close_firmware_to_emmc(f_firmware_slot); log_i("done"); log_i("wrote %u bytes",f_bytes_read); f_bytes_read = 0; request->send(200, "text/plain", "all done firmware"); + wav_player_resume(); } } @@ -379,35 +347,30 @@ size_t rf_firmware_size; void handleNewRecoveryFirmware(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){ //once if(index==0){ - // AsyncWebHeader* firmware_slot_string = request->getHeader("slot-index"); - // sscanf(firmware_slot_string->value().c_str(), "%d", &f_firmware_slot); + wav_player_pause(); AsyncWebHeader* firmware_size_string = request->getHeader("firmware-size"); sscanf(firmware_size_string->value().c_str(), "%d", &rf_firmware_size); - // AsyncWebHeader* firmware_name_string = request->getHeader("firmware-name"); - // strcpy(&f_firmware_name[0], firmware_name_string->value().c_str()); - // log_i("firmware size %u, firmware name %s",f_firmware_size,f_firmware_name); - - // struct firmware_t *f = get_firmware_slot(-1); - // f->length = rf_firmware_size; - // strcpy(f->name, firmware_name_string->value().c_str()); } - //always if(rf_firmware_size > MAX_FIRMWARE_SIZE){ request->send(400, "text/plain", "FILES TOO LARGE"); return; } Serial.print("."); + feedLoopWDT(); write_recovery_firmware_to_emmc(data, len); rf_bytes_read += len; //done if(index + len == total){ + feedLoopWDT(); close_recovery_firmware_to_emmc(total); + feedLoopWDT(); log_i("done"); log_i("wrote %u bytes",rf_bytes_read); rf_bytes_read = 0; request->send(200, "text/plain", "all done recovery firmware"); + wav_player_resume(); } } @@ -427,9 +390,11 @@ void handleNewGUI(AsyncWebServerRequest *request, uint8_t *data, size_t len, siz struct website_t *w = get_website_slot(f_firmware_slot); w->length = f_gui_size; strcpy(w->name, gui_name_string->value().c_str()); + feedLoopWDT(); } //always if((f_firmware_size > MAX_FIRMWARE_SIZE) || (f_gui_size > MAX_WEBSITE_SIZE)){ + feedLoopWDT(); request->send(400, "text/plain", "FILES TOO LARGE"); return; } @@ -440,6 +405,7 @@ void handleNewGUI(AsyncWebServerRequest *request, uint8_t *data, size_t len, siz //done if(index + len == total){ + feedLoopWDT(); close_website_to_emmc(f_firmware_slot); log_i("done"); log_i("wrote %u bytes",f_bytes_read); @@ -449,10 +415,12 @@ void handleNewGUI(AsyncWebServerRequest *request, uint8_t *data, size_t len, siz } void handleFsjson(AsyncWebServerRequest *request){ + // wav_player_pause(); char *json = print_fs_json(); size_t size = strlen(json); // wlog_e("fs size is %d",size); AsyncWebServerResponse *response = request->beginResponse("text/html", size, [size,json](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { + feedLoopWDT(); size_t toWrite = min(size - index, maxLen); memcpy(buffer, json + index, toWrite); if(index + toWrite == size){ @@ -462,6 +430,7 @@ void handleFsjson(AsyncWebServerRequest *request){ }); response->addHeader("size",String(size)); request->send(response); + // wav_player_resume(); // request->send("text/html", size, [size,json](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { // size_t toWrite = min(size - index, maxLen); // memcpy(buffer, json + index, toWrite); @@ -476,6 +445,7 @@ void handleEmmcGUI(AsyncWebServerRequest *request){ size_t size = website_lut[metadata->current_website_index].length; size_t start_block = website_lut[metadata->current_website_index].start_block; request->send("text/html", size, [size,start_block](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { + feedLoopWDT(); size_t toWrite = min(size - index, maxLen); size_t written = get_website_chunk(start_block, toWrite, buffer, size); // memcpy(buffer, buf, toWrite); @@ -486,6 +456,7 @@ void handleEmmcGUI(AsyncWebServerRequest *request){ void handleMain(AsyncWebServerRequest *request){ size_t size = sizeof(MAIN_page) / sizeof(char); request->send("text/html", size, [size](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { + feedLoopWDT(); size_t toWrite = min(size - index, maxLen); memcpy(buffer, MAIN_page + index, toWrite); return toWrite; @@ -500,6 +471,7 @@ void handleRPC(AsyncWebServerRequest *request){ } void handleBootFromEmmc(AsyncWebServerRequest *request){ + wav_player_pause(); char index = 0; AsyncWebHeader* firmware_slot_string = request->getHeader("index"); sscanf(firmware_slot_string->value().c_str(), "%d", &index); diff --git a/src/wav_player.c b/src/wav_player.c index 2e84a3a..14da6d6 100644 --- a/src/wav_player.c +++ b/src/wav_player.c @@ -31,22 +31,22 @@ static const char* TAG = "wav_player"; #define DAC_BUFFER_SIZE_IN_BYTES ( DAC_BUFFER_SIZE_IN_SAMPLES * sizeof(int16_t) ) #define LOOPS_PER_BUFFER ( BYTES_PER_READ / DAC_BUFFER_SIZE_IN_BYTES ) -// #define NUM_BUFFERS 18 +#define NUM_BUFFERS 18 // #define NUM_BUFFERS 20 -#define NUM_BUFFERS 22 -// #define NUM_BUFFERS 25 -// #define DAMPEN_BITS 2 #define DAMPEN_BITS 1 -// #define USE_SQRT_SCALE 0 -// #define USE_VOLUME 0 -// #define USE_VOLUME_FP 1 -// #define USE_VOLUME_FP_SQRT 0 #define LOG_PERFORMANCE 0 #define MAX_READS_PER_LOOP 4 // #define MAX_READS_PER_LOOP 3 +#define USE_EQ 1 +#define USE_PAN 1 + +// from midi.c +uint8_t channel_lut[16]; +struct pan_t channel_pan[16]; + struct metadata_t metadata; bool mute = false; struct buf_t { @@ -83,7 +83,6 @@ esp_err_t dac_write(const void *src, size_t size, size_t *bytes_written); void dac_pause(void); void dac_resume(void); -int16_t sqrtLUT[128]; struct buf_t bufs[NUM_BUFFERS]; int16_t *output_buf; @@ -91,6 +90,8 @@ struct wav_player_event_t wav_player_event; int new_midi = 0; int new_midi_buf = -1; +int16_t sqrtLUT[128]; +float sqrt_float_LUT[128]; float float_lut[128]; uint32_t tmp32; @@ -146,8 +147,13 @@ void init_float_lut(void) { for(int i=0;i<128;i++) { - float num = (float)i/127; + // float_lut + float num = (float)i/127.0; float_lut[i] = num; + // sqrt_float_lut + float a = (float)sqrt(i * 127.0); + float b = a / 127; + sqrt_float_LUT[i] = b; } } @@ -156,6 +162,54 @@ int16_t IRAM_ATTR scale_sample (int16_t in, uint8_t volume) return (int16_t)(in * float_lut[volume]); } +int16_t IRAM_ATTR scale_sample_sqrt (int16_t in, uint8_t volume) +{ + return (int16_t)(in * sqrt_float_LUT[volume]); +} + +float eq_high = 1; +float eq_low = 0; + +static float temp_low_L; +static float temp_high_L; +static float temp_low_R; +static float temp_high_R; +static float distanceToGo; +static float trebleOnly; + +int16_t IRAM_ATTR apply_EQ(int16_t in, bool left) +{ + if(left) + { + // Treble calculations + distanceToGo = in - temp_low_L; + temp_low_L += distanceToGo * 0.125; // Number controls treble frequency + trebleOnly = in - temp_low_L; + + // Bass calculations + distanceToGo = temp_low_L - temp_high_L; + temp_high_L += distanceToGo * 0.125; // Number controls bass frequency + + return (int16_t)(temp_low_L + trebleOnly * eq_high + temp_high_L * eq_low); + } + else + { + // Treble calculations + distanceToGo = in - temp_low_R; + temp_low_R += distanceToGo * 0.125; // Number controls treble frequency + trebleOnly = in - temp_low_R; + + // Bass calculations + distanceToGo = temp_low_R - temp_high_R; + temp_high_R += distanceToGo * 0.125; // Number controls bass frequency + + return (int16_t)(temp_low_R + trebleOnly * eq_high + temp_high_R * eq_low); + } + // return (int16_t)(temp_low_R + trebleOnly * 1 + temp_high_R * 0); + // The "1" controls treble. 0 = none; 1 = untouched; 2 = +6db + // The "0" controls bass. -1 = none; 0 = untouched; 1 = +6db +} + void stop_wav(uint8_t voice, uint8_t note) { struct wav_player_event_t wav_player_event; @@ -173,6 +227,7 @@ void play_wav(uint8_t voice, uint8_t note, uint8_t velocity) wav_player_event.voice = voice; wav_player_event.velocity = velocity; wav_player_event.note = note; + wav_player_event.channel = 0; xQueueSendToBack(wav_player_queue, &wav_player_event, portMAX_DELAY); } @@ -387,49 +442,45 @@ void wav_player_task(void* pvParameters) size_t remaining = (bufs[i].size - bufs[i].wav_position) / sizeof(int16_t); size_t to_write = remaining < DAC_BUFFER_SIZE_IN_SAMPLES ? remaining : DAC_BUFFER_SIZE_IN_SAMPLES; - - switch(bufs[i].wav_data.response_curve){ - case RESPONSE_ROOT_SQUARE: + + uint8_t channel = bufs[i].wav_player_event.channel; + uint8_t left_vol = channel_pan[channel].left_vol; + uint8_t right_vol = channel_pan[channel].right_vol; + + bool left = false; + for(int s=0; s> DAMPEN_BITS ); + // incriment fade var + if(bufs[i].fade) + { + if(bufs[i].volume > 0) { - for(int s=0; s> (15 + DAMPEN_BITS)); - if(bufs[i].fade) - { - if(bufs[i].volume > 0) - { - bufs[i].volume--; - } - else - { - bufs[i].done = true; - } - } - } + bufs[i].volume--; } - break; - case RESPONSE_FIXED: - case RESPONSE_LINEAR: + else { - for(int s=0; s> DAMPEN_BITS ) ; - if(bufs[i].fade) - { - if(bufs[i].volume > 0) - { - bufs[i].volume--; - } - else - { - bufs[i].done = true; - } - } - } + bufs[i].done = true; } + } } + // incriment that buffers position bufs[i].head_position++; @@ -463,10 +514,16 @@ void wav_player_task(void* pvParameters) } } - // apply the global volume + // apply the global volume and EQ + bool left = false; for(size_t i=0;iWaver UI
+Waver UI
)====="; \ No newline at end of file