Skip to content

cdp-wasm-suite/cdp-sampler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@cdp-wasm-suite/cdp-sampler

The single source of truth for the cdp-sampler polyphonic one-shot sampler DSP, shared by two targets:

  • cdp-web (standalone web app) — compiled to WebAssembly and run inside an AudioWorklet.
  • cdp-plugin (VST/AU/Clap) — include/CDPSampler.h is compiled directly into the C++ plugin.

Both run byte-identical DSP: a fixed voice pool, oldest-voice stealing, and 4-point cubic-Hermite (Catmull-Rom) interpolation. MIDI note 60 plays the sample at native speed; each semitone is a 2^(1/12) playback-rate step, scaled by sampleRate / hostRate. One-shot: note-off lets a voice ring to the sample's end.

Install

The package is published to GitHub Packages. Point the @cdp-wasm-suite scope at the GitHub registry in your project's .npmrc (a GITHUB_TOKEN with read:packages is required):

@cdp-wasm-suite:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
npm install @cdp-wasm-suite/cdp-sampler

Layout

Path Used by
include/CDPSampler.h header-only DSP (cdp::Sampler) — included by C++ and WASM
src/cdp_sampler_wasm.cpp C ABI wrapper for the WASM build
scripts/build-wasm.sh Emscripten build → wasm/cdp-sampler.wasm
wasm/cdp-sampler.wasm standalone module the AudioWorklet instantiates

Build the WASM

source /path/to/emsdk/emsdk_env.sh   # Emscripten on PATH
npm run build:wasm

The output is a STANDALONE_WASM module: it carries its own malloc + linear memory and imports only env.emscripten_notify_memory_growth (a no-op), so it instantiates inside an AudioWorkletGlobalScope from raw bytes. Call the exported _initialize() once after instantiation.

C ABI

void   cdpsamp_init(int numVoices, double hostSampleRate);
void   cdpsamp_set_host_sample_rate(double sr);
float* cdpsamp_alloc_sample(int numChans, int numFrames);   // write planar PCM here
void   cdpsamp_commit_sample(int numChans, int numFrames, double sampleRate);
void   cdpsamp_note_on(int note, int vel);
void   cdpsamp_note_off(int note);
void   cdpsamp_all_notes_off(void);
float* cdpsamp_out_ptr(void);    // planar: channel c at out_ptr + c*max_block
int    cdpsamp_max_block(void);
void   cdpsamp_process(int numChans, int numFrames);

Use from C++ (cdp-plugin)

#include "CDPSampler.h"   // via header search path to this repo's include/

cdp::Sampler mSampler;
mSampler.Init(16, hostSampleRate);
mSampler.SetSample(planarFloats, numChans, numFrames, sampleRate);  // borrowed pointer
mSampler.NoteOn(60, 100);
mSampler.Process<double>(outputs, numChans, numFrames);             // overwrites outputs

About

Simple polyphonic sampler player used by cdp-plugin and cdp-web

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors