UNPKG

audio-inspect

Version:

Lightweight yet powerful audio analysis library

106 lines (102 loc) 2.92 kB
/** * audio-inspect ライブラリの型定義 */ /** * 音声データの構造 */ interface AudioData { /** サンプルレート(Hz) */ sampleRate: number; /** チャンネルごとのオーディオデータ */ channelData: Float32Array[]; /** 音声の長さ(秒) */ duration: number; /** チャンネル数 */ numberOfChannels: number; /** サンプル数 */ length: number; } /** * バイカッドフィルタ係数の型定義 */ interface BiquadCoeffs { b0: number; b1: number; b2: number; a0: number; a1: number; a2: number; } interface LUFSOptions { channelMode?: 'mono' | 'stereo'; gated?: boolean; calculateShortTerm?: boolean; calculateMomentary?: boolean; calculateLoudnessRange?: boolean; calculateTruePeak?: boolean; } interface LUFSResult { integrated: number; shortTerm?: Float32Array; momentary?: Float32Array; loudnessRange?: number; truePeak?: number[]; statistics?: { percentile10: number; percentile95: number; }; } /** * テスト用:K-weightingフィルタ係数を取得 * @param sampleRate サンプルレート * @returns K-weightingフィルタ係数 */ declare function getKWeightingCoeffs(sampleRate: number): BiquadCoeffs[]; declare function getLUFS(audio: AudioData, options?: LUFSOptions): LUFSResult; declare class RealtimeLUFSProcessor { private sampleRate; private channelMode; private blockSize; private hopSize; private blockBuffer; private maxBlocks; private currentSamples; private sampleCount; private biquadStates; private totalSamplesProcessed; constructor(sampleRate: number, channelMode?: 'mono' | 'stereo', maxDurationMs?: number); /** * 新しいオーディオチャンクを処理 * @param chunk - 入力オーディオチャンク(チャンネルごとのFloat32Array配列) * @returns 現在のLUFS値(integrated, momentary, shortTerm) */ process(chunk: Float32Array[]): { integrated: number; momentary: number; shortTerm: number; }; /** * 現在の統合ラウドネスを計算 */ private calculateCurrentLUFS; /** * 状態をリセット */ reset(): void; /** * 現在のブロックバッファ数を取得 */ getBufferSize(): number; } interface RealtimeLUFSOptions { channelMode?: 'mono' | 'stereo'; maxDurationMs?: number; } /** * リアルタイムLUFS処理器を取得 * @param sampleRate サンプルレート * @param options 処理オプション * @returns リアルタイムLUFS処理器 */ declare function getLUFSRealtime(sampleRate: number, options?: RealtimeLUFSOptions): RealtimeLUFSProcessor; export { type LUFSOptions, type LUFSResult, type RealtimeLUFSOptions, getKWeightingCoeffs, getLUFS, getLUFSRealtime };