audio

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package audio plays sounds at 3D locations. The expected usage is to initialize the audio system and load sound data. Then play sounds that are close enough to the sound listener to be audible.

Package audio is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context added in v0.20.0

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

Context is used to initialize and play audio. It works with an audioAPI to allow different audio players implementations.

func New

func New() *Context

New provides the default audio implementation.

func (*Context) DisableAudio added in v0.20.0

func (c *Context) DisableAudio()

DisableAudio is used to turn off the audio system when there are no supported audio drivers.

func (*Context) Dispose added in v0.20.0

func (c *Context) Dispose()

Closes and the audio layer, releasing any audio resources.

func (*Context) DropSound added in v0.20.0

func (c *Context) DropSound(sound, buff uint64)

DropSound disposes the audio resources allocated with LoadSound. Must be called on a valid audio context, ie: before Dispose()

func (*Context) Init added in v0.20.0

func (c *Context) Init() error

Init the audio context state. Must be called once on startup.

func (*Context) LoadSound added in v0.20.0

func (c *Context) LoadSound(sound, buff *uint64, d *Data) error

LoadSound copies the sound data to the sound card and returns references that can be used to play or dispose the sound.

sound : updated reference to the bound sound.
buff  : updated reference to the sound data buffer.
d     : sound data bytes and settings to be bound.

func (*Context) PlaceListener added in v0.20.0

func (c *Context) PlaceListener(x, y, z float64)

PlaceListener control sounds by setting the x,y,z locations for the listener. While there is only ever one listener, there can be many sounds.

func (*Context) PlaySound added in v0.20.0

func (c *Context) PlaySound(sound uint64, x, y, z float64)

Play the given sound.

func (*Context) SetGain added in v0.20.0

func (c *Context) SetGain(gain float64)

Volume control: valid values are 0->1.

type Data

type Data struct {
	Name       string // Unique sound name.
	AudioData  []byte // The raw audio data.
	Channels   uint16 // Number of audio channels.
	SampleBits uint16 // 8 bits = 8, 16 bits = 16, etc.
	Frequency  uint32 // 8000, 44100, etc.
	DataSize   uint32 // Audio data size: total file size minus header size.
}

Data is a shared audio resource that is used to load sound data onto a sound card.

func (*Data) Set

func (d *Data) Set(channels, sampleBits uint16, frequency, dataSize uint32, data []byte)

Set is a convenience method that populates sound data with the given information. It attempts to reuse the existing sound data buffer.

type Loader added in v0.20.0

type Loader interface {
	LoadSound(sound, buff *uint64, d *Data) error
}

Loader provides the interface for uploading sound data to the audio device.

Jump to

Keyboard shortcuts

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