-
Notifications
You must be signed in to change notification settings - Fork 73
Tutorial 05 Playing sound
Oliver Simmons edited this page Feb 5, 2022
·
1 revision
Playing sound is very easy with the SDL_mixer API.
Download full example: 05-sound.tgz
Just like other additional modules, SDL_mixer must be loaded separately.
local mixer = require("SDL.mixer")
Open the audio device with standard defaults.
assert(mixer.openAudio(44100, SDL.audioFormat.S16, 2, 1024))
Now we can load a chunk and play it to the first channel.
local sound = assert(mixer.loadWAV("gun.wav"))
Play the sound on the first channel.
sound:playChannel(1)
-- Wait for the sound to play
SDL.delay(5000)