Exemplo n.º 1
0
func writeHeader(w io.Writer, f *audio.File) {
	writeString(w, "RIFF")
	writeUint32(w, uint32(36+f.Length()*int(f.ByteDepth())*f.NumChannels()))
	writeString(w, "WAVE")
	writeString(w, "fmt ")
	writeUint32(w, 16)
	writeUint16(w, 1)
	writeUint16(w, uint16(f.NumChannels()))
	writeUint32(w, uint32(f.SampleRate))
	writeUint32(w, uint32(int(f.SampleRate)*f.NumChannels()*int(f.ByteDepth())))
	writeUint16(w, uint16(int(f.ByteDepth())*f.NumChannels()))
	writeUint16(w, uint16(f.Depth))
}
Exemplo n.º 2
0
func Encode(w io.Writer, f *audio.File) error {
	writeHeader(w, f)
	writeString(w, "data")
	writeUint32(w, uint32(f.Length()*int(f.ByteDepth())*f.NumChannels()))

	for sample := range f.Data[0] {
		for channel := range f.Data {
			value := f.Data[channel][sample]
			switch f.ByteDepth() {
			case 1:
				writeUint8(w, uint8(value))
			case 2:
				writeUint16(w, uint16(value))
			default:
				return ErrUnsupportedDepth
			}
		}
	}
	return nil
}
Exemplo n.º 3
0
func EstimateFileSize(f *audio.File) uint64 {
	return 44 + uint64(f.Length()*int(f.ByteDepth())*f.NumChannels())
}