Documentation ¶
Overview ¶
Package audio is a work in progress package containing audio related sub packages.
The APIs are not stable, the code is unfinalized and should not be used in production.
See sub packages.
Index ¶
- Variables
- func AvgInt(xs ...int) int
- func IeeeFloatToInt(b [10]byte) int
- func Int32toInt24LEBytes(n int32) []byte
- func IntMaxSignedValue(b int) int
- func IntToIeeeFloat(i int) [10]byte
- func Uint24to32(bytes []byte) uint32
- func Uint32toUint24Bytes(n uint32) []byte
- type DataFormat
- type Format
- type PCMBuffer
- func (b *PCMBuffer) AsFloat32s() (out []float32)
- func (b *PCMBuffer) AsFloat64s() (out []float64)
- func (b *PCMBuffer) AsInt16s() (out []int16)
- func (b *PCMBuffer) AsInt32s() (out []int32)
- func (b *PCMBuffer) AsInt64s() (out []int64)
- func (b *PCMBuffer) AsInts() (out []int)
- func (b *PCMBuffer) CacheFloat64s()
- func (b *PCMBuffer) CacheInts()
- func (b *PCMBuffer) Clone() *PCMBuffer
- func (b *PCMBuffer) Len() int
- func (b *PCMBuffer) Size() (numFrames int)
- func (b *PCMBuffer) SwitchPrimaryType(t DataFormat)
Constants ¶
This section is empty.
Variables ¶
var ( // FormatMono225008bBE mono 8bit 22.5kHz AIFF like format. FormatMono225008bBE = &Format{ NumChannels: 1, SampleRate: 22500, BitDepth: 8, Endianness: binary.BigEndian, } // FormatMono2250016bBE mono 16bit 22.5kHz AIFF like format. FormatMono2250016bBE = &Format{ NumChannels: 1, SampleRate: 22500, BitDepth: 16, Endianness: binary.BigEndian, } // FormatMono441008bBE mono 8bit 44.1kHz AIFF like format. FormatMono441008bBE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 8, Endianness: binary.BigEndian, } // FormatMono4410016bBE mono 16bit 44.1kHz AIFF like format. FormatMono4410016bBE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 16, Endianness: binary.BigEndian, } // FormatMono4410024bBE mono 24bit 44.1kHz AIFF like format. FormatMono4410024bBE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 24, Endianness: binary.BigEndian, } // FormatMono4410032bBE mono 32bit 44.1kHz AIFF like format. FormatMono4410032bBE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 32, Endianness: binary.BigEndian, } // FormatStereo225008bBE Stereo 8bit 22.5kHz AIFF like format. FormatStereo225008bBE = &Format{ NumChannels: 2, SampleRate: 22500, BitDepth: 8, Endianness: binary.BigEndian, } // FormatStereo2250016bBE Stereo 16bit 22.5kHz AIFF like format. FormatStereo2250016bBE = &Format{ NumChannels: 2, SampleRate: 22500, BitDepth: 16, Endianness: binary.BigEndian, } // FormatStereo441008bBE Stereo 8bit 44.1kHz AIFF like format. FormatStereo441008bBE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 8, Endianness: binary.BigEndian, } // FormatStereo4410016bBE Stereo 16bit 44.1kHz AIFF like format. FormatStereo4410016bBE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 16, Endianness: binary.BigEndian, } // FormatStereo4410024bBE Stereo 24bit 44.1kHz AIFF like format. FormatStereo4410024bBE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 24, Endianness: binary.BigEndian, } // FormatStereo4410032bBE Stereo 32bit 44.1kHz AIFF like format. FormatStereo4410032bBE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 32, Endianness: binary.BigEndian, } // FormatMono225008bLE mono 8bit 22.5kHz AIFF like format. FormatMono225008bLE = &Format{ NumChannels: 1, SampleRate: 22500, BitDepth: 8, Endianness: binary.LittleEndian, } // FormatMono2250016bLE mono 16bit 22.5kHz AIFF like format. FormatMono2250016bLE = &Format{ NumChannels: 1, SampleRate: 22500, BitDepth: 16, Endianness: binary.LittleEndian, } // FormatMono441008bLE mono 8bit 44.1kHz AIFF like format. FormatMono441008bLE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 8, Endianness: binary.LittleEndian, } // FormatMono4410016bLE mono 16bit 44.1kHz AIFF like format. FormatMono4410016bLE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 16, Endianness: binary.LittleEndian, } // FormatMono4410024bLE mono 24bit 44.1kHz AIFF like format. FormatMono4410024bLE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 24, Endianness: binary.LittleEndian, } // FormatMono4410032bLE mono 32bit 44.1kHz AIFF like format. FormatMono4410032bLE = &Format{ NumChannels: 1, SampleRate: 44100, BitDepth: 32, Endianness: binary.LittleEndian, } // FormatStereo225008bLE Stereo 8bit 22.5kHz AIFF like format. FormatStereo225008bLE = &Format{ NumChannels: 2, SampleRate: 22500, BitDepth: 8, Endianness: binary.LittleEndian, } // FormatStereo2250016bLE Stereo 16bit 22.5kHz AIFF like format. FormatStereo2250016bLE = &Format{ NumChannels: 2, SampleRate: 22500, BitDepth: 16, Endianness: binary.LittleEndian, } // FormatStereo441008bLE Stereo 8bit 44.1kHz AIFF like format. FormatStereo441008bLE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 8, Endianness: binary.LittleEndian, } // FormatStereo4410016bLE Stereo 16bit 44.1kHz AIFF like format. FormatStereo4410016bLE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 16, Endianness: binary.LittleEndian, } // FormatStereo4410024bLE Stereo 24bit 44.1kHz AIFF like format. FormatStereo4410024bLE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 24, Endianness: binary.LittleEndian, } // FormatStereo4410032bLE Stereo 32bit 44.1kHz AIFF like format. FormatStereo4410032bLE = &Format{ NumChannels: 2, SampleRate: 44100, BitDepth: 32, Endianness: binary.LittleEndian, } )
var (
ErrInvalidBuffer = errors.New("invalid buffer")
)
var ( // RootA or concert A is the reference frequency for A4. // Modify this package variable if you need to change it to 435 (classical) or // 415 (baroque). Methods refering to this root A note will use this variable. RootA = 440.0 )
Functions ¶
func IeeeFloatToInt ¶
IeeeFloatToInt converts a 10 byte IEEE float into an int.
func Int32toInt24LEBytes ¶
Int32toInt24LEBytes converts a int32 into a 3 byte int24 representation
func IntMaxSignedValue ¶
IntMaxSignedValue returns the max value of an integer based on its memory size
func IntToIeeeFloat ¶
IntToIeeeFloat converts an int into a 10 byte IEEE float.
func Uint24to32 ¶
Uint24to32 converts a 3 byte uint23 into a uint32 BigEndian!
func Uint32toUint24Bytes ¶
Uint32toUint24Bytes converts a uint32 into a 3 byte uint24 representation
Types ¶
type DataFormat ¶
type DataFormat int
DataFormat is an enum type to indicate the underlying data format used.
const ( // Unknown refers to an unknown format Unknown DataFormat = iota // Integer represents the int type. // it represents the native int format used in audio buffers. Integer // Float represents the float64 type. // It represents the native float format used in audio buffers. Float // Byte represents the byte type. Byte )
type Format ¶
type Format struct { // NumChannels is the number of channels contained in the data NumChannels int // SampleRate is the sampling rate in Hz SampleRate int // BitDepth is the number of bits of data for each sample BitDepth int // Endianess indicate how the byte order of underlying bytes Endianness binary.ByteOrder }
Format is a high level representation of the underlying data.
type PCMBuffer ¶
type PCMBuffer struct { // Format describes the format of the buffer data. Format *Format // Ints is a store for audio sample data as integers. Ints []int // Floats is a store for audio samples data as float64. Floats []float64 // Bytes is a store for audio samples data as raw bytes. Bytes []byte // DataType indicates the primary format used for the underlying data. // The consumer of the buffer might want to look at this value to know what store // to use to optimaly retrieve data. DataType DataFormat // contains filtered or unexported fields }
PCMBuffer encapsulates uncompressed audio data and provides useful methods to read/manipulate this PCM data.
func NewPCMByteBuffer ¶
NewPCMByteBuffer returns a new PCM buffer backed by the passed float samples
func NewPCMFloatBuffer ¶
NewPCMFloatBuffer returns a new PCM buffer backed by the passed float samples
func NewPCMIntBuffer ¶
NewPCMIntBuffer returns a new PCM buffer backed by the passed integer samples
func (*PCMBuffer) AsFloat32s ¶
AsFloat32s returns the buffer samples as float32 sample values.
func (*PCMBuffer) AsFloat64s ¶
AsFloat64s returns the buffer samples as float64 sample values.
func (*PCMBuffer) CacheFloat64s ¶
func (b *PCMBuffer) CacheFloat64s()
CacheFloat64s ensures that the underlying int store is filled up so Floats() can be called knowing that the data is available. Note that if the underlying data is changed, it is the caller responsibility to refresh the cache.
func (*PCMBuffer) CacheInts ¶
func (b *PCMBuffer) CacheInts()
CacheInts ensures that the underlying int store is filled up so Ints() can be called knowing that the data is available. Note that if the underlying data is changed, it is the caller responsibility to refresh the cache.
func (*PCMBuffer) Clone ¶
Clone creates a clean clone that can be modified without changing the source buffer.
func (*PCMBuffer) SwitchPrimaryType ¶
func (b *PCMBuffer) SwitchPrimaryType(t DataFormat)
SwitchPrimaryType is a convenience method to switch the primary data type. Use this if you process/swap a different type than the original type.
Directories ¶
Path | Synopsis |
---|---|
Package aiff is a AIFF/AIFC decoder and encoder.
|
Package aiff is a AIFF/AIFC decoder and encoder. |
caf package implements an Apple Core Audio Format (CAF) parser.
|
caf package implements an Apple Core Audio Format (CAF) parser. |
demos
|
|
decimator
given a PCM audio file, convert it to mono and decimates it.
|
given a PCM audio file, convert it to mono and decimates it. |
dsp
|
|
cmd
generator example
|
generator example |
MIDI package is a midi format parser that parses the content of a midi stream and asyncronously send the data to a provided channel or collect the data into an accessible struct,
|
MIDI package is a midi format parser that parses the content of a midi stream and asyncronously send the data to a provided channel or collect the data into an accessible struct, |
mp3 is a package used to access mp3 information See: http://sea-mist.se/fou/cuppsats.nsf/all/857e49b9bfa2d753c125722700157b97/$file/Thesis%20report-%20MP3%20Decoder.pdf Uses some code from https://github.com/tcolgate/mp3 under MIT license Tristan Colgate-McFarlane and badgerodon
|
mp3 is a package used to access mp3 information See: http://sea-mist.se/fou/cuppsats.nsf/all/857e49b9bfa2d753c125722700157b97/$file/Thesis%20report-%20MP3%20Decoder.pdf Uses some code from https://github.com/tcolgate/mp3 under MIT license Tristan Colgate-McFarlane and badgerodon |
cmd/validator
this is a simple tool to validate the mp3 files in a folder
|
this is a simple tool to validate the mp3 files in a folder |
id3v1
id3v1 is a package allowing the extraction of id3v1 tags.
|
id3v1 is a package allowing the extraction of id3v1 tags. |
Package riff is package implementing a simple Resource Interchange File Format (RIFF) parser with basic support for sub formats such as WAV.
|
Package riff is package implementing a simple Resource Interchange File Format (RIFF) parser with basic support for sub formats such as WAV. |
riffinfo
riffinfo is a command line tool used to gather information about riff files.
|
riffinfo is a command line tool used to gather information about riff files. |
filters
filters implement easy to use audio filters.
|
filters implement easy to use audio filters. |
Package wav is a package allowing developers to decode and encode audio PCM data using the Waveform Audio File Format https://en.wikipedia.org/wiki/WAV
|
Package wav is a package allowing developers to decode and encode audio PCM data using the Waveform Audio File Format https://en.wikipedia.org/wiki/WAV |