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 ¶
- func Peaks(path string, n int) ([]float32, error)
- func PeaksOf(samples []float32, n int) []float32
- type PeakCache
- type Player
- func (pl *Player) Active() bool
- func (pl *Player) Current() string
- func (pl *Player) Left() time.Duration
- func (pl *Player) PlayPreview(id string, data []byte, path string, limit time.Duration) error
- func (pl *Player) PlayStream(id string, s *Stream)
- func (pl *Player) Playing(id string) bool
- func (pl *Player) Progress(id string) float32
- func (pl *Player) Seek(id string, fraction float32)
- func (pl *Player) Stop()
- func (pl *Player) Streaming(id string) bool
- func (pl *Player) Toggle(id, path string) error
- type Stream
- type StreamReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PeakCache ¶
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.
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) Left ¶
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 ¶
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 ¶
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) Stop ¶
func (pl *Player) Stop()
Stop stops, closes the stream (and its file) and forgets the audio.
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 ¶
NewStream returns an empty stream of rate/channels audio keeping at most maxSeconds of it (0: 30 minutes).
func (*Stream) AppendPCM16 ¶
AppendPCM16 adds little-endian 16-bit PCM (the protocol's "pcm16le").
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.
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) 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.