parent
a0bc9cbce6
commit
210dc81b25
|
|
@ -1,2 +1,2 @@
|
||||||
idf_component_register(SRCS "esp32_eurorack_generic.c"
|
idf_component_register(SRCS "esp32_eurorack_generic.c" "wavetable.c"
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
#include "freertos/portmacro.h"
|
#include "freertos/portmacro.h"
|
||||||
#include "hal/i2c_types.h"
|
#include "hal/i2c_types.h"
|
||||||
|
|
||||||
|
#include "wavetable.h"
|
||||||
|
|
||||||
/* DAC Peripheral Config */
|
/* DAC Peripheral Config */
|
||||||
#define DAC_SCL_PIN 12
|
#define DAC_SCL_PIN 12
|
||||||
#define DAC_SDA_PIN 13
|
#define DAC_SDA_PIN 13
|
||||||
|
|
@ -117,6 +119,9 @@ void app_main(void)
|
||||||
ESP_LOGI(TAG, "Sucessfully initialized DAC");
|
ESP_LOGI(TAG, "Sucessfully initialized DAC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Generate wave tables */
|
||||||
|
gen_wavetables();
|
||||||
|
|
||||||
/* Loop to test DAC output */
|
/* Loop to test DAC output */
|
||||||
while (1) {
|
while (1) {
|
||||||
dac_out_test();
|
dac_out_test();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "wavetable.h"
|
||||||
|
|
||||||
|
#define SAMPLE_RATE 22000 /* 22kHz */
|
||||||
|
#define FREQ 440
|
||||||
|
#define TIME 1
|
||||||
|
|
||||||
|
float_t *sin_tbl;
|
||||||
|
|
||||||
|
static const char *TAG = "wavetable";
|
||||||
|
|
||||||
|
static void gen_sin_table(void)
|
||||||
|
{
|
||||||
|
/* Allocate memory */
|
||||||
|
uint16_t table_length = 1024; /* TODO make this accurate to sample rate and frequency */
|
||||||
|
sin_tbl = (float *)malloc(sizeof(float) * table_length);
|
||||||
|
|
||||||
|
/* Loop through values and store in table */
|
||||||
|
for (uint16_t i = 0; i < table_length; i++) {
|
||||||
|
sin_tbl[i] = sin((2 * M_PI * i) / table_length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gen_wavetables(void)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Generating sine wavetable");
|
||||||
|
gen_sin_table();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef WAVETABLE_H_ /* Guard */
|
||||||
|
#define WAVETABLE_H_
|
||||||
|
|
||||||
|
/* Generates all wavetables */
|
||||||
|
void gen_wavetables(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue