Documentation ¶
Overview ¶
Package audio provides utilities for playing or writing audio streams to OS consumers
Index ¶
- Constants
- Variables
- func BatchLoad(baseFolder string) error
- func BlankBatchLoad(baseFolder string) error
- func FadeIn(dur time.Duration, in pcm.Reader) pcm.Reader
- func FadeOut(dur time.Duration, in pcm.Reader) pcm.Reader
- func Get(file string) (pcm.Reader, error)
- func Init(d Driver) error
- func InitDefault() error
- func Load(file string) (pcm.Reader, error)
- func LoopReader(r pcm.Reader) pcm.Reader
- func MustNewWriter(f pcm.Format) pcm.Writer
- func NewWriter(f pcm.Format) (pcm.Writer, error)
- func Play(ctx context.Context, src pcm.Reader, options ...PlayOption) error
- func ReadAtLeast(r pcm.Reader, buf []byte, min int) (n int, err error)
- func ReadFull(r pcm.Reader, buf []byte) (n int, err error)
- type BytesReader
- type Cache
- type Driver
- type LoopingReader
- type PlayOption
- type PlayOptions
Constants ¶
const WriterBufferLengthInSeconds float64 = .5
WriterBufferLengthInSeconds defines how much data os-level writers provided by this package will rotate through in a theoretical circular buffer.
Variables ¶
var DefaultCache = NewCache()
DefaultCache is the receiver for package level loading operations.
var ErrMismatchedPCMFormat = fmt.Errorf("source and destination have differing PCM formats")
ErrMismatchedPCMFormat will be returned by operations streaming from Readers to Writers where the PCM formats of those Readers and Writers are not equivalent.
var SkipDevicesContaining string = "HDMI"
TODO: do other drivers need this? Can we pick devices more intelligently?
Functions ¶
func BatchLoad ¶
BatchLoad attempts to load all audio files within a given directory should their file ending match a registered audio file parser
func BlankBatchLoad ¶
BlankBatchLoad acts like BatchLoad, but replaces all loaded assets with empty audio constructs. This is intended to reduce start-up times in development.
func InitDefault ¶
func InitDefault() error
InitDefault calls Init with the following value by OS: windows: DriverDirectSound linux,osx: DriverPulse
func LoopReader ¶
LoopReader will cache read bytes as they are read and resend them after the reader returns EOF.
func MustNewWriter ¶
MustNewWriter calls NewWriter and panics if an error is returned.
func NewWriter ¶
NewWriter returns a writer which can accept audio streamed matching the given format
func Play ¶
Play will copy data from the provided src to the provided dst until ctx is cancelled. This copy is not constant. The copy will occur in two phases: first, an initial population of the writer to give distance between the read cursor and write cursor; immediately upon this write, the writer should begin playback. Following this setup, a sub-second amount of data will streamed from src to dst after waiting that same duration. These wait times can be configured via PlayOptions.
func ReadAtLeast ¶
ReadAtLeast acts like io.ReadAtLeast with a pcm Reader. It will read until at least min bytes have been read into the provided buffer.
Types ¶
type BytesReader ¶
A BytesReader acts like a bytes.Buffer for converting raw []bytes into pcm Readers.
func ReadAll ¶
func ReadAll(r pcm.Reader) *BytesReader
ReadAll will read all of the content within a reader and convert it into a BytesReader. Use carefully; use on a LoopingReader or reader which generates its data (e.g. synth types) will likely read until OOM.
func (*BytesReader) Copy ¶
func (b *BytesReader) Copy() *BytesReader
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a simple audio data cache
type Driver ¶
type Driver int
A Driver defines the underlying interface that should be used for initializing PCM audio writers.
type LoopingReader ¶
A LoopingReader will read from Reader continually, even after it has been fully consumed. The data read from the reader will be cached after read within the LoopingReader structure, potentially inflating memory if provided a large stream.
type PlayOption ¶
type PlayOption func(*PlayOptions)
A PlayOption sets some value on a PlayOptions struct.
type PlayOptions ¶
type PlayOptions struct { // If FadeOutOnStop is non-zero, when this play is stopped early it will fade out for this duration. FadeOutOnStop time.Duration // If Destination is not provided, Play will create a new writer which will be // closed after Play is complete. Destination pcm.Writer // The span of data that should be copied from reader to writer // at a time. If too low, may lose accuracy on windows. If too high, // may require manual resets when changing audio sources. // Defaults to 50 Milliseconds. CopyIncrement time.Duration // How many increments should make up the time between our read and write // cursors-- i.e. the audio will be playing at X and we will be writing to // X + ChaseIncrements * CopyIncrement. // This must be at least 2 to avoid the read and write buffers clipping. // Defaults to 2. ChaseIncrements int // If AllowMismatchedFormats is false, Play will error when a reader's PCM format // disagrees with a writer's expected PCM format. Defaults to false. AllowMismatchedFormats bool ClearBufferOnStop bool }
PlayOptions define ways to configure how playback of some audio proceeds
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package format provides audio file and format parsers
|
Package format provides audio file and format parsers |
ceol
Package ceol provides functionality to handle .ceol files and .ceol encoded data (Bosca Ceoil files).
|
Package ceol provides functionality to handle .ceol files and .ceol encoded data (Bosca Ceoil files). |
dls
Package dls contains data structures for DLS (.dls) file types.
|
Package dls contains data structures for DLS (.dls) file types. |
flac
Package flac provides functionality to handle .flac files and .flac encoded data.
|
Package flac provides functionality to handle .flac files and .flac encoded data. |
mp3
Package mp3 provides functionality to handle .mp3 files and .mp3 encoded data.
|
Package mp3 provides functionality to handle .mp3 files and .mp3 encoded data. |
riff
Package riff reads and umarshalls RIFF files.
|
Package riff reads and umarshalls RIFF files. |
wav
Package wav provides functionality to handle .wav files and .wav encoded data.
|
Package wav provides functionality to handle .wav files and .wav encoded data. |
internal
|
|
Package pcm provides a interface for interacting with PCM audio streams
|
Package pcm provides a interface for interacting with PCM audio streams |
Package synth provides functions and types to support waveform synthesis.
|
Package synth provides functions and types to support waveform synthesis. |