46 lines
708 B
Go
46 lines
708 B
Go
package audio
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
)
|
|
|
|
var ErrFormat = errors.New("invalid audio format")
|
|
|
|
type Format uint
|
|
|
|
// Audio format.
|
|
const (
|
|
ByteFormat Format = iota
|
|
Int8Format
|
|
Int16LEFormat
|
|
Int16BEFormat
|
|
Int32LEFormat
|
|
Int32BEFormat
|
|
invalidFormat
|
|
)
|
|
|
|
func (f Format) Order() binary.ByteOrder {
|
|
switch f {
|
|
case Int16LEFormat, Int32LEFormat:
|
|
return binary.LittleEndian
|
|
case Int16BEFormat, Int32BEFormat:
|
|
return binary.BigEndian
|
|
default:
|
|
return binary.NativeEndian
|
|
}
|
|
}
|
|
|
|
func (f Format) BytesPerSample() int {
|
|
switch f {
|
|
case ByteFormat, Int8Format:
|
|
return 8
|
|
case Int16LEFormat, Int16BEFormat:
|
|
return 16
|
|
case Int32LEFormat, Int32BEFormat:
|
|
return 32
|
|
default:
|
|
return 0
|
|
}
|
|
}
|