8000 LilTracker synth refactoring by and3rson · Pull Request #105 · and3rson/lilka · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

LilTracker synth refactoring #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const menu_icon_t* get_file_icon(const String& filename) {
return &lua_img;
} else if (lowerCasedFileName.endsWith(".js")) {
return &js_img;
} else if (lowerCasedFileName.endsWith(".mod")) {
} else if (lowerCasedFileName.endsWith(".mod") || lowerCasedFileName.endsWith(".lt")) {
return &music;
} else {
return &normalfile_img;
Expand All @@ -168,7 +168,7 @@ const uint16_t get_file_color(const String& filename) {
return lilka::colors::Maya_blue;
} else if (lowerCasedFileName.endsWith(".js")) {
return lilka::colors::Butterscotch;
} else if (lowerCasedFileName.endsWith(".mod")) {
} else if (lowerCasedFileName.endsWith(".mod") || lowerCasedFileName.endsWith(".lt")) {
return lilka::colors::Pink_lace;
} else {
return lilka::colors::Light_gray;
Expand Down
57 changes: 57 additions & 0 deletions firmware/keira/src/apps/liltracker/i2s_sink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <lilka.h>
#include "synth.h"

#include "i2s_sink.h"

I2SSink::I2SSink() {
constexpr uint8_t pinCount = 3;
uint8_t pins[pinCount] = {LILKA_I2S_BCLK, LILKA_I2S_LRCK, LILKA_I2S_DOUT};
uint8_t funcs[pinCount] = {I2S0O_BCK_OUT_IDX, I2S0O_WS_OUT_IDX, I2S0O_SD_OUT_IDX};
for (int i = 0; i < pinCount; i++) {
gpio_pad_select_gpio(pins[i]);
gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_OUTPUT);
gpio_matrix_out(pins[i], funcs[i], false, false);
}

esp_i2s::i2s_config_t cfg = {
.mode = (esp_i2s::i2s_mode_t)(esp_i2s::I2S_MODE_MASTER | esp_i2s::I2S_MODE_TX),
.sample_rate = SYNTH_SAMPLE_RATE,
.bits_per_sample = esp_i2s::I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = esp_i2s::I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format =
(esp_i2s::i2s_comm_format_t)(esp_i2s::I2S_COMM_FORMAT_STAND_I2S | esp_i2s::I2S_COMM_FORMAT_STAND_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 4,
.dma_buf_len = SYNTH_BUFFER_SIZE,
.use_apll = false,
.tx_desc_auto_clear = true,
};
if (esp_i2s::i2s_driver_install(esp_i2s::I2S_NUM_0, &cfg, 0, NULL) != ESP_OK) {
lilka::serial_err("Failed to install I2S driver");
return;
}
if (esp_i2s::i2s_zero_dma_buffer(esp_i2s::I2S_NUM_0) != ESP_OK) {
lilka::serial_err("Failed to zero I2S DMA buffer");
return;
}
}

I2SSink::~I2SSink() {
// Deinit I2S (free DMA buffers & uninstall driver)
// TODO: Seems like this does not free the DMA buffers and causes a memory leak!
if (esp_i2s::i2s_driver_uninstall(esp_i2s::I2S_NUM_0) != ESP_OK) {
lilka::serial_err("Failed to uninstall I2S driver");
}
}

void I2SSink::start() {
}

size_t I2SSink::write(const int16_t* data, size_t size) {
size_t bytesWritten = 0;
esp_i2s::i2s_write(esp_i2s::I2S_NUM_0, data, size * sizeof(int16_t), &bytesWritten, portMAX_DELAY);
return bytesWritten / sizeof(int16_t);
}

void I2SSink::stop() {
}
10 changes: 10 additions & 0 deletions firmware/keira/src/apps/liltracker/i2s_sink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "sink.h"

class I2SSink : public Sink {
public:
I2SSink();
~I2SSink();
void start() override;
size_t write(const int16_t* data, size_t size) override;
void stop() override;
};
372 changes: 201 additions & 171 deletions firmware/keira/src/apps/liltracker/liltracker.cpp

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions firmware/keira/src/apps/liltracker/liltracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ class LilTrackerApp : public App {
explicit LilTrackerApp(String path);

private:
Mixer mixer;
Sequencer sequencer;
void run() override;
int drawElement(
const char* text, int16_t x, int16_t y, lilka::Alignment hAlign, lilka::Alignment vAlign, bool editing,
bool focused, uint16_t color
);
void startPreview(Track* track, page_t* page, int8_t requestedChannelIndex, uint16_t requestedEventIndex);
// void startPreview(Track* track, page_t* page, int8_t requestedChannelIndex, uint16_t requestedEventIndex);
void alert(String title, String message);
bool confirm(String title, String message);
String filePicker(bool isSave);
String filePicker(String ext, bool isSave);
void loadTrack(Track* track, String path);
void saveTrack(Track* track, String path);

Expand Down
Loading
Loading
0