Skip to content

Latest commit

 

History

History
98 lines (64 loc) · 14.5 KB

README.md

File metadata and controls

98 lines (64 loc) · 14.5 KB

PL_SYNTH

Create raw samples for sound effects and music in JS and C/C++. The synthesizer is a port of Sonant, the tracker is written from scratch.

Release Version

pl_synth is implemented in multiple different ways. The release files are self-contained, i.e. you only need to use one of these files in your project.

  • release/pl_synth.min.js - the minified version of the vanilla JS implementation. 1.2kb gzipped.
  • release/pl_synth_wasm.min.js - the minified version of the JS+WASM implementation. The compiled WASM is embedded. 2.5kb gzipped, but about twice as fast as vanilla JS. Recommended if you're not size-restricted.
  • c/pl_synth.h - a single header library for C/C++

Tracker software

Songs and sound effects can be created with the tracker software contained in tracker.html. After cloning this repo, the tracker can be launched with a simple doubleclick (i.e. it loads fine from a file:// url). The only requirement for the tracker is release/pl_synth_wasm.min.js.

An online version can be found at https://phoboslab.org/synth/

Demo Songs

Usage

In a browser, load the pl_synth_wasm.min.js, instantiate pl_synth and then use synth.sound() and synth.song() to create WebAudio AudioBuffers. These AudioBuffers can be re-used for multiple AudioBufferSourceNodes, so you only need to generate them once.

pl_synth_wasm_init(audioContext, callback(synth))

When using the JS+WASM version, this asynchronously instantiates pl_synth with the given AudioContext.

pl_synth_init(audioContext)

When using the vanilla JS version, this instantiates pl_synth with the given AudioContext. Returns the synth instance.

synth.sound(instrument, note = 147, row_len = 5513)

Creates a single sound effect with the given instrument data (as created with the tracker), and an optional note and row_len. The default note value 147 correspondes to a C-5 note. The default row_len correspondes to 120 BPM. Returns a WebAudio AudioBuffer.

synth.song(songData)

Creates a whole song with the given songData (as created with the tracker). Returns a WebAudio AudioBuffer.

Synopsis

<script src="pl_synth_wasm.min.js"></script>
<script>
// Create a new WebAudio context
let audioContext = new AudioContext();

// Instantiate the JS+WASM pl_synth. Since we need to compile the the embedded 
// WASM module you need to wait for the callback to use it.
pl_synth_wasm_init(audioContext, (synth) => {

	// Create a sound effect
	buffer = synth.sound([7,3,140,1,232,3,8,,9,1,139,3,,4611,1403,34215,256,4,1316,255,,,,1,,1,7,255]);

	// Create a WebAudio AudioBufferSourceNode and play it
	let source = audioContext.createBufferSource();
	source.buffer = buffer;
	source.connect(audioContext.destination);
	source.start();
});
</script>

Also have a look at example.html.

Native C/C++ Version

For usage of the native C/C++ version please refer to the documentation within c/pl_synth.h and have a look at c/example.c. This uses pl_synth.h to generate some music and saves it as example.wav