Skip to content

Commit

Permalink
keira: liltracker: pack structs, cleanup code, fix UI fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Apr 17, 2024
1 parent c034f66 commit d479626
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 179 deletions.
2 changes: 2 additions & 0 deletions firmware/keira/src/apps/liltracker/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
#define DEFAULT_BPM 400
#define CHANNEL_SIZE 32
#define MAX_VOLUME 128

#define PACKED __attribute__((packed))
4 changes: 3 additions & 1 deletion firmware/keira/src/apps/liltracker/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <stdint.h>

#include "config.h"

typedef enum : uint8_t {
EFFECT_TYPE_NONE,
EFFECT_TYPE_ARPEGGIO, // NES: 00xy
Expand Down Expand Up @@ -30,7 +32,7 @@ const char effect_signs[EFFECT_TYPE_COUNT] = {
typedef struct {
effect_type_t type;
uint8_t param;
} effect_t;
} PACKED effect_t;

typedef void (*effect_fn_t)(
const float time, const float relTime, float* frequency, float* amplitude, float* phase, uint8_t param
Expand Down
7 changes: 3 additions & 4 deletions firmware/keira/src/apps/liltracker/liltracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void LilTrackerApp::run() {

int visualizerMode = VISUALIZER_MODE_PER_CHANNEL;

event_t copiedEvent = {N_C0, WAVEFORM_CONT, MAX_VOLUME, EVENT_TYPE_CONT, {EFFECT_TYPE_NONE, 0}};
event_t copiedEvent = {NOTE_ZERO, WAVEFORM_CONT, MAX_VOLUME, EVENT_TYPE_CONT, {EFFECT_TYPE_NONE, 0}};

char str[64];

Expand Down Expand Up @@ -381,7 +381,6 @@ void LilTrackerApp::run() {
int8_t fontShiftY = 0;
if (event.waveform == WAVEFORM_CONT) {
sprintf(str, ".");
canvas->setFont(FONT);
} else {
sprintf(str, "%d", event.waveform - 1);
canvas->setFont(FONT_ICONS);
Expand All @@ -398,7 +397,7 @@ void LilTrackerApp::run() {
eventFocused && currentSegment == SEGMENT_WAVEFORM,
event.waveform == WAVEFORM_CONT ? lilka::colors::Battleship_gray : lilka::colors::Cyan
);
canvas->setFont(FONT);
canvas->setFont(SCORE_FONT);
xOffset += 9;
// Volume
if (event.volume == 0) {
Expand Down Expand Up @@ -610,7 +609,7 @@ void LilTrackerApp::run() {
}
}
if (!found) {
event.note = N_C0;
event.note = NOTE_ZERO;
}
}
if (state.up.justPressed) {
Expand Down
171 changes: 5 additions & 166 deletions firmware/keira/src/apps/liltracker/note.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#pragma once

// #include <math.h>
#include <stdint.h>

#include "config.h"

typedef struct noteinfo_t {
uint8_t index; // [0;11]
uint8_t octave;
uint8_t octave; // [0;9]
char* toStr();
void add(int16_t semitoneCount);
void fromFrequency(float frequency);
float toFrequency();
} noteinfo_t;

// inline float modulate_frequency(int16_t frequency, int16_t semitoneCount) {
// return frequency * powf(2.0f, semitoneCount / 12.0f);
// }
} PACKED noteinfo_t;

// Lookup table for powers of 2 in range [-10;10] with a step of 1/12
extern float pow2table[12 * 10 * 2 + 1];
Expand All @@ -27,165 +24,7 @@ inline float modulate_frequency(float frequency, float semitoneCount) {
index = 12 * 10 * 2;
}
return frequency * pow2table[index];
// int index = semitoneCount + 12;
// if (index < 0) {
// index = 0;
// } else if (index > 24) {
// index = 24;
// }
//
// return frequency * pow2table[index][0] / pow2table[index][1];
}

#define N_C0 \
#define NOTE_ZERO \
{ 0, 0 }

#define N_C1 \
{ 0, 1 }
#define N_CS1 \
{ 1, 1 }
#define N_D1 \
{ 2, 1 }
#define N_DS1 \
{ 3, 1 }
#define N_E1 \
{ 4, 1 }
#define N_F1 \
{ 5, 1 }
#define N_FS1 \
{ 6, 1 }
#define N_G1 \
{ 7, 1 }
#define N_GS1 \
{ 8, 1 }
#define N_A1 \
{ 9, 1 }
#define N_AS1 \
{ 10, 1 }
#define N_B1 \
{ 11, 1 }

#define N_C2 \
{ 0, 2 }
#define N_CS2 \
{ 1, 2 }
#define N_D2 \
{ 2, 2 }
#define N_DS2 \
{ 3, 2 }
#define N_E2 \
{ 4, 2 }
#define N_F2 \
{ 5, 2 }
#define N_FS2 \
{ 6, 2 }
#define N_G2 \
{ 7, 2 }
#define N_GS2 \
{ 8, 2 }
#define N_A2 \
{ 9, 2 }
#define N_AS2 \
{ 10, 2 }
#define N_B2 \
{ 11, 2 }

#define N_C3 \
{ 0, 3 }
#define N_CS3 \
{ 1, 3 }
#define N_D3 \
{ 2, 3 }
#define N_DS3 \
{ 3, 3 }
#define N_E3 \
{ 4, 3 }
#define N_F3 \
{ 5, 3 }
#define N_FS3 \
{ 6, 3 }
#define N_G3 \
{ 7, 3 }
#define N_GS3 \
{ 8, 3 }
#define N_A3 \
{ 9, 3 }
#define N_AS3 \
{ 10, 3 }
#define N_B3 \
{ 11, 3 }

#define N_C4 \
{ 0, 4 }
#define N_CS4 \
{ 1, 4 }
#define N_D4 \
{ 2, 4 }
#define N_DS4 \
{ 3, 4 }
#define N_E4 \
{ 4, 4 }
#define N_F4 \
{ 5, 4 }
#define N_FS4 \
{ 6, 4 }
#define N_G4 \
{ 7, 4 }
#define N_GS4 \
{ 8, 4 }
#define N_A4 \
{ 9, 4 }
#define N_AS4 \
{ 10, 4 }
#define N_B4 \
{ 11, 4 }

#define N_C5 \
{ 0, 5 }
#define N_CS5 \
{ 1, 5 }
#define N_D5 \
{ 2, 5 }
#define N_DS5 \
{ 3, 5 }
#define N_E5 \
{ 4, 5 }
#define N_F5 \
{ 5, 5 }
#define N_FS5 \
{ 6, 5 }
#define N_G5 \
{ 7, 5 }
#define N_GS5 \
{ 8, 5 }
#define N_A5 \
{ 9, 5 }
#define N_AS5 \
{ 10, 5 }
#define N_B5 \
{ 11, 5 }

#define N_C6 \
{ 0, 6 }
#define N_CS6 \
{ 1, 6 }
#define N_D6 \
{ 2, 6 }
#define N_DS6 \
{ 3, 6 }
#define N_E6 \
{ 4, 6 }
#define N_F6 \
{ 5, 6 }
#define N_FS6 \
{ 6, 6 }
#define N_G6 \
{ 7, 6 }
#define N_GS6 \
{ 8, 6 }
#define N_A6 \
{ 9, 6 }
#define N_AS6 \
{ 10, 6 }
#define N_B6 \
{ 11, 6 }
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/liltracker/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pattern::Pattern() : xMutex(xSemaphoreCreateMutex()) {
channels[channelIndex].volume = 1.0f;
for (int16_t eventIndex = 0; eventIndex < CHANNEL_SIZE; eventIndex++) {
event_t event = {
N_C0,
NOTE_ZERO,
eventIndex == 0 ? defaultWaveforms[channelIndex] : WAVEFORM_CONT,
MAX_VOLUME,
EVENT_TYPE_CONT,
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/liltracker/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ typedef struct {
uint8_t volume;
event_type_t type;
effect_t effect;
} event_t;
} PACKED event_t;

typedef struct {
uint8_t volume;
event_t events[CHANNEL_SIZE];
} channel_t;
} PACKED channel_t;

class Pattern {
public:
Expand Down
1 change: 0 additions & 1 deletion firmware/keira/src/apps/liltracker/synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ typedef struct {
// some effects are cancelled by others, some are reset by OFF, etc... /AD
effect_t effect;
float effectStartTime;
// float time; // TODO
} channel_state_t;

class Synth {
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/liltracker/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Each page tells which patterns to play.
typedef struct page_t {
int16_t patternIndices[CHANNEL_COUNT] = {0, 0, 0};
} page_t;
} PACKED page_t;

// Track is the top-level container for a song.
// It contains patterns and pages.
Expand Down
7 changes: 4 additions & 3 deletions firmware/keira/src/apps/liltracker/wav_sink.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <lilka.h>

#include "sink.h"
#include "config.h"

typedef struct {
char chunkID[4]; // "RIFF"
unsigned int chunkSize; // size of the entire file minus 8 bytes
char format[4]; // "WAVE"
} riff_header_t;
} PACKED riff_header_t;

typedef struct {
char subchunk1ID[4]; // "fmt "
Expand All @@ -17,12 +18,12 @@ typedef struct {
unsigned int byteRate; // = SampleRate * NumChannels * BitsPerSample/8
unsigned short blockAlign; // = NumChannels * BitsPerSample/8
unsigned short bitsPerSample; // 16 for PCM
} fmt_subchunk_t;
} PACKED fmt_subchunk_t;

typedef struct {
char subchunk2ID[4]; // "data"
unsigned int subchunk2Size; // num samples * num channels * bits per sample/8
} data_subchunk_t;
} PACKED data_subchunk_t;

class WAVSink : public Sink {
public:
Expand Down

0 comments on commit d479626

Please sign in to comment.