Skip to content
Open
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
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json

This file was deleted.

25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ compile_commands.json
*.out
cpu/src/resources/bfin_ldr.h
run.sh
freetribe.code-workspace
.vscode
5 changes: 3 additions & 2 deletions cpu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ BIN=$(PREFIX)objcopy

# C compilation options.
NEST_INT ?= 0
OPTIMISE ?= -g3 -Og
# OPTIMISE ?= -g3 -Og
# OPTIMISE ?= -O3
OPTIMISE ?= -Os
CPU ?= arm926ej-s
CFLAGS := -mcpu=$(CPU) $(OPTIMISE) -fdata-sections -ffunction-sections -fanalyzer -fstack-usage -Wstack-usage=128 -Wall
CFLAGS := -mcpu=$(CPU) $(OPTIMISE) -fdata-sections -ffunction-sections -fanalyzer -fstack-usage -Wstack-usage=128 -Wall -Wno-unused

# Assembly compilation options.
ASM_FLAGS := -x assembler-with-cpp
Expand Down
5 changes: 5 additions & 0 deletions cpu/cpu.lds
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MEMORY
{
OC_RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x20000
ARM_RAM (rwx) : ORIGIN = 0xFFFF0000, LENGTH = 0x2000
DDR2_RAM (rw) : ORIGIN = 0xc0000000, LENGTH = 64M /* sk hynix h5ps5162kfr-s5c chip maximum is 64MB */
}

SECTIONS
Expand Down Expand Up @@ -94,4 +95,8 @@ SECTIONS
_stack = .;
} > ARM_RAM


_ddr2_start = ORIGIN(DDR2_RAM);
_ddr2_end = ORIGIN(DDR2_RAM) + LENGTH(DDR2_RAM);

}
18 changes: 18 additions & 0 deletions cpu/src/api/freetribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ under the terms of the GNU Affero General Public License as published by

/*----- Includes -----------------------------------------------------*/

#define TINYPRINTF_DEFINE_TFP_PRINTF 0
#define TINYPRINTF_OVERRIDE_LIBC 0
#include "utils/tinyprintf.h"
#include "freetribe.h"
#include <stdint.h>
#include <stdarg.h>

/*----- Macros -------------------------------------------------------*/

Expand Down Expand Up @@ -133,6 +137,20 @@ void ft_register_print_callback(void (*callback)(char *)) {
*/
void ft_print(char *text) { svc_midi_send_string(text); }

/**
* @brief Literally printf girl
*/
void ft_printf(const char *format, ...)
{
va_list ap;
static char str[256];

va_start(ap, format);
tfp_vsprintf(str, format, ap);
svc_midi_send_string(str);
va_end(ap);
}

// Panel API
//
/**
Expand Down
1 change: 1 addition & 0 deletions cpu/src/api/freetribe.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ int8_t ft_fill_frame(uint16_t x_start, uint16_t y_start, uint16_t x_end,

void ft_register_print_callback(void (*callback)(char *));
void ft_print(char *text);
void ft_printf(const char *format, ...);

void ft_register_midi_callback(event_type event,
t_midi_event_callback callback);
Expand Down
356 changes: 356 additions & 0 deletions cpu/src/apps/system23/lookup_tables.h

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions cpu/src/apps/system23/lut.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#include "lut.h"
#include "param_scale.h"

int32_t g_cutoff_lut[128];
int32_t g_resonance_lut[256];

void lut_init() {
// float_to_fract32(1.0 - (value / 255.0f))

for (int i = 0; i < 128; i++) {
g_cutoff_lut[i] = float_to_fix16(cv_to_filter_freq_oversample(note_to_cv(i)));
}

for (int i = 0; i <= 255; i++) {
g_resonance_lut[i] = 0x7fffffff - (i * (1 << 23));
}

}
10 changes: 10 additions & 0 deletions cpu/src/apps/system23/lut.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LUT_H
#define LUT_H
#include <stdint.h>

extern int32_t g_cutoff_lut[128];
extern int32_t g_resonance_lut[256];

void lut_init();

#endif
172 changes: 172 additions & 0 deletions cpu/src/apps/system23/param_scale.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*----------------------------------------------------------------------

This file is part of Freetribe

https://github.com/bangcorrupt/freetribe

License

GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007

AGPL-3.0-or-later

Freetribe is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Freetribe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

Copyright bangcorrupt 2023

----------------------------------------------------------------------*/

/**
* @file param_scale.h
*
* @brief Public API for parameter scaling.
*/

#ifndef PARAM_SCALE_H
#define PARAM_SCALE_H

#ifdef __cplusplus
extern "C" {
#endif

/*----- Includes -----------------------------------------------------*/

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

#include "lookup_tables.h"

/*----- Macros -------------------------------------------------------*/

// Maximum and minimum float values representable as fract32.
#define FRACT32_MAX_FLOAT 0x0.FFFFFFp0F
#define FRACT32_MIN_FLOAT -1.0F

#define FIX16_MAX 0x7FFFFFFF
#define FIX16_MIN 0x80000000
#define FIX16_ONE 0x00010000

/// TODO: These could probably be optimised.
/// Aleph_Phasor takes normalised frequency in Hz, 16.16 format.
/// Aleph_FilterSVF appears to want that converted to radians.
/// Our CPU side module_set_param function expects all values
/// as floating point between -1.0 and 1.0.

// Normalise frequency, 0x7fffffff / (48000 << 16)
#define OSC_FREQ_CONST 0.6826667

// Convert to radians.
#define FILTER_FREQ_CONST (OSC_FREQ_CONST * 2 * M_PI)

// Half frequency as 2 times oversampled.
#define FILTER_FREQ_OVERSAMPLE_CONST (OSC_FREQ_CONST * M_PI)

#define CONCERT_PITCH_HZ 440.0
#define CONCERT_PITCH_MIDI 69.0

#define CV_CENTRE_FREQ 27.5

/*----- Typedefs -----------------------------------------------------*/

/*----- Extern variable declarations ---------------------------------*/

/*----- Static variable definitions ----------------------------------*/

/*----- Extern function prototypes -----------------------------------*/

/*----- Extern function implementations ------------------------------*/

static inline float clamp_value(float value) {

return fmaxf(fminf(value, FRACT32_MAX_FLOAT), FRACT32_MIN_FLOAT);
}

static inline int32_t float_to_fract32(float value) {

int32_t result;

if (value == 0) {
result = 0;

} else {
result = (int32_t)roundf(scalbnf(clamp_value(value), 31));
}

return result;
}

static inline int32_t float_to_fix16(float value) {

int32_t result;

if (value == 0) {
result = 0;

} else {
result = (int32_t)(value * FIX16_ONE);
}

return result;
}

static inline float note_to_freq(float note) {

return CONCERT_PITCH_HZ * powf(2.0, ((note - CONCERT_PITCH_MIDI) / 12.0));
}

static inline float freq_to_cv(float freq) {

// 0.1 per octave, 0 == 27.5 Hz (A0).
return (logf(freq / CV_CENTRE_FREQ) / logf(2.0)) / 10;
}

static inline float note_to_cv(float note) {

return freq_to_cv(note_to_freq(note));
}

static inline float cv_to_freq(float cv) {

return powf(2.0, cv * 10) * CV_CENTRE_FREQ;
}

static float cv_to_osc_freq(float cv) {

return cv_to_freq(cv) * OSC_FREQ_CONST;
}

static float cv_to_filter_freq(float cv) {

return cv_to_freq(cv) * FILTER_FREQ_CONST;
}

static float cv_to_filter_freq_oversample(float cv) {

return cv_to_freq(cv) * FILTER_FREQ_OVERSAMPLE_CONST;
}



static inline int32_t note_to_fract32(uint8_t note) {
return freq_12tet_lut[note];
}


#ifdef __cplusplus
}
#endif
#endif

/*----- End of file --------------------------------------------------*/
8 changes: 8 additions & 0 deletions cpu/src/apps/system23/sequencer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef SEQUENCER_H
#define SEQUENCER_H

#define GATE_4TH ((SAMPLERATE * 60) / (BPM * 4))
#define GATE_8TH ((SAMPLERATE * 60) / (BPM * 8))
#define GATE_16TH ((SAMPLERATE * 60) / (BPM * 16))

#endif
Loading