sound

package
v0.0.0-...-1f00af5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sound manages music and sound effects.

Index

Constants

This section is empty.

Variables

View Source
var (
	// If enabled is false, all sound functions are no-ops.
	Enabled bool

	// Root folder on disk where sound and music files should live.
	SoundRoot = filepath.Join("rtp", "sfx")
	MusicRoot = filepath.Join("rtp", "music")
)

Package globals.

View Source
var (

	// Supported file extensions, in preference order.
	SupportedSoundExtensions = []string{
		".wav",
		".ogg",
		".mp3",
	}
)

SDL engine globals.

Functions

func LoadMusic

func LoadMusic(filename string) audio.Playable

LoadMusic loads filename from the MusicRoot into the global music cache. If the music is already loaded, does nothing.

func LoadSound

func LoadSound(filename string) audio.Playable

LoadSound loads filename from the SoundRoot into the global SFX cache. If the sound is already loaded, does nothing.

func PlaySound

func PlaySound(filename string)

PlaySound plays the named sound. It will de-duplicate if the same sound is already playing.

func PreloadAll

func PreloadAll()

PreloadAll looks in the SoundRoot and MusicRoot folders and preloads all supported files into the caches.

func ResolveFilename

func ResolveFilename(filename string) (string, error)

ResolveFilename resolves the filename to a sound file on disk.

Ogg has been found more reliable than MP3 for cross-platform distribution. A doodad might request a "sound.mp3" but the filename on disk is actually "sound.ogg" and this function will return the latter, if "sound.mp3" does not exist.

If the exact filename does exist, it is returned; otherwise a preference order of WAV > OGG > MP3 will be tried and returned if those versions exist.

Returns the full path on disk (e.g. "rtp/sfx/sound.ogg")

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL