chirpWave

a chirp wave with linearly changing frequency.

110 total functionsUpdated: 30/07/2026

chirpWave

a chirp wave with linearly changing frequency.

Parameters

NameTypeDescription
xf32Input position.
startFrequencyf32Starting frequency.
endFrequencyf32Ending frequency.
amplitudef32Wave amplitude.
periodf32Period over which frequency changes.

Returns

f32wave value.

WGSL Code

fn chirpWave(x: f32, startFrequency: f32, endFrequency: f32, amplitude: f32, period: f32) -> f32 {
  // Calculate the time within the current period
  let t = fract(x / period);
  
  // Calculate the frequency at the current time (linear interpolation)
  let freq = mix(startFrequency, endFrequency, t);
  
  // Calculate the phase which increases with changing frequency
  let k = (endFrequency - startFrequency) / period;
  let phase = 2.0 * 3.14159 * (startFrequency * t + 0.5 * k * t * t);
  
  // Return the sine wave with the calculated phase
  return sin(phase) * amplitude;
}

About wgsl-fns

A JavaScript library providing WGSL utility functions as strings for WebGPU shader development. Includes mathematical utilities, noise generation, signed distance fields, and color manipulation functions.

Install:npm install wgsl-fns
Import:import { chirpWave, getFns } from 'wgsl-fns'
Usage:getFns(['chirpWave'])