Lab

recording

Recording into an arrangement: an input recorder on an AudioWorklet that keeps each block with its frame on the audio clock, the frames of a take with the latency taken off, and the audio or MIDI clip a take becomes, with record quantization and overdub

pnpm dlx shadcn@latest add @audio-ui/recording
import { takeFrames, sliceBlocks, blockPeak, audioTakeClip, RECORD_QUANTIZE, /* … */ } from "@/lib/recording";
Fileslib/recording.ts, lib/input-recorder.ts
Depends onarrangement
npm@audio-ui/core, @audio-ui/engine
Used byblock-audio-editor
ExportKindWhat it is
RecordedBlockinterfaceWhat came in from an input, block by block: each block's first frame on the audio clock, and its channels.
takeFramesfunctionWhere on the audio clock a take's sound was played: from and to on the arrangement, in seconds, while playback ran from playFrom at clock frame playAt.
sliceBlocksfunctionThe frames [from, to) of the clock out of blocks, as one channel array each: silence where no block came in.
blockPeakfunctionThe loudest sample of a block, over its channels: what a take drawn live shows of it.
audioTakeClipfunctionThe clip an audio take becomes: from where it started, as long as it lasted, over what lies under it.
PlayedNoteinterfaceA note played while recording, on the arrangement: where it started and ended, in seconds.
RECORD_QUANTIZEconstThe record quantizations: none, or a note value as a share of a whole note.
takeNotesfunctionThe notes of a MIDI take between from and to, in seconds from origin: each as long as it was held (to to when it is still held), its start moved to the nearest quantize seconds from origin when it is not 0 (REC-009).
midiTakeClipfunctionThe MIDI clip a take becomes, from from to to on the arrangement, over what lies under it.
overdubbedfunctionA MIDI clip with a take's notes added to its own (Overdub on, REC-009): placed in its source's time, so they sound where they were played.

Usage

Recording into the arrangement: an input recorder on an AudioWorklet (installed with it as input-recorder) that keeps blocks of the input with their frame on the audio clock, and the clips a take becomes, audio or MIDI.

import { createInputRecorder } from "@/lib/input-recorder";
import { audioTakeClip, takeFrames } from "@/lib/recording";

const recorder = await createInputRecorder(ctx); // null where worklets cannot run
input.connect(recorder.input);
recorder.start();
// … the take …
const blocks = await recorder.stop();
const [from, to] = takeFrames({ from, latency, playAt, playFrom, sampleRate: ctx.sampleRate, to });
const clip = audioTakeClip({ id, length, name: "Take 1", recording: id, start, track });

takeFrames lines the take up with the arrangement, taking the input's latency off; sliceBlocks keeps the frames inside it; midiTakeClip makes a MIDI clip of the notes played, quantized if asked; overdubbed merges a take over a clip. The Transport shows Record, count-in and Punch; what is recorded and when is the host's.

Built by Ouest Labs, the source code is available on GitHub.
RSS