sound: zikichombo.org/sound Index | Files | Directories

package sound

import "zikichombo.org/sound"

Package sound provides a core library for working with audio.

Package sound is part of http://zikichombo.org

Index

Package Files

cae.go closer.go doc.go duplex.go form.go pipe.go seek.go sink.go source.go

Variables

var ErrChannelAlignment = errors.New("Channels misaligned")

ErrChannelAlignment is returned by sources and sinks when the input/output slices aren't sized correctly with respect to the number of channels in the sink/source. More concretely this error is returned when:

Sink.Send(d) is called and len(d) % Sink.Channels() != 0

Source.Receive(d) is called and len(d) % Source.Channels() != 0

Because the buffers d don't contain a number of samples representing one sample for all channels for all represented points in time.

var ErrFrameAlignment = errors.New("duplex frames misaligned.")

See Duplex.SendReceive

func Duration Uses

func Duration(s Seeker) time.Duration

Duration takes a Seeker and returns its total duration in time.

func Pipe Uses

func Pipe(v Form) (Source, Sink)

Pipe creates a pair of Source and Sink such that writes to the sink are passed through to reads from the Source.

The returned source, sink are safe for use in multiple goroutines.

Pipe is the dual of zikichombo.org/sound/ops.Copy.

func SeekDur Uses

func SeekDur(s Seeker, d time.Duration) error

SeekDur takes a Seeker and seeks to the greatest frame not exceeding d time.

SeekDur returns the error given by the call to s.Seek() implementing the seek.

func When Uses

func When(s Seeker) time.Duration

When takes a Seeker and returns its position in terms of time.

type Closer Uses

type Closer interface {
    Close() error
}

type Duplex Uses

type Duplex interface {
    // NB: channels returns InChannels() + OutChannels()
    Form
    Closer
    InChannels() int
    OutChannels() int

    // SendReceive on a duplex connection will play out
    // and capture to in.
    //
    // SendReceive returns a ErrChannelAlignment if
    // len(in) is not a multiple of InChannels() and also
    // if len(out) is not a multiple of OutChannels().
    //
    // SendReceive returns a ErrFrameAlignment if
    // the number of frames in out is not equal to the number
    // of frames in in.
    //
    // SendReceive returns the number of frames of input, n.
    // n == 0 iff error != nil
    // if n < len(in)/InChannels() then only the first
    // n frames of out are sent and subsequent calls to
    // SendReceive will return 0, io.EOF.
    //
    SendReceive(out, in []float64) (int, error)
}

Duplex is an interface for full duplex sound I/O.

type Form Uses

type Form interface {
    Channels() int
    SampleRate() freq.T
}

Interface Form specifies the logical content of pcm audio data, namely the number of channels and the sample rate. Form does not specify the in-memory layout of pcm audio data such as sample codec or whether or not the data is channel-interleaved.

Applications which normalize memory layout of pcm data can use Form implementations to determine all necessary values of pcm data.

func MonoCd Uses

func MonoCd() Form

MonoCd returns a single channel form at CD sampling rate.

func MonoDvd Uses

func MonoDvd() Form

MonoDvd gives a single channel form at Dvd sample rate (48kHz).

func NewForm Uses

func NewForm(f freq.T, c int) Form

NewForm creates a new Form for sampling frequency f with c channels of data.

func StereoCd Uses

func StereoCd() Form

StereoCd returns a 2-channel form at CD sampling rate.

func StereoDvd Uses

func StereoDvd() Form

StereoDvd gives a 2-channel form at Dvd sample rate (48kHz).

type RandomAccess Uses

type RandomAccess interface {
    Seeker
    // Receive is as specified in Source.Receive.
    Receive(dst []float64) (int, error)
    // Send is as specified as in Sink.Send.
    Send(src []float64) error
}

RandomAccess is an interface for full read/write/seek support.

type Seeker Uses

type Seeker interface {
    Form
    Pos() int64         // Where we currently are in the source
    Len() int64         // Length of the source in frames
    Seek(f int64) error // Seek goes to the frame index f
}

Interface Seeker provides common access to a source of sound with seek support.

type Sink Uses

type Sink interface {
    Form
    Closer
    // Send sends all the samples in d, returning a non-nil
    // error if it does not succeed.
    //
    // len(d) must be a multiple of the number of channels
    // associated with the Sink, or Send will return a
    // ErrChannelAlignment.
    //
    // In case the Sink is multi-channel, d is interpreted in
    // channel-deinterleaved format.
    Send(d []float64) error
}

Sink is an interface for a destination of samples.

var Discard Sink = &discard{}

Discard does nothing when samples are sent to it.

type SinkSeeker Uses

type SinkSeeker interface {
    Seeker
    Closer
    // Send is as specified as in Sink.Send.
    Send(src []float64) error
}

SinkSeeker is a Sink with Seek support.

type Source Uses

type Source interface {
    Form
    Closer
    // Receive places samples in d.
    //
    // Receive returns the number of frames placed in d together with
    // any error.  Receive may use all of d as scatch space.
    //
    // Receive returns a non-nil error if and only if it returns 0 frames
    // received.  Receive may return 0 < n < len(d)/Channels() frames only
    // if the subsequent call will return (0, io.EOF).  As a result, the
    // caller need not be concerned with whether or not the data is "ready".
    //
    // Receive returns multi-channel data in de-interleaved format.
    // If len(d) is not a multiple of Channels(), then Receive returns
    // ErrChannelAlignment.  If Receive returns fewer than len(d)/Channels()
    // frames, then the deinterleaved data of n frames is arranged in
    // the prefix d[:n*Channels()].
    Receive(d []float64) (int, error)
}

Source is an interface for a source of samples.

type SourceSeeker Uses

type SourceSeeker interface {
    Seeker
    Closer
    // Receive is as specified in Source.Receive.
    Receive(dst []float64) (int, error)
}

SourceSeeker is a Source with Seek support.

Directories

PathSynopsis
cilPackage cil provides channel (de-)interleaving support.
freqPackage freq gives frequency types and operations.
genPackage gen provides audio generators.
opsPackage ops provides basic source and channel operations which do not require multiplexing io.
samplePackage sample provides support for different sample point data formats.
sndbufPackage sndbuf provides in memory audio sources and sinks.

Package sound imports 6 packages (graph) and is imported by 14 packages. Updated 2018-11-10. Refresh now. Tools for package owners.