Skip to content

Node.js Native Editing and Retune ​

@libraz/libsonare-native carries the same editing surface as the browser package: the vocal edit session family, the block-by-block StreamingRetune pitch shifter and the note-editing helpers. The names, requests and results are the ones documented for the browser, so this page is a map of what Node exports and the few places it differs. Offline Vocal Editing is the walkthrough, and Projects and Editing API and Pitch and Notes API are the per-symbol references. Conventions, errors and handle release are on Node.js Native API.

Vocal edit sessions ​

createVocalEditSession({ samples, sampleRate, ...options }) analyses mono audio and opens a VocalEditSession; restoreVocalEditSession({ samples, sampleRate, state }) reopens one from session.exportState() and the same samples. Edits happen in a draft, and rendering happens from an immutable snapshot, so a render never sees a half-applied edit.

Editing and rendering a vocal take
beginEditapply, commitcaptureRenderSnapshotrender,renderAsync, jobcreateVocalEditSessionVocalEditDraftCommitted revisionVocalRenderSnapshotRendered samples
A draft batches operations against one revision; a snapshot freezes a state so rendering is independent of later edits.
ClassRole
VocalEditSessionThe analysed notes, the committed revision, undo() / redo() and history(). Disposing it also disposes every draft it began
VocalEditDraftOne edit transaction: apply({ operations }), then commit() or cancel(). Passing expectedRevision refuses the call when the session has moved on
VocalRenderSnapshotAn immutable render view with its own lifetime. render(request) is synchronous and polls an optional cancel hook, renderAsync(request) renders off the calling thread and takes an AbortSignal, and beginRenderJob(request) returns a job
VocalRenderJobAn incremental render: next() advances one work unit, finalize() collects the samples, abort() stops it

Revisions and request ids are decimal strings, because a 64-bit counter exceeds 2^53. A canceled render publishes no partial samples. vocalEditAbiVersion() is undefined in a build without vocal editing, and capabilities().features.vocalEdit reports the same fact.

typescript
import { createVocalEditSession } from '@libraz/libsonare-native';

using session = createVocalEditSession({ samples, sampleRate });
const { notes } = session.notes();

using draft = session.beginEdit();
draft.apply({ operations: [{ kind: 'reset', noteIds: [notes[0].id] }] });
draft.commit();

using snapshot = session.captureRenderSnapshot();
const { samples: edited } = snapshot.render({});

A Project applies a committed render to a clip or take with applyVocalEdit(request), lists what each clip depends on with vocalEditDependencies(), and re-renders stored edits against the original audio with rehydrateVocalEdits(originals, options?); a truthy return from options.cancel stops the rehydrate. See Projects and Editing API for the request shapes.

StreamingRetune ​

StreamingRetune is the block-by-block mono pitch shifter. Construct it with { pitchSemitones?, mix?, grainSizeSamples? }, call prepare(sampleRate, maxBlockSize) once, then processMono(block) per block; the output has the input's length. setConfig(config) changes the controls between blocks, config() reads them back in a form setConfig accepts, and reset() clears the grain state. pitchSemitones is in [-24, 24], mix in [0, 1], and grainSizeSamples a multiple of 4 in [4, 8192]; omitting it picks an automatic grain of about 46 ms that grainSizeSamples reports after prepare. A new grain size applies at the next prepare. latencySamples is one grain. A non-finite control or a block holding a non-finite sample is refused rather than substituted. Release it with destroy(), or using.

typescript
import { StreamingRetune } from '@libraz/libsonare-native';

const retune = new StreamingRetune({ pitchSemitones: 3, mix: 1 });
retune.prepare(48000, 512);
const shifted = retune.processMono(block);
retune.setConfig({ pitchSemitones: -2 });
retune.destroy();

Note helpers ​

The note-editing helpers work on a monophonic take and its F0 track. They take a request object (the positional form (samples, sampleRate, options) exists for the ones that take audio), and a shape error is a TypeError or RangeError naming the call. Option tables are on Pitch and Notes API.

FunctionUse
extractNotes(request)Segments an F0 track into notes, each with its median pitch, quality figures, amplitude curve and an identity edit. Nothing is applied
renderNotes(request)Resynthesizes the audio from edited notes; a set whose edits are all identity returns the input unchanged
decomposeNotePitch(request)Splits a note's pitch into centre, slow drift and vibrato curves that add back to the original
splitNote(request) / mergeNotes(request)Cut one note in two, or join a run of notes into one that takes the first note's edit
noteTargetsFromSmf(request)Reads note targets from a Standard MIDI File, honouring its tempo map
assignNoteTargets(request)Matches each note to the target it overlaps longest and sets the correction, limited by maxCorrectionSemitones
noteStretch(request) / noteMove(request)Time-stretch or move one note region of the audio
pitchCorrectToMidi(request)Retunes a held note from one MIDI pitch to another; listed with the effects on Node.js Native Analysis, Effects and Utilities