import { type ReferenceComparison } from './audioReference'; import { type ProvenanceRow } from './audioProvenance'; type Json = Record; export type AudioIssueLevel = 'error' | 'warn'; export interface AudioIssue { code: string; level: AudioIssueLevel; /** JSON path of the row, e.g. `audio.bank.assets[3]` or `audio.slots[startup].assets[0]`. */ path: string; message: string; fix: string; } /** What a decoded WAV measured. */ export interface WavMeasure { format: 'pcm' | 'float' | 'other'; formatTag: number; channels: number; sampleRate: number; bitsPerSample: number; frames: number; durationS: number; /** dBFS of the loudest sample (−Infinity for all-zero). */ peakDbfs: number; /** dBFS RMS over the whole file. */ rmsDbfs: number; } /** An audio row the runtime will try to load, with where it came from. */ export interface AudioRow { path: string; /** `bank` = an engine/exhaust ladder rung; `slot` = a one-shot or loop on a named slot. */ use: 'bank' | 'slot'; slot?: string; /** The rpm label a bank ladder rung was authored at (from the blend's `[file, rpm]` samples). */ rpm?: number; row: Json; } /** Below this peak a sample is treated as silent. −60 dBFS is ~0.1 % of full scale. */ export declare const SILENT_PEAK_DBFS = -60; /** Below this RMS a sample is "very quiet": audible only with gain, flagged as a warning. */ export declare const QUIET_RMS_DBFS = -50; /** * Parse a RIFF/WAVE file and measure it. Throws with a plain reason on anything the engine's decoder would not take. * Handles PCM 8/16/24/32-bit and IEEE float 32/64, plus WAVE_FORMAT_EXTENSIBLE carrying either. */ export declare function measureWav(bytes: Uint8Array): WavMeasure; /** Judge one decoded sample. Returns issues; empty means it will play and is audible. */ export declare function judgeWav(path: string, label: string, m: WavMeasure): AudioIssue[]; /** A bank rung must be a real broadband engine sound, not a near-pure synthetic tone (round 5's biggest regression). */ export declare function judgeRungSpectral(path: string, label: string, bytes: Uint8Array): AudioIssue[]; /** * Clipping and DC offset, measured on the decoded samples of any row. Flat-topped runs (>= 3 consecutive samples) at * the converter's rails, or at the file's own peak after it was clipped and turned down, are hard distortion the ear * hears on a sustained engine note; the calibration set of real recordings (993, F355, platform pack, 41 field recordings) peaks at 0.04 % of samples, * the F40's limited rungs sit at 0.1-0.7 %. DC offset * clicks when a one-shot starts or a loop wraps; real recordings measured up to 0.0045 full scale (0.0143 on the worst of 41 field recordings). */ export declare function judgeClipDc(path: string, label: string, bytes: Uint8Array, use: AudioRow['use']): AudioIssue[]; /** A horn recorded from a real car has jitter and a noise floor; an exactly periodic synthetic tone is a beep. */ export declare function judgeHornRow(path: string, label: string, bytes: Uint8Array): AudioIssue[]; export interface LadderRef { /** `audio.bank.blends..samples[]`. */ path: string; blend: string; rungs: Array<{ name: string; rpm: number; }>; } /** Every distinct rung ladder the package's engine and exhaust blends drive. */ export declare function collectLadders(pkg: unknown): LadderRef[]; /** Ladder-level content defects: a copied rung, a fixed formant stack, a fixed tone. Needs each rung's decoded bytes. */ export declare function judgeLadders(pkg: unknown, bytesByName: ReadonlyMap): AudioIssue[]; /** The rev limiter slot is re-fired every 60 ms by the runtime, so it has to be a short crack: a long clip stacks into a held tone. */ export declare function judgeRevLimiterRow(path: string, label: string, bytes: Uint8Array): AudioIssue[]; export interface ClipRef { /** `bank` rung or `slot` one-shot. */ use: 'bank' | 'slot'; path: string; /** Slot name, or the ladder path for a rung. */ role: string; /** The asset name. */ name: string; rpm?: number; /** Human label for messages. */ label: string; bytes: Uint8Array; /** The sim recording the clip cites (provenance source file, take, transforms), when it cites one. */ source?: string; /** For a rung the source re-pitched itself: the take, without the rate (`sourceRepitchTake`). */ take?: string; } /** * The identity of the sourced recording a row cites: two roles citing the same take of the same source file are the * sim's own choice to play one recording for both (a sim drives two roles from one take; the idle * slot names the ladder's own idle rung), not lazy reuse. Undefined for an unsourced row. */ /** * A rung the SOURCE itself re-pitched (Assetto Corsa auto-pitch, an FMOD event's RPM pitch automation): the take it * plays, without the rate. Rungs sharing it are the sim playing one recording at several rpms — what the source does, * not a resampled copy passed off as independent recordings. Undefined for any other row. */ export declare function sourceRepitchTake(row: Json | undefined): string | undefined; export declare function sourcedRecordingKey(row: Json): string | undefined; /** * Near-duplicate SLOTS across roles: one take, one random seed or one resampled recording used under two names that are * meant to sound different (shift up vs shift down, horn vs an engine rung, an engine rung vs an exhaust rung, a door * open vs close). Same-ladder clusters are an error once they take half the ladder (or three rungs), a warning below. */ export declare function judgeNearDuplicates(clips: readonly ClipRef[]): AudioIssue[]; /** Every (ladder, rung) pair that has decoded bytes, as clips with the ladder as their role. */ export declare function rungClips(pkg: unknown, rungBytes: ReadonlyMap): ClipRef[]; export interface AudioCheckOptions { /** Real-car reference clips to compare the idle voice (and named slots) with. */ reference?: ReferenceClips; } /** What a reference clip is compared with in the candidate. */ export interface ReferenceClips { /** Slot name -> reference clips for it. `idle` is the engine at idle: the idle slot's sample, else the lowest engine-ladder rung. */ bySlot: ReadonlyMap>; } export interface ReferenceReportRow { slot: string; candidate: string; references: string[]; comparisons: ReferenceComparison[]; } /** Compare the candidate's idle voice (and any named slot) with real-car reference clips. */ export declare function judgeAgainstReference(pkg: unknown, clips: readonly ClipRef[], reference: ReferenceClips): { issues: AudioIssue[]; rows: ReferenceReportRow[]; }; /** * Comb ratio (the better of the firing series and its half-order series) at or above which a rung is pitched at its * label. Measured on real sim-mod/official F40 ladders (Kunos AC, euan / Gabry BeamNG mods; 130 rungs): 0 below 1.5, * 11 between 1.5 and 3, the rest above. */ export declare const FIRING_COMB_PASS = 3; /** * Below this the rung is off its label: two-octaves-down copies of those ladders measured below it on 128 of 130 rungs, * one-octave-down copies on 74; a synthesised rung at the crank order (round 7's fault) measures about 0.6. */ export declare const FIRING_COMB_OCTAVE_OFF = 1.5; /** The engine numbers a ladder rung's pitch is judged against, read from the package's `audio` block. */ export interface AudioPitchMeta { cylinderCount: number; strokes: number; crankLayout: string | undefined; /** A battery-electric car's motor ladder: no firing order, so no firing-fundamental pitch check. */ electric?: boolean; } export declare function audioPitchMeta(pkg: unknown): AudioPitchMeta; /** * A ladder rung's pitch must match its rpm label against the firing fundamental for the declared cylinder count, * strokes and crank layout. Rejects a rung an octave or more off (round 7 synthesised a flat-plane V8 at the crank * order — two octaves low); a rung that merely shows no clear comb is a warning, not a fail (its pitch is unverifiable). */ export declare function judgeRungPitch(path: string, label: string, bytes: Uint8Array, rpm: number, meta: AudioPitchMeta): AudioIssue[]; /** * Every audio row the runtime would try to load, selected exactly as PortableVehicleAudioAdapter selects them. * `includeUnconsumed` also returns the assets of `consumed: false` slots: they are part of the Package's runtime * closure (the engine validator requires their url/checksum/bytes), so upload, provisioning and sealing need them even * though the runtime does not play them today. */ export declare function collectAudioRows(pkg: unknown, opts?: { includeUnconsumed?: boolean; }): { rows: AudioRow[]; issues: AudioIssue[]; }; /** The adapter's own shape test (`normalizedAsset`): fields a row must carry for the runtime to even request it. */ export declare function runtimeRowIssues(r: AudioRow): AudioIssue[]; /** * Bare lowercase sha256 of a Continuum object id: `cid:sha256:` → ``, or a bare 64-hex sha unchanged. * Undefined for anything that is neither (a malformed or absent cid/checksum), so the membership check can skip it. */ export declare function sha256OfCid(value: unknown): string | undefined; /** * The sha256s a Package Version SEALS, normalized to bare hex. The closure is the manifest's `root` and every * `variants[].object` — the same set the publisher enforces and the runtime resolves audio from. Accepts a Package * Version manifest, a publication intent (`{ packageVersion, objects }`), or a publication receipt * (`{ objectCids }`), so the check works both before sealing (what we are about to seal) and after (what was sealed). */ export declare function sealedClosureSha256s(source: unknown): Set; /** * Membership: every loadable row's object must be sealed into the Package closure. The runtime resolves a vehicle's * audio from the closure, not from an arbitrary public URL — a row whose cid (or the sha256 of its bytes) is not in * the closure plays nothing and 404s, exactly as a missing url does, and it does so WITHOUT any error at the URL * itself (the object is public; it is simply not one the Package owns). A missing reference is a hard error. */ /** * The assets of `consumed: false` slots that still ship a recording (idle, intake, transmissionWhine on an * audio-import package). The runtime does not play them today, but they are in the Package's closure and the engine's * package validator requires each one to be a complete, loadable row — a broken one stops the car being presented. * So the checks verify they load (file or url, digest, size, a decodable WAV) without judging them as played sounds. */ export declare function unconsumedAudioRows(pkg: unknown): AudioRow[]; export declare function closureMembershipIssues(rows: AudioRow[], closure: ReadonlySet): AudioIssue[]; /** Where a row's local file is: `file`, then `path`, then `name`, each beside the package and under `audio/`. */ export declare function localFileFor(row: Json, dir: string): string | undefined; /** Placeholder origin for local preflight; replace it with a verified public object URL before sealing. */ export declare const PENDING_AUDIO_ORIGIN = "https://pending-upload.invalid"; /** * Fill each loadable row that has a LOCAL file but no url with the file's checksum/bytes/cid/mediaType and a * placeholder url, so the engine's own package validator (which requires a complete runtime closure) can judge the * rest of the package before anything is uploaded. Returns the copy and how many rows were filled. */ export declare function provisionalAudio(pkg: unknown, dir: string): { pkg: unknown; filled: number; }; export interface AudioCheckRowReport { path: string; use: 'bank' | 'slot'; slot?: string; name: string; source: 'local' | 'url'; file?: string; url?: string; httpStatus?: number; bytes?: number; checksumSha256?: string; measure?: WavMeasure; } export interface AudioCheckReport { ok: boolean; mode: 'local' | 'read-back'; errors: number; warnings: number; /** No `audio.bank`: the platform's synthesised fallback engine plays instead. */ fallbackEngine: boolean; rows: AudioCheckRowReport[]; issues: AudioIssue[]; /** Timbre measured against the supplied real-car reference clips (only when `--reference` was given). */ reference?: ReferenceReportRow[]; /** Where each slot's recordings came from (audioProvenance.ts). */ provenance?: ProvenanceRow[]; } export type FetchLike = (url: string) => Promise<{ status: number; bytes: Uint8Array; }>; export declare const defaultFetch: FetchLike; /** * PRE-SEAL: every row that will be loaded must resolve to either a local WAV beside the Package or an already-public * URL; local files are decoded and measured, and URLs are fetched. Exact object pins and public URLs are required * before sealing, so these fields are optional only during local preflight. */ export declare function checkAudioLocal(pkg: unknown, dir: string, fetchImpl?: FetchLike, closure?: ReadonlySet, options?: AudioCheckOptions): Promise; /** * READ-BACK: the package as the runtime receives it. Every selected row must pass the adapter's shape test AND * fetch 200 with the declared size and digest AND decode to an audible WAV. Identical urls are fetched once. */ export declare function checkAudioReadBack(pkg: unknown, fetchImpl?: FetchLike, closure?: ReadonlySet, options?: AudioCheckOptions): Promise; export declare function formatAudioReport(report: AudioCheckReport): string; export {};