Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ppl-synth

The sound synthesizer used in PewPew Live.

Heavily based on and compatible with jfxr.

Repo organisation

  • src/ contains the code for the library.
  • example/ contains a minimal example that generates two pcm files.

Using the library

Step 1: Define a configuration:

SynthesizerConfig config;
config.frequency_ = 200;
config.sustain_ = 0.04;
config.decay_ = 0.14;
config.frequency_jump1_amount_ = 60;
config.wave_generator_type_ = SynthesizerConfig::SAWTOOTH;

The values for the configuration can be found by using jfxr.

There complete list of supported fields can be found in the source code for SynthesizerConfig.

Step 2: Synthetize the sound using said configuration:

auto pcm_data = Synthesize(config);

Building and running the example

example/ contains an example usage of the library.

You build the example with CMake.

To build from the command line:

mkdir out
cd out
cmake ..
make

Executing the binary results in the creation of 2 raw pcm files. Those raw pcm file can be played with ffplay:

ffplay -f s16le -ar 22k -ac 1 out_16bit.pcm

Benchmarks

benchmark/ contains a speed benchmark that synthesizes a representative set of 2-second sounds (one per wave generator, plus modulation, harmonics and flanger variants) and reports the time per sound.

Build and run it the same way as the example:

mkdir out
cd out
cmake ../benchmark
make
./ppl_synth_benchmark

The binary optionally takes the number of iterations per sound as its first argument (defaults to 200).

Tests

test/ contains a golden test that checks the synthesizer still generates approximately the same sounds as before. For the same representative set of sounds as the benchmark, it compares, against the reference recorded in test/golden_data.h, the sample count, the overall RMS and peak amplitude, a coarse RMS amplitude envelope over 32 time windows, and a coarse zero-crossing-rate profile over those windows.

These are deliberately characteristics that survive small phase/timing drift, so output-preserving optimizations (reordered floating-point math, a reformulated phase accumulator, an approximate transcendental, ...) keep passing while genuine changes to a sound's envelope, energy or pitch are still caught. Raw sample values are intentionally not compared: two waveforms that sound the same but are shifted by a fraction of a sample differ wildly sample-for-sample.

Build and run it with CMake/CTest:

mkdir out
cd out
cmake ../test
make
ctest --output-on-failure

After an intentional change to the synthesizer output, regenerate the reference (the values depend on the platform's math and RNG implementations):

./ppl_synth_test --generate > ../test/golden_data.h

About

The synthesizer that's used in PewPew Live

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages