Divooka Reference

Spectral

8 nodes

On this page 8

Draw Short-Time Transform

Function

Draws a spectrogram: time across, frequency up, and how strong each frequency is at each moment as brightness.

Signature
DrawTransform -> Pixel Image
    spectrogram: Audio Spectrogram
    width: Integer
    height: Integer
PixelImage DrawTransform(
    AudioSpectrogram spectrogram,
    int width = 800,
    int height = 300)

Parameters

nametypedefaultdescription
spectrogramAudio Spectrogram—The transform.
widthInteger800Pixels across.
heightInteger300Pixels up.

Returns

PicturePixel Image

Remarks

Several channels are drawn as their average. Levels run from -100 dB, black, to 0 dB, white, through the same colours as Draw Spectrogram, so a band taken out shows as a dark stripe.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Inverse Transform

Function

Puts a clip back together from its frequencies: the inverse short-time Fourier transform.

Signature
Inverse(spectrogram: Audio Spectrogram) -> AudioBuffer
AudioBuffer Inverse(AudioSpectrogram spectrogram)

Parameters

nametypedefaultdescription
spectrogramAudio Spectrogram—The transform, changed or not.

Returns

AudioAudioBuffer

Remarks

Each frame is turned back into samples, windowed again and overlap-added, and the sum divided by how much window covers each sample. A spectrogram nothing has changed comes back as the clip it was taken from, to within float rounding.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Keep Band

Function

Keeps only the frequencies from Low up to High.

Signature
KeepBand -> Audio Spectrogram
    spectrogram: Audio Spectrogram
    low: Number
    high: Number
AudioSpectrogram KeepBand(
    AudioSpectrogram spectrogram,
    double low = 300,
    double high = 3000)

Parameters

nametypedefaultdescription
spectrogramAudio Spectrogram—The transform.
lowNumber300The band's lower edge, in hertz.
highNumber3000The band's upper edge, in hertz; above half the sample rate means everything from the lower edge up.

Returns

SpectrogramAudio Spectrogram

Remarks

A frequency is kept when its bin's centre lies in the band, low end included and high end not, and the rest are set to nothing. Keep Band and Remove Band with the same edges are exact complements: the two inverses add up to the clip.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Remove Band

Function

Takes out the frequencies from Low up to High and keeps the rest.

Signature
RemoveBand -> Audio Spectrogram
    spectrogram: Audio Spectrogram
    low: Number
    high: Number
AudioSpectrogram RemoveBand(
    AudioSpectrogram spectrogram,
    double low = 300,
    double high = 3000)

Parameters

nametypedefaultdescription
spectrogramAudio Spectrogram—The transform.
lowNumber300The band's lower edge, in hertz.
highNumber3000The band's upper edge, in hertz.

Returns

SpectrogramAudio Spectrogram
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Separate Harmonic and Percussive

Function

Divides a clip into what holds steady - notes, chords, sustained voices - and what is brief and broad - drums, clicks, consonants.

Signature
SeparateHarmonicPercussive -> (harmonic: AudioBuffer, percussive: AudioBuffer)
    audio: AudioBuffer
    kernel: Integer
    power: Number
    frameSize: Integer
    hop: Integer
void SeparateHarmonicPercussive(
    AudioBuffer audio,
    out AudioBuffer harmonic,
    out AudioBuffer percussive,
    int kernel = 31,
    double power = 2,
    int frameSize = 2048,
    int hop = 512)

Parameters

nametypedefaultdescription
audioAudioBuffer—The clip.
kernelInteger31How many frames, and frequencies, each median spans; odd. Wider separates more firmly and smears more.
powerNumber2How firmly each frequency is given to one side: 1 shares in proportion, 2 is librosa's default, higher approaches all or nothing.
frameSizeInteger2048Samples per frame, as Short-Time Transform takes it.
hopInteger512Samples between frames, as Short-Time Transform takes it.

Returns

harmonicAudioBuffer
percussiveAudioBuffer

Remarks

Fitzgerald's median-filtering method, as librosa's decompose.hpss computes it: across time the steady parts stand out, across frequency the sharp ones do, and each frequency at each moment is shared between the two in proportion. The shares add to one everywhere, so the two parts mixed together are the clip.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Split Into Bands

Function

Divides a clip into frequency bands - lows, mids, highs, or as many as the edges make - which add back up to the clip.

Signature
SplitIntoBands -> AudioBuffer Array
    audio: AudioBuffer
    edges: Number Array
    frameSize: Integer
    hop: Integer
AudioBuffer[] SplitIntoBands(
    AudioBuffer audio,
    double[] edges,
    int frameSize = 2048,
    int hop = 512)

Parameters

nametypedefaultdescription
audioAudioBuffer—The clip.
edgesNumber Array—Where one band ends and the next begins, in hertz, rising.
frameSizeInteger2048Samples per frame, as Short-Time Transform takes it.
hopInteger512Samples between frames, as Short-Time Transform takes it.

Returns

BandsAudioBuffer Array

Remarks

Edges at 250 and 4000 Hz give three clips: everything below 250 Hz, 250 to 4000 Hz, and everything above. Every frequency lands in exactly one band, so Mix All of the bands is the clip again.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Strongest Frequencies

Function

The frequencies a clip holds most of - its constituents, strongest first, each with its level and the note nearest it.

Signature
StrongestFrequencies -> Table
    audio: AudioBuffer
    count: Integer
Table StrongestFrequencies(AudioBuffer audio, int count = 10)

Parameters

nametypedefaultdescription
audioAudioBuffer—The clip.
countInteger10How many to list.

Returns

FrequenciesTable

Remarks

Peaks of the clip's averaged spectrum, each placed between bins by fitting a parabola to it and its neighbours. A peak within a semitone of a stronger one is the same constituent's skirt and is left out.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing

Short-Time Transform

Function

Takes a clip apart into its frequencies over time: the short-time Fourier transform.

Signature
Transform -> Audio Spectrogram
    audio: AudioBuffer
    frameSize: Integer
    hop: Integer
AudioSpectrogram Transform(
    AudioBuffer audio,
    int frameSize = 2048,
    int hop = 512)

Parameters

nametypedefaultdescription
audioAudioBuffer—The clip.
frameSizeInteger2048Samples per frame, a power of two from 64 to 32768: larger tells close frequencies apart, smaller places changes more exactly in time.
hopInteger512Samples from one frame to the next, at most a quarter of the frame so the frames overlap enough to rebuild the clip.

Returns

SpectrogramAudio Spectrogram

Remarks

Each channel is cut into Hann-windowed frames of Frame Size samples, one every Hop, and each frame becomes the amplitude and phase of every frequency in it. The clip is padded with half a frame of silence at each end, as librosa and SciPy do, so its first and last moments come back too.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Spectral
Package
Audio Processing