/** helper functions for generating spectrograms */ import { AudioInformation } from "./audioInformation"; import { SpectrogramOptions } from "../../components/spectrogram/spectrogramOptions"; /** * A class to generate a spectrogram from an sample buffer. * The output is a Uint8ClampedArray that can be painted into a canvas. * This is a big messy, stateful, side-effecty class that is designed to * reduce allocations and improve performance. */ export declare class SpectrogramGenerator { #private; private audio; private options; private fft; private fftWidth; private fftHeight; private smooth; private colorScale; private melScale; /** This is the last column of spectrum we converted into pixels */ private lastFrameIndex; private imageBuffer; private readonly fftOutput; private readonly complexInput; private readonly window; private readonly spectrum; readonly estimatedWindowLoss: number; private readonly amplificationFactor; constructor(audio: AudioInformation, options: SpectrogramOptions); get nyquist(): number; get step(): number; get size(): number; get outputBuffer(): Uint8ClampedArray; get width(): number; get height(): number; get totalSamples(): number; /** * Generate a 2D spectrogram from the audio samples. * Assumes a progressive rendering scenario where the audio samples are * continuously fed into the spectrogram. * If it can't fill a window with samples, it will wait partially consume the current buffer with the assumption * the next buffer will include the unconsumed samples. * To indicate the end of the audio stream supply `consumeAll = true` to consume all samples in the buffer. * @param samples The audio samples to generate the spectrogram from. * @param lastSampleIndex The index of the last sample in the input buffer. * The buffer may have more samples than this but they should be considered uninitialized memory. * @param consumeAll If true, the function will consume all samples in the buffer. * @returns The number of samples consumed from the input buffer. */ partialGenerate(samples: Float32Array, lastSampleIndex: number, consumeAll: boolean): number; private extractWindow; private interleaveReals; /** * Converts the output of the fft into a magnitude and scales it. * We keep only the positive frequencies and discard the dc offset and negative frequencies. * @param fftOutput The output of the fft. * @param spectrum The array to store the magnitude of the fft. * @param windowSize */ private extractMagnitudeAndScale; private paintSpectrumIntoPixelBuffer; }