The sound object represents a sound or an audio track. It is in the 16-bit stereo format, and can be played back in the object's window.
Its syntax can be one of:
sound <name> = <initializer>; sound <name> = <initializer> : <modifier1, modifier2, ...>;
The available modifiers and initializers are listed below.
The immediate waveform and spectrum of each sound is accessible in GLSL code that follows it via these functions:
- vec2 shadron_Waveform(sound s, float timeOffset) – returns the Y position of the left and right channels of the waveform of sound s at the current time plus timeOffset. The offset must be between -1 and 1, and this range corresponds to 512 sound samples. The output is also between -1 and 1.
- vec2 shadron_Spectrum(sound s, float frequency) – returns the intensity of a given frequency in the spectrum of the left and right channels of sound s at the current time. The frequency argument must be between 0 and 1, and represents the linear range from 0 Hz up to the Nyquist frequency SAMPLE_RATE / 2. The output is also between 0 and 1.
You can specify any subset of the following sound modifiers:
- hidden(<true / false>) – do not create a window for the sound and only make it available for sampling and export
- full_range(<true / false>) – if enabled, the sound's waveform and spectrum will be available for sampling in full floating point precision
- repeat(<true / false>) – specifies whether to loop the sound
- window(<function name>)
– specifies a windowing function to be used when computing the sound's spectrum. The possible values are:
- rectangular (default)
Initializes the sound as a file input. A file name can be supplied as an argument, which will be loaded. The supported formats are WAV, OGG, and FLAC. A different file may be loaded at any later point.
sound MySoundFile = file("tone.wav");
Initializes the sound as the output of a GLSL shader, which generates audio procedurally.
Its first argument is a GLSL function that will be evaluated for each sample. The function must have one input float parameter, which is the time from the beginning of the audio track, in seconds. Its return type must be either float for mono, or vec2 for stereo audio. The value itself is the position of the curve at that time, in the range (-1, +1).
The second argument specifies the sample rate (number of samples per second). This has to be a positive integer and it is strongly advised to use a standard value, such as 44100.
sound MyProceduralSound = glsl(getWavePosition, 44100);