Skip to content

AudioWaveformRenderer

ClassAudioToolAudioTool.Editor
public class AudioWaveformRenderer

Renders audio waveforms to textures for visualization in the editor. Stateless for textures - caller owns and passes texture references.

RenderWaveform(ref Texture2D, AudioClip, int, int)

Section titled “RenderWaveform(ref Texture2D, AudioClip, int, int)”
public bool RenderWaveform(ref Texture2D texture, AudioClip clip, int width, int height)

Renders a waveform from an AudioClip to a texture.

Parameters

NameTypeDescription
textureUnityEngine.Texture2DReference to texture to render into (will be created/resized if needed)
clipUnityEngine.AudioClipThe audio clip to visualize
widthSystem.Int32Width of the output texture
heightSystem.Int32Height of the output texture

Returns

System.Boolean: True if successful

RenderWaveform(ref Texture2D, float[], int, int, int)

Section titled “RenderWaveform(ref Texture2D, float[], int, int, int)”
public bool RenderWaveform(ref Texture2D texture, float[] samples, int channels, int width, int height)

Renders a waveform from raw samples to a texture.

Parameters

NameTypeDescription
textureUnityEngine.Texture2DReference to texture to render into (will be created/resized if needed)
samplesSystem.Single[]Interleaved audio samples
channelsSystem.Int32Number of audio channels
widthSystem.Int32Width of the output texture
heightSystem.Int32Height of the output texture

Returns

System.Boolean: True if successful

CreateOverlay(ref Texture2D, int, int, float, float, float, float, float, float, float, AnimationCurve, AnimationCurve)

Section titled “CreateOverlay(ref Texture2D, int, int, float, float, float, float, float, float, float, AnimationCurve, AnimationCurve)”
public bool CreateOverlay(ref Texture2D texture, int width, int height, float selectionStart, float selectionEnd, float playheadPosition = -1, float silenceStart = 0, float silenceEnd = 1, float fadeInEnd = -1, float fadeOutStart = -1, AnimationCurve fadeInCurve = null, AnimationCurve fadeOutCurve = null)

Creates an overlay texture with selection and playhead.

Parameters

NameTypeDescription
textureUnityEngine.Texture2DReference to texture to render into (will be created/resized if needed)
widthSystem.Int32Width of the overlay
heightSystem.Int32Height of the overlay
selectionStartSystem.SingleNormalized start position of selection (0-1)
selectionEndSystem.SingleNormalized end position of selection (0-1)
playheadPositionSystem.SingleNormalized playhead position (0-1), negative to hide
silenceStartSystem.SingleNormalized start of detected silence region (0-1)
silenceEndSystem.SingleNormalized end of detected silence region (0-1)
fadeInEndSystem.SingleNormalized position where fade-in ends (-1 to disable)
fadeOutStartSystem.SingleNormalized position where fade-out starts (-1 to disable)
fadeInCurveUnityEngine.AnimationCurveAnimationCurve for fade-in visualization (null to skip)
fadeOutCurveUnityEngine.AnimationCurveAnimationCurve for fade-out visualization (null to skip)

Returns

System.Boolean: True if successful

public int NormalizedToSample(float normalized, int totalSamples)

Converts a normalized position (0-1) to a sample index.

Parameters

NameTypeDescription
normalizedSystem.SinglePosition across the waveform; values outside 0 to 1 are clamped.
totalSamplesSystem.Int32Number of per-channel sample frames represented by the waveform.

Returns

System.Int32: The nearest zero-based sample-frame index.

public float SampleToNormalized(int sample, int totalSamples)

Converts a sample index to a normalized position (0-1).

Parameters

NameTypeDescription
sampleSystem.Int32Zero-based sample-frame index.
totalSamplesSystem.Int32Number of per-channel sample frames represented by the waveform.

Returns

System.Single: A clamped position from 0 at the start to 1 at the end.

public float PixelToNormalized(int pixelX, int width)

Converts a pixel X coordinate to a normalized position.

Parameters

NameTypeDescription
pixelXSystem.Int32Horizontal pixel coordinate relative to the waveform texture.
widthSystem.Int32Waveform texture width in pixels.

Returns

System.Single: A clamped position from 0 at the left edge to 1 at the right edge.

public int NormalizedToPixel(float normalized, int width)

Converts a normalized position to a pixel X coordinate.

Parameters

NameTypeDescription
normalizedSystem.SinglePosition across the waveform; values outside 0 to 1 are clamped.
widthSystem.Int32Waveform texture width in pixels.

Returns

System.Int32: The nearest horizontal pixel coordinate.

public AudioWaveformRenderer()

public Color BackgroundColor { get; set; }

Gets or sets the background color of the waveform.

Returns

UnityEngine.Color

public Color WaveformColor { get; set; }

Gets or sets the waveform color.

Returns

UnityEngine.Color

public Color SelectionColor { get; set; }

Gets or sets the selection highlight color.

Returns

UnityEngine.Color