sound

package module
v0.0.0-...-223702d Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 3 Imported by: 0

README

Ebitengine Sound Library

Overview

A small library that makes playing sounds and music with Ebitengine easier. This package is intended to be used in combination with ebitengine-resource.

Key features:

  • Playlist-style player
  • Sound queue
  • Per-group volume control (music/sfx/voice/etc.)
  • Tightly integrated with a resource manager library
  • Repetitive Play() caching

Dependencies:

Installation

go get github.com/quasilyte/ebitengine-sound

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PlayOptions

type PlayOptions struct {
	Volume float64
}

type Playlist

type Playlist struct {

	// SelectFunc implements the next track selection.
	//
	// By default, this field is set to a function
	// that selects the next track and wraps to track 0.
	// Another example of a selection strategy would be
	// a random selection or ping-pong style wrapping.
	//
	// When the first track needs to be selected,
	// the currentIndex argument would be -1 as
	// no tracks are being played at that moment.
	//
	// Use [Playlist.Len] to determine the appropriate
	// track index bound.
	SelectFunc func(currentIndex int) int
	// contains filtered or unexported fields
}

func NewPlaylist

func NewPlaylist(sys *System) *Playlist

func (*Playlist) Add

func (pl *Playlist) Add(id resource.AudioID)

func (*Playlist) AddWithOptions

func (pl *Playlist) AddWithOptions(id resource.AudioID, opts PlayOptions)

func (*Playlist) GetSilenceDuration

func (pl *Playlist) GetSilenceDuration() float64

func (*Playlist) IsPaused

func (pl *Playlist) IsPaused() bool

func (*Playlist) Len

func (pl *Playlist) Len() int

func (*Playlist) SetPaused

func (pl *Playlist) SetPaused(paused bool)

func (*Playlist) SetSilenceDuration

func (pl *Playlist) SetSilenceDuration(seconds float64)

func (*Playlist) Update

func (pl *Playlist) Update(delta float64)

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(sys *System) *Queue

func (*Queue) PlaySound

func (q *Queue) PlaySound(id resource.AudioID)

PlaySound is a shorthand for [PlaySoundWithOptions](id, {Volume: 1.0}).

func (*Queue) PlaySoundWithOptions

func (q *Queue) PlaySoundWithOptions(id resource.AudioID, opts PlayOptions)

PlaySoundWithOptions adds the sound to the queue. If the queue is currently empty, it will start playing right away. Otherwise, it will be played after all other queued sound have played.

func (*Queue) Reset

func (q *Queue) Reset()

Reset stops the currently playing sounds and clears all queued sounds.

func (*Queue) Update

func (q *Queue) Update()

type System

type System struct {
	// contains filtered or unexported fields
}

func (*System) GetContext

func (sys *System) GetContext() *audio.Context

func (*System) GetGlobalVolume

func (sys *System) GetGlobalVolume() float64

GetGlobalVolume reports the current global volume multiplier.

func (*System) GetGroupVolume

func (sys *System) GetGroupVolume(groupID uint) float64

GetGroupVolume reports the current volume multiplier for the given group. The max groupID is 7 (therefore, there could be 8 groups in total). Use [SetGroupVolume] to adjust the group's volume multiplier.

func (*System) Init

func (sys *System) Init(a *audio.Context, l *resource.Loader)

func (*System) PlaySound

func (sys *System) PlaySound(id resource.AudioID) resource.Audio

PlaySound is a shorthand for [PlaySoundWithOptions](id, {Volume: 1.0}).

The returned Audio object can be ignored unless you want to check it's player field for a readonly operation like IsPlaying.

func (*System) PlaySoundWithOptions

func (sys *System) PlaySoundWithOptions(id resource.AudioID, opts PlayOptions) resource.Audio

func (*System) SetGlobalVolume

func (sys *System) SetGlobalVolume(volume float64)

SetGlobalVolume assigns an extra volume multiplier. It's used when computing the effective volume level. Setting it to 0.5 would make all sounds two times quiter.

Imagine an average game that has separate volume controls (sfx, voice, music) plus "master volume" that would be applied on top of that. The global volume level is that multiplier.

func (*System) SetGroupVolume

func (sys *System) SetGroupVolume(groupID uint, multiplier float64)

SetGroupVolume assigns the volume multiplier for the given group. The max groupID is 7 (therefore, there could be 8 groups in total). Use [GetGroupVolume] to get the group's current volume multiplier.

A sound multiplier of 0 effectively mutes the group.

func (*System) Update

func (sys *System) Update()

Update adjusts the audio system state for the next tick of the game.

It needs to be called somewhere near the beginning of [ebiten.Game.Update] method.

Jump to

Keyboard shortcuts

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