Documentation
¶
Index ¶
- Variables
- func AppleNoteToPitch(note uint16) string
- func AppleScaleToString(scale uint16) string
- type AppleMetadata
- type Chunk
- type Decoder
- func (d *Decoder) Drain() error
- func (d *Decoder) Duration() (time.Duration, error)
- func (d *Decoder) EOF() bool
- func (d *Decoder) Err() error
- func (d *Decoder) Format() *audio.Format
- func (d *Decoder) FullPCMBuffer() (*audio.IntBuffer, error)
- func (d *Decoder) FwdToPCM() error
- func (d *Decoder) IsValidFile() bool
- func (d *Decoder) NextChunk() (*Chunk, error)
- func (d *Decoder) PCMBuffer(buf *audio.IntBuffer) (n int, err error)
- func (d *Decoder) PCMLen() int64
- func (d *Decoder) ReadInfo()
- func (d *Decoder) Reset()
- func (d *Decoder) Rewind() error
- func (d *Decoder) SampleBitDepth() int32
- func (d *Decoder) Seek(offset int64, whence int) (int64, error)
- func (d *Decoder) String() string
- func (d *Decoder) Tempo() float64
- func (d *Decoder) WasPCMAccessed() bool
- type Encoder
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // COMMID is the common chunk ID COMMID = [4]byte{'C', 'O', 'M', 'M'} COMTID = [4]byte{'C', 'O', 'M', 'T'} SSNDID = [4]byte{'S', 'S', 'N', 'D'} // ErrFmtNotSupported is a generic error reporting an unknown format. ErrFmtNotSupported = errors.New("format not supported") // ErrUnexpectedData is a generic error reporting that the parser encountered unexpected data. ErrUnexpectedData = errors.New("unexpected data content") // Debug is a flag that can be turned on to see more logs Debug = false )
Functions ¶
func AppleNoteToPitch ¶
AppleNoteToPitch returns the pitch for the stored note.
func AppleScaleToString ¶
AppleScaleToString converts the scale information into a string representation.
Types ¶
type AppleMetadata ¶
type AppleMetadata struct {
// Beats is the number of beats in the sample
Beats uint32
// Note is the root key of the sample (48 = C)
Note uint16
// Scale is the musical scale; 0 = neither, 1 = minor, 2 = major, 4 = both
Scale uint16
// Numerator of the time signature
Numerator uint16
// Denominator of the time signature
Denominator uint16
// IsLooping indicates if the sample is a loop or not
IsLooping bool
// Tags are tags related to the content of the file
Tags []string
}
AppleMetadata is a list of custom fields sometimes set by Apple specific progams such as Logic.
type Chunk ¶
Chunk is a struct representing a data chunk the reader is shared with the container but convenience methods are provided. The reader always starts at the beggining of the data. SSND chunk is the sound chunk Chunk specs: http://www.onicos.com/staff/iz/formats/aiff.html AFAn seems to be an OS X specific chunk, meaning & format TBD
func (*Chunk) IsFullyRead ¶
IsFullyRead checks if we're finished reading the chunk
type Decoder ¶
type Decoder struct {
// ID is always 'FORM'. This indicates that this is a FORM chunk
ID [4]byte
// Size contains the size of data portion of the 'FORM' chunk.
// Note that the data portion has been
// broken into two parts, formType and chunks
Size uint32
// Form describes what's in the 'FORM' chunk. For Audio IFF files,
// formType (aka Format) is always 'AIFF'.
// This indicates that the chunks within the FORM pertain to sampled sound.
Form [4]byte
NumChans uint16
NumSampleFrames uint32
BitDepth uint16
SampleRate int
//
PCMSize uint32
PCMChunk *Chunk
//
Comments []string
// AIFC data
Encoding [4]byte
EncodingName string
// Apple specific
HasAppleInfo bool
AppleInfo AppleMetadata
// contains filtered or unexported fields
}
Decoder is the wrapper structure for the AIFF container
func NewDecoder ¶
func NewDecoder(r io.ReadSeeker) *Decoder
NewDecoder creates a new reader reading the given reader and pushing audio data to the given channel. It is the caller's responsibility to call Close on the reader when done.
func (*Decoder) Duration ¶
Duration returns the time duration for the current AIFF container
Example ¶
path, _ := filepath.Abs("fixtures/kick.aif")
f, err := os.Open(path)
if err != nil {
panic(err)
}
defer f.Close()
c := NewDecoder(f)
d, _ := c.Duration()
fmt.Printf("kick.aif has a duration of %f seconds\n", d.Seconds())
Output: kick.aif has a duration of 0.203356 seconds
func (*Decoder) FullPCMBuffer ¶
FullPCMBuffer is an inneficient way to access all the PCM data contained in the audio container. The entire PCM data is held in memory. Consider using Buffer() instead.
func (*Decoder) FwdToPCM ¶
FwdToPCM forwards the underlying reader until the start of the PCM chunk. If the PCM chunk was already read, no data will be found (you need to rewind).
func (*Decoder) IsValidFile ¶
IsValidFile verifies that the file is valid/readable.
Example ¶
f, err := os.Open("fixtures/kick.aif")
if err != nil {
log.Fatal(err)
}
defer f.Close()
fmt.Printf("is this file valid: %t", NewDecoder(f).IsValidFile())
Output: is this file valid: true
func (*Decoder) PCMBuffer ¶
PCMBuffer populates the passed PCM buffer and returns the number of samples read and a potential error. If the reader reaches EOF, an io.EOF error will be returned.
func (*Decoder) ReadInfo ¶
func (d *Decoder) ReadInfo()
ReadInfo reads the underlying reader to extract information. This method is safe to call multiple times.
func (*Decoder) Reset ¶
func (d *Decoder) Reset()
Reset resets the decoder (and rewind the underlying reader)
func (*Decoder) Rewind ¶ added in v1.1.0
Rewind allows the decoder to be rewound to the beginning of the PCM data. This is useful if you want to keep on decoding the same file in a loop.
func (*Decoder) SampleBitDepth ¶
SampleBitDepth returns the bit depth encoding of each sample.
func (*Decoder) WasPCMAccessed ¶
WasPCMAccessed returns positively if the PCM data was previously accessed.
type Encoder ¶
type Encoder struct {
SampleRate int
BitDepth int
NumChans int
WrittenBytes int
// contains filtered or unexported fields
}
Encoder encodes LPCM data into an aiff content.
func NewEncoder ¶
func NewEncoder(w io.WriteSeeker, sampleRate, bitDepth, numChans int) *Encoder
NewEncoder creates a new encoder to create a new aiff file. Don't forget to add Frames to the encoder before writing.