Skip to content

Commit

Permalink
devsync f2e9e49
Browse files Browse the repository at this point in the history
  • Loading branch information
eh2k committed Jun 15, 2024
1 parent 9b81a8a commit a75d8e1
Show file tree
Hide file tree
Showing 32 changed files with 134 additions and 86 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
<summary><b>ChangeLog</b></summary>

````
== 2024-06-15
* Enhancement:
* T1 Clock - resets to begin after 200milis silence
* internal crc32 checks for debugging
* midi response optimization
* squares-and-circles api
* serial
* fs
* Bugfixes
* out of memory handling - prevent crashing
== 2024-04-19
* Enhancement: Engine Load "Options" (Reset IO + Copy From) #74
* SD Format - preserves stored patches
Expand Down Expand Up @@ -147,7 +157,7 @@ E.g you can chain the mono audio signal from an oscillator machine to the neighb

>[Long press [LEFT]] enters the machine-selection-page.<br/>
>[Short press [R-ENCODER]] loads the selected engine.<br/>
>[Long press [R-ENCODER]] loads the selected engine extended mode.<br/>
>[Long press [R-ENCODER]] loads the selected engine - extended mode.<br/>
* Load & reset I/O settings
* Load & keep IO settings <img align="right" src="doc/engine_load_resetio.png" width=196px />
* Copy #1-4 (parameter values + modulations + I/O settings)
Expand Down
Binary file modified app/DRUMS/Djembe.bin
Binary file not shown.
Binary file modified app/DRUMS/TR707-HiHat.bin
Binary file not shown.
Binary file modified app/DRUMS/TR707.bin
Binary file not shown.
Binary file modified app/DRUMS/TR909-HiHat.bin
Binary file not shown.
Binary file modified app/DRUMS/TR909-Ride.bin
Binary file not shown.
Binary file modified app/FX/Delay.bin
Binary file not shown.
Binary file modified app/FX/JU60_chorus.bin
Binary file not shown.
Binary file modified app/FX/Rev-Dattorro.bin
Binary file not shown.
Binary file modified app/FX/Reverb.bin
Binary file not shown.
Binary file modified app/FX/ReverbSC.bin
Binary file not shown.
Binary file modified app/GND/FFT.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions app/GND/FFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ float fft_read(int s, int e)
float level2[64];
float level[64];

void draw_spectrum(int yy, int hh)
static void draw_spectrum(int yy, int hh)
{
float logN2 = logf(N / 2);

Expand Down Expand Up @@ -176,7 +176,7 @@ void draw_spectrum(int yy, int hh)
// };

for (uint32_t i = 0; i < (N / 2); i++)
magnitudes[i] = 0;
magnitudes[i] = 0;
count = 0;
}

Expand Down
Binary file modified app/GND/Scope.bin
Binary file not shown.
Binary file modified app/MIDI/Clock.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions app/MIDI/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ uint8_t clk_change(uint8_t clk)

void engine::process()
{
machine::clk_bpm(bpm * 100);
bpm = machine::clk_bpm() / 100;
uint8_t clk = clk_change(engine::clock());

if (clk)
Expand All @@ -84,7 +84,7 @@ void engine::process()

int16_t a = count_down-- > 0 ? (5 * PITCH_PER_OCTAVE) : 0;
std::fill_n(engine::outputBuffer_i16<0>(), FRAME_BUFFER_SIZE, a);
std::fill_n(engine::outputBuffer_i16<1>(), FRAME_BUFFER_SIZE, a);
std::fill_n(engine::outputBuffer_i16<1>(), FRAME_BUFFER_SIZE, clk == CLOCK_RESET ? (5 * PITCH_PER_OCTAVE) : 0);
}

void engine::draw()
Expand Down
Binary file modified app/MIDI/Monitor.bin
Binary file not shown.
Binary file modified app/MIDI/VAx6.bin
Binary file not shown.
Binary file modified app/NOISE/808_squares.bin
Binary file not shown.
Binary file modified app/NOISE/NES.bin
Binary file not shown.
Binary file modified app/NOISE/WhitePink.bin
Binary file not shown.
Binary file modified app/SPEECH/LPC.bin
Binary file not shown.
Binary file modified app/SPEECH/SAM.bin
Binary file not shown.
Binary file modified app/SYNTH/Open303.bin
Binary file not shown.
Binary file modified app/SYNTH/Resonator.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ touch -d "$(date -R -r $X.cpp)" $X.bin

cat $X.log | arm-none-eabi-c++filt -t > ${X}2.log

arm-none-eabi-objdump -Dztr --source $X.elf | arm-none-eabi-c++filt -t > $X.elf.txt
arm-none-eabi-objdump -g -Dztr --source $X.elf | arm-none-eabi-c++filt -t > $X.elf.txt
#arm-none-eabi-nm -l -t d -S -C --size-sort --synthetic --special-syms --with-symbol-versions --reverse-sort ./$X.elf > $X.log
which elf-size-analyze >/dev/null && elf-size-analyze -t arm-none-eabi- ./$X.elf -F -R --no-color >> $X.log
md5sum $X.bin | tee -a $X.log
Expand Down
104 changes: 67 additions & 37 deletions app/squares-and-circles-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <stdio.h>
#include <string.h>

#ifndef MACHINE_INTERNAL

#if 0
#define WASM_EXPORT extern "C" __attribute__((used)) __attribute__((visibility("default")))
#define WASM_EXPORT_AS(NAME) WASM_EXPORT __attribute__((export_name(NAME)))
Expand Down Expand Up @@ -83,43 +85,9 @@

#ifndef EMSCRIPTEN

#include <stdlib.h>
#include <new>

void *operator new(std::size_t sz)
{
void *out = malloc(sz);
return out;
}

void *operator new[](std::size_t sz)
{
void *out = malloc(sz);
return out;
}

void operator delete(void *ptr) noexcept
{
free(ptr);
}

void operator delete(void *ptr, std::size_t size) noexcept
{
free(ptr);
}

void operator delete[](void *ptr) noexcept
{
free(ptr);
}

void operator delete[](void *ptr, std::size_t size) noexcept
{
free(ptr);
}

extern "C" uint32_t micros();
extern "C" uint32_t millis();
extern "C" uint32_t crc32(uint32_t crc, const void *buf, size_t size);

#endif
#endif
Expand Down Expand Up @@ -199,6 +167,8 @@ extern "C"

namespace engine
{
constexpr uint8_t CLOCK_RESET = 97;

inline uint32_t t() { return *__t; }
inline uint8_t clock() { return *__clock; }
inline uint8_t trig() { return *__trig; }
Expand Down Expand Up @@ -366,7 +336,6 @@ using namespace ui;
using namespace UI;
#endif

#ifndef __no_gfx
namespace gfx
{
extern "C" void drawCircle(int x, int y, int r);
Expand All @@ -390,4 +359,65 @@ namespace gfx
return __display_buffer_u8_p;
}
}
#endif

namespace machine
{
extern "C"
{
extern void serial_write(void const *buffer, uint32_t bufsiz);
extern uint32_t serial_read(void *buffer, uint32_t length);
extern uint32_t serial_available();

extern void get_device_id(uint8_t *mac);

extern float cpu_load_percent();

extern uint8_t *engine_malloc(uint32_t size);
extern void engine_start(uint32_t args);
extern void engine_stop(uint32_t result);
}
}

#endif // MACHINE_INTERNAL

// fatfs api -- ff.h

enum FRESULT : int
{
FR_OK = 0,
FR_DISK_ERR = 1,
FR_NO_FILE = 4,
};

typedef struct
{
void *impl;
} FIL;

typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
typedef unsigned char BYTE; /* char must be 8-bit */
typedef uint16_t WORD; /* 16-bit unsigned integer */
typedef uint32_t DWORD; /* 32-bit unsigned integer */
typedef uint64_t QWORD; /* 64-bit unsigned integer */
typedef WORD WCHAR; /* UTF-16 character type */
typedef DWORD FSIZE_t;

#define FA_READ 0x01
#define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA_OPEN_APPEND 0x30

extern "C"
{
FRESULT f_open(FIL *f, const char *name, uint32_t mode);
FRESULT f_read(FIL *f, void *p, UINT size, UINT *bytes_read);
FSIZE_t f_tell(FIL *fp);
FSIZE_t f_size(FIL *fp);
FRESULT f_truncate(FIL *fp);
FRESULT f_lseek(FIL *fp, FSIZE_t ofs);
FRESULT f_close(FIL *f);
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw);
}
45 changes: 30 additions & 15 deletions src/build.py → build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ def make_engines_hex(apps_json, ih = intelhex.IntelHex(), offset= 0):
if not os.path.exists(bin_file):
continue
bin_size=os.path.getsize(bin_file)
print("0x%x" % offset, bin_file, bin_size, udynlink_size(bin_file) % 4)

ih.loadbin(bin_file,offset=offset)
bin_offset = offset
offset += bin_size
with open(bin_file, "rb") as f:
crc32sum = zlib.crc32(f.read())
ih.puts(offset, crc32sum.to_bytes(4, 'little') )
offset += 4

print("0x%x" % bin_offset, bin_file, bin_size, udynlink_size(bin_file) % 4, "CRC32: %x" % crc32sum)

offset += 4 - (offset % 4)

ih.puts(offset, 0xffff.to_bytes(4, 'little') )
return ih

Expand All @@ -55,18 +64,21 @@ def make_engines_hex(apps_json, ih = intelhex.IntelHex(), offset= 0):
midi_out = None
midi_in = None

try:
for mo in mido.get_output_names():
if "S&C" in mo:
midi_out = mido.open_output(mo)
break
def midi_init():
global midi_in, midi_out
try:
for mo in mido.get_output_names():
if "S&C" in mo or "Squares&Circles" in mo or "Teensy MIDI" in mo:
midi_out = mido.open_output(mo)
break

for mi in mido.get_input_names():
if "S&C" in mi:
midi_in = mido.open_input(mi)
break
except:
pass
for mi in mido.get_input_names():
print(mi)
if "S&C" in mi or "Squares&Circles" in mi or "Teensy MIDI" in mi:
midi_in = mido.open_input(mi)
break
except:
pass


def chunk_bytes(bytes_object, chunk_size):
Expand Down Expand Up @@ -100,7 +112,7 @@ def sendFLASHDATA(name, data0):
ch = 0 + ((data[i + 1] & 0xF0) >> 4)
rawValue = [0b11100000 | ch, int16 & 0x7f, int16 >> 7 & 0x7f]
midi_out.send(mido.Message.from_bytes(rawValue))
time.sleep(1/10000)
time.sleep(2/10000)
i += 2

flush(midi_in)
Expand All @@ -125,12 +137,15 @@ def post_program_action(source, target, env):
print(program_path, len(ahx))

def upload_hex(source, target, env):
if midi_out == None:
exit(-1)

midi_init()

print(midi_in)
print(midi_out)

if midi_out == None:
exit(-1)

program_path = env.GetBuildPath("$PROJECT_DIR/.pio/build/$PIOENV/engines.hex")
ahx = intelhex.IntelHex(program_path)

Expand Down
26 changes: 12 additions & 14 deletions lib/bbd/bbd_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

void BBD_Line::setup(unsigned ns, const BBD_Filter_Coef &fin, const BBD_Filter_Coef &fout)
{
mem_.reserve(8192);

fin_ = &fin;
fout_ = &fout;

Expand All @@ -17,12 +15,6 @@ void BBD_Line::setup(unsigned ns, const BBD_Filter_Coef &fin, const BBD_Filter_C
Gin_.reset(new cdouble[Min]);
Gout_.reset(new cdouble[Mout]);

set_delay_size(ns);
clear();
}

void BBD_Line::set_delay_size(unsigned ns)
{
mem_.clear();
mem_.resize(ns);
imem_ = 0;
Expand Down Expand Up @@ -59,29 +51,34 @@ void BBD_Line::process(unsigned n, const float *input, float *output, const floa
cdouble *Gin = Gin_.get(), *Gout = Gout_.get();
const cdouble *Pin = fin.P.get(), *Pout = fout.P.get();

for (unsigned i = 0; i < n; ++i) {
for (unsigned i = 0; i < n; ++i)
{
double fclk = clock[i];

for (unsigned m = 0; m < Mout; ++m)
Xout[m] = 0;

if (fclk > 0) {
if (fclk > 0)
{
auto pclk_old = pclk;
pclk += fclk;
unsigned tick_count = (unsigned)pclk;
pclk -= tick_count;
for (unsigned tick = 0; tick < tick_count; ++tick) {
for (unsigned tick = 0; tick < tick_count; ++tick)
{
auto d = (1 - pclk_old + tick) * (1 / fclk);
d -= (unsigned)d;
if ((ptick & 1) == 0) {
if ((ptick & 1) == 0)
{
fin.interpolate_G(d, Gin);
cdouble s = 0;
for (unsigned m = 0; m < Min; ++m)
s += Gin[m] * Xin[m];
mem[imem] = s.real();
imem = ((imem + 1) < ns) ? (imem + 1) : 0;
}
else {
else
{
fout.interpolate_G(d, Gout);
auto ybbd = mem[imem];
auto delta = ybbd - ybbd_old;
Expand All @@ -97,7 +94,8 @@ void BBD_Line::process(unsigned n, const float *input, float *output, const floa
Xin[m] = Pin[m] * Xin[m] + cdouble(input[i]);

cdouble y = fout.H * ybbd_old;
for (unsigned m = 0; m < Mout; ++m) {
for (unsigned m = 0; m < Mout; ++m)
{
cdouble xout = Pout[m] * Xout_mem[m] + Xout[m];
Xout_mem[m] = xout;
y += xout;
Expand Down
11 changes: 4 additions & 7 deletions lib/bbd/bbd_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

class BBD_Line {
public:

BBD_Line():mem_(0)
{}

/**
* Initialize a delay line with the specified parameters. (non-RT)
* @param fs audio sampling rate
Expand All @@ -16,13 +20,6 @@ class BBD_Line {
*/
void setup(unsigned ns, const BBD_Filter_Coef &fin, const BBD_Filter_Coef &fout);

/**
* Change the number of stages. (RT?)
* @note It guarantees not to reallocate the buffer for \f$ns \leq 8192\f$.
* @param ns number of stages / length of the virtual capacitor array
*/
void set_delay_size(unsigned ns);

/**
* Reinitialize all the internal state to zero. (RT)
*/
Expand Down
Loading

0 comments on commit a75d8e1

Please sign in to comment.