audio

package
v0.5.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audio is AudioSmith's sound handling in Go: waveform peaks (with a disk cache) and the streaming player today; the timeline mixer, peaks pyramid, loudness and QC analysis later (M1/M4).

Imports: nothing internal. It wraps github.com/egoist/mygo/audio.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Peaks

func Peaks(path string, n int) ([]float32, error)

Peaks reads an audio file and returns n peak magnitudes (0–1), one per equal slice of the file, for drawing its waveform. It decodes the whole file, streaming when the decoder knows its length: call it off the UI thread, or use a PeakCache.

func PeaksOf

func PeaksOf(samples []float32, n int) []float32

PeaksOf reduces per-frame magnitudes to n peaks normalized to the loudest.

Types

type PeakCache

type PeakCache struct {
	Dir string
	N   int // peaks per waveform
}

PeakCache keeps waveform peaks on disk, one file per audio id (<Dir>/<id>.f32: N little-endian float32), so a waveform is decoded once. Audio is assumed immutable under its id. Safe for concurrent use; its methods do I/O, so call them off the UI thread.

func (PeakCache) Get

func (c PeakCache) Get(id, audioPath string) ([]float32, error)

Get returns id's peaks from the cache, or computes them from audioPath and stores them. Silent or empty audio gives an empty, non-nil slice.

func (PeakCache) Remove

func (c PeakCache) Remove(id string) error

Remove deletes id's cached peaks, if any.

type Player

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

Player plays one take at a time, identified by an id, streaming it from its file (myaudio.OpenStream decodes about a second ahead), so long audio plays without being read into memory. Loading opens the file and reads its header only. Use it from the UI thread (not goroutine-safe).

func (*Player) Active

func (pl *Player) Active() bool

Active reports whether anything is playing.

func (*Player) Current

func (pl *Player) Current() string

Current is the id of the loaded audio, playing or paused; "" when none.

func (*Player) Left

func (pl *Player) Left() time.Duration

Left is when to look whether the audio playing ended: soon after the time it has left, within leftMax, or leftStream for a stream still growing; 0 when nothing plays.

func (*Player) PlayPreview

func (pl *Player) PlayPreview(id string, data []byte, path string, limit time.Duration) error

PlayPreview plays a short preview as id's audio, in a format MyGo's audio decodes (the app registers Ogg Vorbis), from data (a bundled clip) or, when data is nil, from the file at path, at most limit of it (0: all), fading out where it cuts. It replaces what was loaded; Stop ends it.

func (*Player) PlayStream

func (pl *Player) PlayStream(id string, s *Stream)

PlayStream plays s, audio that grows while it plays, as id's: the preview of a take still rendering. Stop (or another Toggle or PlayStream) closes it.

func (*Player) Playing

func (pl *Player) Playing(id string) bool

Playing reports whether id is playing.

func (*Player) Progress

func (pl *Player) Progress(id string) float32

Progress is where id is, from 0 to 1 (0 when it is not loaded).

func (*Player) Seek

func (pl *Player) Seek(id string, fraction float32)

Seek moves id to fraction (0–1) of its length, if it is loaded.

func (*Player) Stop

func (pl *Player) Stop()

Stop stops, closes the stream (and its file) and forgets the audio.

func (*Player) Streaming

func (pl *Player) Streaming(id string) bool

Streaming reports whether id's audio is a preview stream.

func (*Player) Toggle

func (pl *Player) Toggle(id, path string) error

Toggle plays id's audio at path, loading it first, or pauses it while it plays. A preview stream of id (PlayStream) that is paused or ended gives way to the file, which can seek.

type Stream

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

Stream is audio that grows while it plays: the Studio's preview of a take still rendering. The render's chunks are appended as they arrive (Append, AppendPCM16) and Finish marks the end. Readers (NewReader) are mygo/audio Decoders over it, each with its own position: Read waits for audio that has not arrived yet (the player plays silence meanwhile) and ends after Finish. Samples are kept as 16-bit, up to a cap; audio past the cap is dropped (the take's file has it all).

Every method may be called from any goroutine.

func NewStream

func NewStream(rate, channels int, maxSeconds float64) *Stream

NewStream returns an empty stream of rate/channels audio keeping at most maxSeconds of it (0: 30 minutes).

func (*Stream) Append

func (s *Stream) Append(samples []float32)

Append adds interleaved float samples (whole frames).

func (*Stream) AppendPCM16

func (s *Stream) AppendPCM16(data []byte)

AppendPCM16 adds little-endian 16-bit PCM (the protocol's "pcm16le").

func (*Stream) Close

func (s *Stream) Close() error

Close ends the stream for good (an abandoned render), waking readers.

func (*Stream) Done

func (s *Stream) Done() bool

Done reports whether Finish was called.

func (*Stream) Finish

func (s *Stream) Finish()

Finish marks the end: readers return io.EOF once they read everything.

func (*Stream) NewReader

func (s *Stream) NewReader() *StreamReader

NewReader returns a decoder of the stream from its start.

func (*Stream) Seconds

func (s *Stream) Seconds() float64

Seconds is how much audio the stream has.

type StreamReader

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

StreamReader reads a Stream: a mygo/audio Decoder. Closing it (the player does when it closes) wakes a Read that waits, and leaves the stream to other readers.

func (*StreamReader) Channels

func (r *StreamReader) Channels() int

Channels implements mygo/audio.Decoder.

func (*StreamReader) Close

func (r *StreamReader) Close() error

Close implements io.Closer.

func (*StreamReader) Len

func (r *StreamReader) Len() int64

Len implements mygo/audio.Decoder: unknown (-1) until the stream is finished.

func (*StreamReader) Read

func (r *StreamReader) Read(buf []float32) (int, error)

Read implements mygo/audio.Decoder: it waits until there is audio to read, the stream is finished, or either is closed.

func (*StreamReader) SampleRate

func (r *StreamReader) SampleRate() int

SampleRate implements mygo/audio.Decoder.

func (*StreamReader) SetPosition

func (r *StreamReader) SetPosition(frame int64) error

SetPosition implements mygo/audio.Decoder; a frame past the audio that arrived so far moves to its end.

Jump to

Keyboard shortcuts

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