Documentation ¶
Overview ¶
Package pcm provides a interface for interacting with PCM audio streams
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedBits = fmt.Errorf("unsupported bits in pcm format")
ErrUnsupportedBits represents that the Bits value for a Format was not supported for some operation.
Functions ¶
This section is empty.
Types ¶
type Format ¶
type Format struct { // SampleRate defines how many times per second a consumer should read a single value. An example // of a common value for this is 44100 or 44.1khz. SampleRate uint32 // Channels defines how many concurrent audio channels are present in audio data. Common values are // 1 for mono and 2 for stereo. Channels uint16 // Bits determines how many bits a single sample value takes up. 8, 16, and 32 are common values. // TODO: Do we need LE vs BE, float vs int representation? Bits uint16 }
Format is a PCM format; it defines how binary audio data should be converted into real audio.
func (Format) BytesPerSecond ¶
BytesPerSecond returns how many bytes this format would be encoded into per second in an audio stream.
func (Format) SampleFloat ¶
ReadFloat reads a single sample from an audio stream, respecting bits and channels: f.Bits / 8 bytes * f.Channels bytes will be read from b, and this count will be returned as 'read'. the length of values will be equal to f.Channels, if no error is returned. If an error is returned, it will be io.ErrUnexpectedEOF or ErrUnsupportedBits
func (Format) SampleSize ¶
type Formatted ¶
type Formatted interface { // PCMFormat will return the Format used by an encoded audio or expected by an audio consumer. // Implementations can embed a Format struct to simplify this. PCMFormat() Format }
The Formatted interface represents types that are aware of a PCM Format they expect or provide.