Spectral
8 nodes
On this page 8
Draw Short-Time Transform
FunctionDraws a spectrogram: time across, frequency up, and how strong each frequency is at each moment as brightness.
DrawTransform -> Pixel Image
spectrogram: Audio Spectrogram
width: Integer
height: IntegerPixelImage DrawTransform(
AudioSpectrogram spectrogram,
int width = 800,
int height = 300)Parameters
| name | type | default | description |
|---|---|---|---|
| spectrogram | Audio Spectrogram | — | The transform. |
| width | Integer | 800 | Pixels across. |
| height | Integer | 300 | Pixels up. |
Returns
| Picture | Pixel 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
FunctionPuts a clip back together from its frequencies: the inverse short-time Fourier transform.
Inverse(spectrogram: Audio Spectrogram) -> AudioBuffer
AudioBuffer Inverse(AudioSpectrogram spectrogram)
Parameters
| name | type | default | description |
|---|---|---|---|
| spectrogram | Audio Spectrogram | — | The transform, changed or not. |
Returns
| Audio | AudioBuffer |
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
FunctionKeeps only the frequencies from Low up to High.
KeepBand -> Audio Spectrogram
spectrogram: Audio Spectrogram
low: Number
high: NumberAudioSpectrogram KeepBand(
AudioSpectrogram spectrogram,
double low = 300,
double high = 3000)Parameters
| name | type | default | description |
|---|---|---|---|
| spectrogram | Audio Spectrogram | — | The transform. |
| low | Number | 300 | The band's lower edge, in hertz. |
| high | Number | 3000 | The band's upper edge, in hertz; above half the sample rate means everything from the lower edge up. |
Returns
| Spectrogram | Audio 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
FunctionTakes out the frequencies from Low up to High and keeps the rest.
RemoveBand -> Audio Spectrogram
spectrogram: Audio Spectrogram
low: Number
high: NumberAudioSpectrogram RemoveBand(
AudioSpectrogram spectrogram,
double low = 300,
double high = 3000)Parameters
| name | type | default | description |
|---|---|---|---|
| spectrogram | Audio Spectrogram | — | The transform. |
| low | Number | 300 | The band's lower edge, in hertz. |
| high | Number | 3000 | The band's upper edge, in hertz. |
Returns
| Spectrogram | Audio Spectrogram |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Spectral
- Package
- Audio Processing
Separate Harmonic and Percussive
FunctionDivides a clip into what holds steady - notes, chords, sustained voices - and what is brief and broad - drums, clicks, consonants.
SeparateHarmonicPercussive -> (harmonic: AudioBuffer, percussive: AudioBuffer)
audio: AudioBuffer
kernel: Integer
power: Number
frameSize: Integer
hop: Integervoid SeparateHarmonicPercussive(
AudioBuffer audio,
out AudioBuffer harmonic,
out AudioBuffer percussive,
int kernel = 31,
double power = 2,
int frameSize = 2048,
int hop = 512)Parameters
| name | type | default | description |
|---|---|---|---|
| audio | AudioBuffer | — | The clip. |
| kernel | Integer | 31 | How many frames, and frequencies, each median spans; odd. Wider separates more firmly and smears more. |
| power | Number | 2 | How firmly each frequency is given to one side: 1 shares in proportion, 2 is librosa's default, higher approaches all or nothing. |
| frameSize | Integer | 2048 | Samples per frame, as Short-Time Transform takes it. |
| hop | Integer | 512 | Samples between frames, as Short-Time Transform takes it. |
Returns
| harmonic | AudioBuffer |
| percussive | AudioBuffer |
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
FunctionDivides a clip into frequency bands - lows, mids, highs, or as many as the edges make - which add back up to the clip.
SplitIntoBands -> AudioBuffer Array
audio: AudioBuffer
edges: Number Array
frameSize: Integer
hop: IntegerAudioBuffer[] SplitIntoBands(
AudioBuffer audio,
double[] edges,
int frameSize = 2048,
int hop = 512)Parameters
| name | type | default | description |
|---|---|---|---|
| audio | AudioBuffer | — | The clip. |
| edges | Number Array | — | Where one band ends and the next begins, in hertz, rising. |
| frameSize | Integer | 2048 | Samples per frame, as Short-Time Transform takes it. |
| hop | Integer | 512 | Samples between frames, as Short-Time Transform takes it. |
Returns
| Bands | AudioBuffer 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
FunctionThe frequencies a clip holds most of - its constituents, strongest first, each with its level and the note nearest it.
StrongestFrequencies -> Table
audio: AudioBuffer
count: IntegerTable StrongestFrequencies(AudioBuffer audio, int count = 10)
Parameters
| name | type | default | description |
|---|---|---|---|
| audio | AudioBuffer | — | The clip. |
| count | Integer | 10 | How many to list. |
Returns
| Frequencies | Table |
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
FunctionTakes a clip apart into its frequencies over time: the short-time Fourier transform.
Transform -> Audio Spectrogram
audio: AudioBuffer
frameSize: Integer
hop: IntegerAudioSpectrogram Transform(
AudioBuffer audio,
int frameSize = 2048,
int hop = 512)Parameters
| name | type | default | description |
|---|---|---|---|
| audio | AudioBuffer | — | The clip. |
| frameSize | Integer | 2048 | Samples per frame, a power of two from 64 to 32768: larger tells close frequencies apart, smaller places changes more exactly in time. |
| hop | Integer | 512 | Samples from one frame to the next, at most a quarter of the frame so the frames overlap enough to rebuild the clip. |
Returns
| Spectrogram | Audio 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