Skip to content
Snippets Groups Projects
Commit 34ae9cfe authored by moon2's avatar moon2 :speech_balloon: Committed by q3k
Browse files

UNFLIPPED SPEAKER PHASE (also some cleanups)

parent a4be0596
No related branches found
No related tags found
No related merge requests found
......@@ -12,12 +12,6 @@
#include <string.h>
#include "../../py/mphal.h"
#define DRUMS_TOP 0
#define NUM_SYNTH 10
static trad_osc_t synths[NUM_SYNTH];
static void audio_player_task(void* arg);
#define DMA_BUFFER_SIZE 64
......@@ -52,34 +46,6 @@ static void i2s_init(void){
}
static float FREQ_TABLE[] = {
523.25,
587.33,
659.25 ,
698.46 ,
783.99 ,
880.00 ,
987.77 ,
1046.50,
1174.66,
1318.51,
};
#if 0
static float FREQ_TABLE[] = {
783.99,
415.30,
440.0,
493.88,
523.25,
587.33,
659.25,
698.46,
830.61,
880.00,
};
#endif
typedef struct _audio_source_t{
void * render_data;
float (* render_function)(void *);
......@@ -165,63 +131,14 @@ static void _audio_init(void) {
init_scope(241);
i2s_init();
//ESP_ERROR_CHECK(i2s_channel_enable(tx_chan));
/*
for(int i = 0; i < NUM_SYNTH; i++){
if((i%2) || (!DRUMS_TOP) ){ //bottom leaves
synths[i].decay_steps = 50;
synths[i].attack_steps = 3;
if(i == 2 || i == 8) synths[i].attack_steps = 15;
synths[i].vol = 1.;
synths[i].gate = 0.01;
synths[i].freq = FREQ_TABLE[i]/2;
synths[i].counter = 0;
synths[i].bend = 1;
synths[i].noise_reg = 1;
synths[i].waveform = 1;
synths[i].skip_hold = !(i % 2);
if(DRUMS_TOP) synths[i].waveform = 4;
} else { //top leaves
synths[i].decay_steps = 50;
synths[i].attack_steps = 0;
synths[i].bend = 1;
synths[i].vol = 0.0;
synths[i].skip_hold = 1;
switch(i){
case 0: //kick
synths[i].freq = 1800;
break;
case 2: //snare 1
synths[i].freq = 5000;
break;
case 4: //snare 2
synths[i].freq = 6000;
break;
case 6: //hihat
synths[i].freq = 12000;
break;
case 8: //crash
synths[i].freq = 16000;
synths[i].gate = 0.1;
break;
}
synths[i].counter = 0;
synths[i].waveform = 8;
synths[i].noise_reg = 1;
}
add_audio_source(&(synths[i]), trad_osc);
}
*/
TaskHandle_t handle;
xTaskCreate(&audio_player_task, "Audio player", 20000, NULL, configMAX_PRIORITIES - 1, &handle);
}
#define MIN(a,b) ((a > b) ? b : a)
#define LR_PHASE -1
#define LR_PHASE 1
#define NAT_LOG_DB 0.1151292546497023
static uint16_t _global_vol = 3000;
static void * _extra_synth = NULL;
void set_global_vol_dB(int8_t vol_dB){
if(vol_dB < (BADGE_MIN_VOLUME_DB)){
......@@ -234,30 +151,14 @@ void set_global_vol_dB(int8_t vol_dB){
}
}
void set_extra_synth(void * synth){
_extra_synth = synth;
}
void clear_extra_synth(){
_extra_synth = NULL;
}
static void audio_player_task(void* arg) {
int16_t buffer[DMA_BUFFER_SIZE * 2];
//memset(buffer, 0, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
while(true) {
for(int i = 0; i < (DMA_BUFFER_SIZE * 2); i += 2){
float sample = 0;
/*
for(int j = 0; j<NUM_SYNTH; j++){
sample += trad_osc(&(synths[j]));
}
if(_extra_synth != NULL){
sample += trad_osc((trad_osc_t * )_extra_synth);
}
*/
audio_source_t * audio_source = _audio_sources;
while(audio_source != NULL){
sample += (*(audio_source->render_function))(audio_source->render_data);
......@@ -272,7 +173,6 @@ static void audio_player_task(void* arg) {
}
size_t count = 0;
//i2s_channel_write(tx_chan, buffer, sizeof(buffer), &count, 1000);
i2s_write(I2S_PORT, buffer, sizeof(buffer), &count, 1000);
if (count != sizeof(buffer)) {
printf("i2s_write_bytes: count (%d) != length (%d)\n", count, sizeof(buffer));
......@@ -283,30 +183,8 @@ static void audio_player_task(void* arg) {
void audio_init() { _audio_init(); }
extern const int16_t boot_snd_start[] asm("_binary_boot_snd_start");
extern const int16_t boot_snd_end[] asm("_binary_boot_snd_end");
extern const int16_t pan_s16_start[] asm("_binary_pan_s16_start");
extern const int16_t pan_s16_end[] asm("_binary_pan_s16_end");
void play_bootsound() {
/*
sound_cfg_t sound = {0,};
sound.buffer = boot_snd_start, sound.size = boot_snd_end - boot_snd_start;
//sound.buffer = pan_s16_start, sound.size = pan_s16_end - pan_s16_start;
sound.slot = 10;
xQueueSend(sound_queue, &sound, 0);
*/
}
void synth_set_freq(int i, float freq){
synths[i].freq = freq;
}
void synth_set_vol(int i, float vol){
synths[i].vol = vol;
}
/*
#define NAT_LOG_SEMITONE 0.05776226504666215
void synth_set_bend(int i, float bend){
......@@ -317,7 +195,9 @@ void synth_set_bend(int i, float bend){
synths[i].bend = exp(bend * NAT_LOG_SEMITONE);
}
}
*/
/*
void synth_stop(int i){
if(synths[i].env_phase){
synths[i].env_phase = 3;
......@@ -335,3 +215,4 @@ void synth_start(int i){
float synth_get_env(int i){
return synths[i].env;
}
*/
......@@ -7,18 +7,8 @@
#define BADGE_VOLUME_LIMIT 30000
void audio_init();
void play_bootsound();
void synth_set_freq(int i, float freq);
void synth_set_vol(int i, float vol);
void synth_set_bend(int i, float bend);
void synth_start(int i);
void synth_stop(int i);
void synth_fullstop(int i);
float synth_get_env(int i);
void set_global_vol_dB(int8_t vol_dB);
void set_extra_synth(void * synth);
void clear_extra_synth();
uint16_t count_audio_sources();
uint16_t add_audio_source(void * render_data, void * render_function);
......
......@@ -66,14 +66,14 @@ void espan_handle_captouch(uint16_t pressed_top, uint16_t pressed_bot)
bool changed = false;
for(int i=0; i<10; i++) {
if(active_paddles[i] == false && paddles[i] == true) {
if(!(i == 2 || i == 8)) synth_start(i);
//if(!(i == 2 || i == 8)) synth_start(i);
leds_animate(i);
active_paddles[i] = true;
changed = true;
} else if(active_paddles[i] == true && paddles[i] == false) {
active_paddles[i] = false;
changed = true;
if(!(i == 2 || i == 8)) synth_stop(i);
//if(!(i == 2 || i == 8)) synth_stop(i);
}
}
......@@ -103,7 +103,6 @@ void os_app_main(void)
captouch_init();
mp_hal_stdout_tx_str("task inits done\n\r");
//play_bootsound();
//not sure how slow captouch_get_cross is so duplicating edge detection here;
bool prev_petals[10] = {0};
//pitch bend as movement relative to inital touch pos to make intonation easier
......@@ -121,6 +120,7 @@ void os_app_main(void)
vTaskDelay(3 / portTICK_PERIOD_MS);
continue;
/*
i = (i + 1) % 10;
if(!(i == 2 || i == 8)) continue;
if(VIB){
......@@ -175,6 +175,7 @@ void os_app_main(void)
vTaskDelay(10 / portTICK_PERIOD_MS);
//captouch_print_debug_info();
*/
}
ESP_ERROR_CHECK(i2c_driver_delete(I2C_MASTER_NUM));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment