Cosmic Docs

Theme
cs.audio

Audio Playback and Capture

This module provides a cross platform API to decode sound files, capture audio, and play audio. There is support for 3D Spatialization. You can adjust the listener's or sound's position, direction, and velocity. The positions are absolute values in the 3D space.

cs.audio.loadWav data: Uint8Array ) object

Decodes .wav data into a Sound handle.

cs.audio.loadWavFile path: string ) object

Decodes a .wav file into a Sound handle. File path can be absolute or relative to the cwd.

cs.audio.loadMp3 data: Uint8Array ) object

Decodes .mp3 data into a Sound handle.

cs.audio.loadMp3File path: string ) object

Decodes a .mp3 file into a Sound handle. File path can be absolute or relative to the cwd.

cs.audio.loadFlac data: Uint8Array ) object

Decodes .flac data into a Sound handle.

cs.audio.loadFlacFile path: string ) object

Decodes a .flac file into a Sound handle. File path can be absolute or relative to the cwd.

cs.audio.loadOgg data: Uint8Array ) object

Decodes .ogg data into a Sound handle.

cs.audio.loadOggFile path: string ) object

Decodes a .ogg file into a Sound handle. File path can be absolute or relative to the cwd.

cs.audio.load data: Uint8Array ) object

Attempt to decode wav, mp3, flac, or ogg data into a Sound handle.

cs.audio.loadFile path: string ) object

Attempt to decode wav, mp3, flac, or ogg file into a Sound handle. File path can be absolute or relative to the cwd.

cs.audio.setListenerPos : number, : number, : number )

Sets the listener's position in 3D space.

cs.audio.getListenerPos (  ) .stdx.math.math.Vec3

Returns the listener's position in 3D space.

cs.audio.setListenerDir x: number, y: number, z: number )

Sets the listener's forward direction in 3D space. See also setListenerUpDir.

cs.audio.getListenerDir (  ) .stdx.math.math.Vec3

Returns the listener's forward direction in 3D space.

cs.audio.setListenerUpDir x: number, y: number, z: number )

Sets the listener's up direction in 3D space.

cs.audio.getListenerUpDir (  ) .stdx.math.math.Vec3

Returns the listener's up direction in 3D space.

cs.audio.setListenerVel x: number, y: number, z: number )

Sets the listener's velocity in 3D space. This is for the doppler effect.

cs.audio.getListenerVel (  ) .stdx.math.math.Vec3

Returns the listener's velocity in 3D space.

Plays the sound. This won't return until the sound is done playing.

Starts playing the sound in the background. Returns immediately. Playing the sound while it's already playing will rewind to the start and begin playback.

Returns whether the sound is playing or looping in the background.

Starts looping the sound in the background.

Returns whether the sound is looping in the background.

Pauses the playback.

Resumes the playback from the current cursor position. If the cursor is at the end, it will rewind to the start and begin playback.

Stops the playback and rewinds to the start.

cs.audio.SoundsetVolume volume: number )

Sets the volume in a positive linear scale. Volume at 0 is muted. 1 is the default value.

Returns the volume in a positive linear scale.

cs.audio.SoundsetGain gain: number )

Sets the volume with gain in decibels.

cs.audio.SoundgetGain (  ) number

Gets the gain in decibels.

cs.audio.SoundsetPitch pitch: number )

Sets the pitch. A higher value results in a higher pitch and must be greater than 0. Default value is 1.

Returns the current pitch.

cs.audio.SoundsetPan pan: number )

Sets the stereo pan. Default value is 0. Set to -1 to shift the sound to the left and +1 to shift the sound to the right.

cs.audio.SoundgetPan (  ) number

Returns the current stereo pan.

Returns the length of the sound in pcm frames. Unsupported for ogg.

Returns the length of the sound in milliseconds. Unsupported for ogg.

Returns the current playback position in pcm frames. Unsupported for ogg.

cs.audio.SoundseekToPcmFrame frameIndex: BigInt )

Seeks to playback position in pcm frames.

cs.audio.SoundsetPosition x: number, y: number, z: number )

Sets the sound's position in 3D space.

cs.audio.SoundgetPosition (  ) .stdx.math.math.Vec3

Returns the sound's position in 3D space.

cs.audio.SoundsetDirection x: number, y: number, z: number )

Sets the sound's direction in 3D space.

cs.audio.SoundgetDirection (  ) .stdx.math.math.Vec3

Returns the sound's direction in 3D space.

cs.audio.SoundsetVelocity x: number, y: number, z: number )

Sets the sound's velocity in 3D space. This is for the doppler effect.

cs.audio.SoundgetVelocity (  ) .stdx.math.math.Vec3

Returns the sound's velocity in 3D space.