synth-datagen

A tool that generates C data headers for synthesizer waveforms and DSP algorithms.

Overview

synth-datagen is a command-line tool written in Go that generates precomputed C header files for use in synthesizer firmware. It reads a YAML configuration file describing the desired output and produces static const data arrays, preprocessor macros, and struct definitions ready to be #included by C code.

The tool supports a range of target platforms -- from resource-constrained microcontrollers (such as AVR) that require fixed-point integer arithmetic and flash storage attributes like PROGMEM, to systems equipped with single-precision or double-precision FPUs where native float or double arrays can be used directly. The scalar type for each data set is configurable, so the same configuration structure can target different hardware by changing a type parameter.

Key highlights

  • Precomputed DSP data -- generates wavetables, ADSR envelope curves, filter coefficients, and MIDI note phase steps as C arrays
  • Band-limited waveforms -- produces per-octave band-limited square, triangle, and sawtooth tables using BLIT synthesis to avoid aliasing
  • Fixed-point and floating-point support -- configurable scalar types from uint8_t to double, with optional fractional bit widths for integer-based fixed-point arithmetic or native float/double output for FPU-equipped platforms
  • Flexible output -- each output header file independently selects which modules and selectors to include, with per-output macros and includes
  • Expression evaluation -- macro and variable values can be computed from expressions with custom environments, enabling derived constants like baud rate registers
  • Chart generation -- optional HTML chart output for visual inspection of generated waveforms and curves

How it works

synth-datagen reads a synth-datagen.yml configuration file that defines global parameters (sample rate, amplitude, scalar types) and one or more output header files. Each output specifies its #include directives, #define macros, and DSP module invocations with selectors that control which data arrays to generate.

Running the tool produces C headers with a consistent structure:

// Code generated by "synth-datagen ..."; DO NOT EDIT.

// SPDX-FileCopyrightText: 2022-present Rafael G. Martins <rafael@rafaelmartins.eng.br>
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

#include <stdint.h>

#define adsr_sample_amplitude 0xff

static const uint8_t adsr_curve_as3310_attack[256] = {
    ...
};
#define adsr_curve_as3310_attack_len 256

All generated data is declared static const with automatically emitted #define macros for array dimensions (_len, _rows, _cols), making it straightforward to iterate over the data in firmware.

Explore further

  • DSP modules -- detailed documentation for each DSP module and the C arrays it produces
  • Configuration -- YAML configuration file format, global parameters, macros, and output structure
  • Source code -- GitHub repository
Project Metadata
License: BSD-3-Clause
API Documentation
rafaelmartins.com/p/synth-datagen
Project Statistics
Stars: 0
Watching: 1
Forks: 0
Updated: