Parameters
Name | Type | Description |
---|---|---|
x | f32 | Input position. |
startFrequency | f32 | Starting frequency. |
endFrequency | f32 | Ending frequency. |
amplitude | f32 | Wave amplitude. |
period | f32 | Period 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 periodlet 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 frequencylet k = (endFrequency - startFrequency) / period;let phase = 2.0 * 3.14159 * (startFrequency * t + 0.5 * k * t * t);// Return the sine wave with the calculated phasereturn sin(phase) * amplitude;}
Showing 5/14 lines