Provides 3D audio, pitch control and other stuff.
local res = resource.load("/sounds/sound.wav")
local pos = go.get_position()
self.soundSource = openal.new_source(res)
self.soundSource.x, self.soundSource.y = pos.x, pos.y
self.soundSource.is_looping = true
self.soundSource:play()
Video demonstration: https://www.youtube.com/watch?v=5vgHMGr8cpw
Add OpenAL as a Defold library dependency. Open game.project
and in the dependencies field (in the project section) add:
https://github.com/Lerg/extension-openal/archive/master.zip
Add WAV files as resources (specify resources directory in game.project
).
Disable Defold’s sound system by using sound_null.appmanifest
in the game.project
file under Native Extensions -> App Manifest.
Float, positive. Adjusts the Doppler effect. Higher value makes the effect more noticeable.
Float, positive. Get or set the speed of sound.
Table. The Listener
object. Described below.
Returns a table with information on OpenAL implementation.
Fields:
vendor
version
renderer
extensions
distance_model
- string.
Sets a distance model by which all sound attenuation is calculated.
Available models:
"inverse"
"inverse_clamped"
"linear"
"linear_clamped"
"exponent"
"exponent_clamped"
"none"
resource
- resource that represents a WAV file.
Returns a Source
object.
Creates a sound source object and loads a WAV file into it. The Source
object is described below.
Only mono WAV files will be positioned. Stereo files will be played as if they are at the listener's position.
source
- a Source
object.
Destroys the sound source and frees the memory.
Represents the listener - a point to which all the sounds come to.
Float. X position.
Float. Y position.
Float. Z position.
Float. X component of the listener's velocity.
Float. Y component of the listener's velocity.
Float. Z component of the listener's velocity.
Float. X component of the listener's "at" orientation.
Float. Y component of the listener's "at" orientation.
Float. Z component of the listener's "at" orientation.
Float. X component of the listener's "up" orientation.
Float. Y component of the listener's "up" orientation.
Float. Z component of the listener's "up" orientation.
Represents a sound source.
Float. X position.
Float. Y position.
Float. Z position.
Float. X component of the source's velocity.
Float. Y component of the source's velocity.
Float. Z component of the source's velocity.
Float. X component of the source's direction.
Float. Y component of the source's direction.
Float. Z component of the source's direction.
Float. Pitch adjustment, default is 1.0
.
Float. Gain adjustment, a value from 0
to 1.0
, default is 1.0
.
Float. Used with the Inverse Clamped Distance Model to set the distance where there will no longer be any attenuation of the source.
Float. The rolloff rate for the source, default is 1.0
.
Float. The distance under which the volume for the source would normally drop by half (before being influenced by source.rolloff_factor
or source.max_distance
), default is 50.0
.
Float. The minimum gain for this source.
Float. The maximum gain for this source.
Float. The gain when outside the oriented cone.
Float. The gain when inside the oriented cone.
Float. Outer angle of the sound cone, in degrees, default is 360
.
Boolean. If true
, the sound will be repeated indefinitely, default is false
.
Boolean. If true
, the sound will be positioned relative to the listener, default is false
.
Float. Get or set the sound playback progress in seconds.
String. Get this source's state. Possible values: "initial"
, "playing"
, "paused"
, "stopped"
.
Starts the playback of the sound from this source.
Pauses the playback.
Resets the playback to the start of the sound.
Stops the playback.