| name | love-sound |
| description | This module is responsible for decoding sound files. It can't play the sounds, see love.audio for that. Use this skill when working with sound operations, audio decoding, sound data manipulation, or any sound-related operations in LÖVE games. |
| license | MIT |
| metadata | {"author":"Ron Dekker <rondekker.nl>"} |
When to use this skill
This module is responsible for decoding sound files. It can't play the sounds, see love.audio for that. Use this skill when working with sound operations, audio decoding, sound data manipulation, or any sound-related operations in LÖVE games.
Common use cases
- Decoding sound files and formats
- Managing sound data and audio buffers
- Performing sound transformations and effects
- Working with compressed audio formats
- Handling sound metadata and properties
Functions
love.sound.newDecoder - Attempts to find a decoder for the encoded sound data in the specified file.
love.sound.newDecoder(file: File, buffer: number) -> decoder: Decoder: No description
love.sound.newDecoder(filename: string, buffer: number) -> decoder: Decoder: No description
love.sound.newSoundData - Creates new SoundData from a filepath, File, or Decoder. It's also possible to create SoundData with a custom sample rate, channel and bit depth. The sound data will be decoded to the memory in a raw format. It is recommended to create only short sounds like effects, as a 3 minute song uses 30 MB of memory this way.
love.sound.newSoundData(filename: string) -> soundData: SoundData: No description
love.sound.newSoundData(file: File) -> soundData: SoundData: No description
love.sound.newSoundData(decoder: Decoder) -> soundData: SoundData: No description
love.sound.newSoundData(samples: number, rate: number, bits: number, channels: number) -> soundData: SoundData: No description
Types
Examples
Decoding sound data
local soundData = love.sound.newSoundData("effect.wav")
local source = love.audio.newSource(soundData)
love.audio.play(source)
Sound data manipulation
local sampleRate = 44100
local bitDepth = 16
local channels = 1
local duration = 1.0
local soundData = love.sound.newSoundData(
sampleRate * duration,
sampleRate,
bitDepth,
channels
)
for i = 0, soundData:getSampleCount() - 1 do
local time = i / sampleRate
local value = math.sin(time * 440 * 2 * math.pi)
soundData:setSample(i, value)
end
local source = love.audio.newSource(soundData)
love.audio.play(source)
Best practices
- Use appropriate sound formats for different use cases
- Consider memory usage when working with large sound files
- Handle sound decoding errors gracefully
- Test sound formats on target platforms
- Be mindful of performance with real-time sound processing
Platform compatibility
- Desktop (Windows, macOS, Linux): Full sound support
- Mobile (iOS, Android): Full support with some format limitations
- Web: Good support but some formats may not be available