# API map

`import * as sd from '<skill>/lib/node.js'` (scripts: everything + file IO + PNG) · `lib/index.js` (browser-safe)
· `lib/webaudio/index.js` (Web Audio layer). Buffers are plain objects **`{ sr, ch: [Float32Array, …] }`**;
functions taking `x` work on one `Float32Array`, functions taking `buf`/`b` on a buffer. `n` = samples,
times in seconds, `sr` defaults to 48000 (`sd.SR`). Every generator takes a `seed`. Source files are short and
commented — open them when you need the exact behaviour.

## core
| Area | Functions |
|---|---|
| util | `SR C_AIR clamp lerp expLerp db2lin lin2db mtof ftom smoothstep t60coef panGains shape` |
| rng | `rng(seed)` → `RNG`: `next() bi() range(a,b) xrange(a,b) int(a,b) chance(p) pick(arr) gauss() exp(rate) logn(median,sigma) jitter(v,amt) shuffle(arr) fork(tag)` |
| buffers | `makeBuf(seconds,sr,channels) mono(x,sr) stereo(l,r,sr) frames(b) duration(b) clone toMono toStereo(b,pan)` · `mix([{buf,at,gain,gainDb,pan}]) mixInto(dst,src,{at,gain,gainDb,pan})` · `gain gainDb peak rms normalize(b,db) fadeIn fadeOut declick(b,ms) slice(b,t0,t1) pad concat reverse trim(b,thresholdDb) applyEnv mapCh` · `varispeed(b,rate) resample(b,newSr) readHermite sanitize` |
| noise | `noise(n,'white'\|'pink'\|'brown'\|'blue'\|'violet',seed) smoothNoise(n,freq,sr,seed,period) fbm(n,freq,sr,seed,{octaves,period}) velvet(n,density,sr,seed)` · streaming `Pink Brown Dust SmoothNoise Fbm` |
| oscillators | `osc(n,'sine'\|'saw'\|'square'\|'tri'\|'pulse',f,sr,{phase,pw,fm}) sine fm(n,fc,ratio,index,sr) partials(n,[{f,amp,t60}],sr)` — `f` may be number, array or `(t)=>Hz` |
| envelopes | `env(n,sr,[[t,v,curve],…]) perc(n,sr,attack,t60) adsr(n,sr,a,d,s,r) glide(n,a,b) follow(x,sr,attack,release)` · `mul(a,b) add(...xs) scaleTo(x,lo,hi)` |
| filters | `filt(x,sr,type,f,q,gainDb)` (lowpass highpass bandpass notch peaking lowshelf highshelf allpass) `filtN eq(x,sr,[[type,f,q,gain],…]) tilt(x,sr,dbPerOct,pivot)` · `sweep(x,sr,'lp'\|'bp'\|'hp'\|'notch',f,q)` with time-varying f/q · streaming `Biquad SVF OnePole DCBlock Resonator` |
| FFT | `stft(x,{size,hop}) istft(S) magnitudes(S) welch(x,sr,size) convolve(a,b) getFFT(n) nextPow2 window(n,kind)` |
| effects (x) | `drive(x,driveDb,'tanh'\|'soft'\|'hard'\|'asym'\|'fold'\|'rect',mix) bitcrush(x,bits,downsample) ringmod(x,sr,f,mix) tremolo(x,sr,rate,depth) exciter(x,sr,{freq,amount}) subharmonic(x,sr,{amount}) transientShape(x,sr,attack,sustain) decorrelate(x,sr,{amount})→stereo haas(x,sr,ms)` |
| effects (buf) | `chorus(b,{rate,baseMs,depthMs,mix,feedback}) phaser(b,{…}) echo(b,{time,feedback,mix,lp,pingpong}) width(b,amount,monoBelow) compress(b,{thresholdDb,ratio,attack,release,kneeDb,makeupDb,mix}) limit(b,{ceilingDb,lookahead,release,gainDb}) duck(b,key,{amountDb}) each(b,(x,sr)=>x')` · `DelayLine` |
| reverb | `synthIR({rt60,size,damping,bassRatio,er,predelay,density,width,seed}) reverb(b,{…room,wetDb,dryDb,wetOnly}) convReverb(b,ir,{wetDb,dryDb}) fdnReverb(b,{rt60,size,damping,auto}) FDN SPACES convolveLong` |
| wav | `encodeWav(b,{bitDepth}) decodeWav(bytes)` · node: `readWav readAudio writeWav(path,b,{bitDepth,meta}) save(path,b,{lens,expect,meta})` |
| kernel | `Kernel` (extend) `register(name,Class) KERNELS renderKernel(k,seconds,{automation,events}) OneShots` |

## synth
| Module | Functions |
|---|---|
| modal | `MATERIALS objectModes({shape,material,f0\|size,count,hit,damping,split,spread,aspect,seed}) morphModes(modes,{pitch,damping,tiltDbOct,jitter})` · `strikeForce(sr,{hardness,velocity,mass}) resonate(force,modes,n,sr) strike(modes,{velocity,hardness,click,thud,duration}) strikes(modes,events,{hardness,variation}) bounceEvents({height,restitution,irregular})` · `rollForce(n,sr,{speed,radius,roughness,wobble}) scrapeForce(n,sr,{speed,pressure,grain,roughness}) stickSlipForce(n,sr,{rate,jitter,sharpness})` · `shatter({material,shape,f0,pieces,scatter}) thump(n,sr,{f,decay,noiseColor,tone})` · `ModalBank PhysicsSonifier` (kernel `physics`: `impact() contact(id,…) contactEnd(id) addBody setBody`) |
| particles | `GrainFlow` (kernel `grains`) `SURFACES pour({surface,seconds,rate,size,height,cover,…}) crunch({surface,size,pressure,seconds})` |
| nature | kernels `Wind Rain Fire Stream Sea Birds Insects` · `birdCall(sr,{f,range,syllables,rate,figure,harm}) thunder({distance,seconds})` |
| mech | kernels `Hum Air Engine Traffic Machine Clock RoomTone` · `siren(sr,{kind,seconds}) horn(sr,{seconds,size})` |
| voice | `speak(text,{engine,voice,seed})→{buf,duration,marks} VOICES planSpeech(text,{rate,range,gibberish}) voiceFx(buf,kind) crowd({voices,seconds,lines,energy,room})` |

## gen / scene / sample
| Module | Functions |
|---|---|
| cinematic | `impact({weight,brightness,character,tail,sub,body,crack,debris,room}) boom({f,seconds,punch}) subDrop({from,to,seconds}) riser({kind,seconds,curve,from,to,note,semitones}) whoosh({texture,seconds,peakAt,from,to,pan}) braam({note,seconds,growl,brightness}) downer shimmer({note,density,scale,rise}) drone({mood,note,seconds,motion,period}) heartbeat({bpm,seconds}) glitch(buf,{grid,stutter,rev,crush,gate,pitch}) reverseSwell(buf,{seconds})` · `cue(layers,{sync})→{buf,sync} master(buf,{target,ceilingDb,glue,monoBelow})` |
| spatial | `spatialize(buf,{path,listener,model,refDistance,rolloff,doppler,air,occlusion,room,roomDb}) passBy({speed,distance,at}) orbit({radius,period}) flyThrough({from,to,duration}) pathFromKeys([[t,x,y,z]]) airCutoff(d)` |
| scene | `renderScene(scene) loopKernel(name,opts,{seconds,xfade}) makeLoop(buf,{seconds,xfade}) tailWrap(buf,seconds) zoneWeights` |
| sample | `sampleModel(buf) resynth(model,{pitch,damping,brightness,tonal,noise,transient,stretch,jitter}) variations(model,count,{jitter}) enhance(buf,{sub,air,punch,tiltDbOct,widen,room,glue}) granulate(buf,{seconds,grain,density,pitch,scan})` |

## analysis
`analyze(buf,{lens}) formatReport(rep) checkExpectations(rep,exp) flatten(rep) loopStats(buf) LENSES` ·
`loudness(buf)→{integrated,momentaryMax,shortTermMax,lra,…} truePeakDb(buf) normalizeLoudness(buf,target,mode)` ·
`compare(a,b) formatCompare variety(bufs,names) formatVariety fingerprint` · `spectrogramPng(buf,{t0,t1,width,height})` ·
measurements: `envelope envelopeStats spectrogram spectralStats spectralPeaks harmonicity pitchTrack onsets periodicity modulation kurtosis stereoStats defects`

## webaudio (`lib/webaudio/index.js`)
`webAudio()` (resolve classes: browser or server emulation) · `renderOffline(seconds, build(ctx))` ·
`kernelNode(ctx,name,opts)` → node with `.set({…}) .call(method,…args) .kill()` · `installKernels(ctx,url?)` ·
`tract(ctx,spec)` → `{input,output,nodes}` · `new SpatialSource(ctx,{…})` → `.input .output .moveTo(p,when) .follow(path,t0,t1)` ·
`AmbienceMixer.create(ctx,scene)` → `.output .goto(zone,xfade) .play(timeline) .layer(name)` · `toAudioBuffer fromAudioBuffer`

## Idioms
```js
// noise burst shaped and filtered
const x = sd.mul(sd.sweep(sd.noise(n, 'pink', seed), sr, 'bp', (t) => 300 * 20 ** (t / dur), 2), sd.perc(n, sr, 0.005, dur));
// layer with offsets, then finish
const out = sd.master(sd.mix([{ buf: a }, { buf: b, at: 0.03, gainDb: -6, pan: 0.3 }]), { target: -18 });
// kernel with automation → file → report
const k = new sd.Wind(sd.SR, { seed: 2 });
sd.save('wind.wav', sd.renderKernel(k, 20, { automation: { speed: [[0, 0.2], [12, 0.9], [20, 0.4]] } }), { lens: 'texture' });
// moving source
sd.spatialize(src, { path: sd.passBy({ speed: 30, distance: 5, at: 2 }), room: sd.SPACES.streetCanyon });
```
