Header
#struct HeaderThe whole of an au header: where the samples are, how they are coded, and their shape.
| Name | Type | Description |
|---|---|---|
data_offset | int = 0 | Where the samples start. At least HeaderSize, and anything between is a text note. |
data_size | int = 0 | How many bytes of samples there are, held inside the file. |
encoding | int = 0 | Which Enc number the samples use. |
rate | int = 0 | Frames per second. |
channels | int = 0 | How many channels. |
import audio
import audio.au
import compress
import filepath
import math
import mem
import os
func main:
mut c := audio.New(22050, 1, 64)
audio.SetSample(c, 3, 0, 0.5)
mut buf := au.EncodeAUEncoding(c, au.EncPcm16)
println au.IsAU(buf.data, buf.len), au.IsAU(buf.data, 8)
println audio.FormatName(audio.DetectFormat(buf.data, buf.len))
mut h := au.Header {}
println au.ReadHeader(buf.data, buf.len, h)
println h.data_offset == au.HeaderSize, h.encoding == au.EncPcm16
println h.rate, h.channels, h.data_size
mut ok := false
info := au.ProbeAU(buf.data, buf.len, ok)
println ok, info.rate, info.channels, info.bits, info.frames, info.lossless
mut dok := false
mut back := au.DecodeAU(buf.data, buf.len, dok)
println dok, back.frames, back.bits, audio.Sample(back, 3, 0)
mut fbuf := au.EncodeAUEncoding(c, au.EncFloat32)
mut fok := false
mut fback := au.DecodeAU(fbuf.data, fbuf.len, fok)
println fok, fback.bits, audio.Sample(fback, 3, 0) == audio.Sample(c, 3, 0)
mut mbuf := au.EncodeAUEncoding(c, au.EncMuLaw)
mut mok := false
mut mback := au.DecodeAU(mbuf.data, mbuf.len, mok)
println mok, mback.bits, math.Abs(audio.Sample(mback, 3, 0) - 0.5) < 0.02
mut minfo := false
println au.ProbeAU(mbuf.data, mbuf.len, minfo).lossless
println compress.BufLen(mbuf) == au.HeaderSize + 64
println compress.BufLen(au.EncodeAUEncoding(c, 99))
println compress.BufLen(au.EncodeAU(c)) == au.HeaderSize + 128
path := filepath.Join(os.TempDir(), "salam_au_example.au")
defer mem.Free(path as void*)
println au.SaveAU(c, path)
mut diskok := false
mut disk := au.OpenAU(path, diskok)
println diskok, disk.frames, disk.rate
mut gone := false
missing := filepath.Join(os.TempDir(), "salam_au_none.au")
defer mem.Free(missing as void*)
au.OpenAU(missing, gone)
println gone
compress.BufFree(buf)
compress.BufFree(fbuf)
compress.BufFree(mbuf)
audio.Free(c)
audio.Free(back)
audio.Free(fback)
audio.Free(mback)
audio.Free(disk)
endtrue false au true true true 22050 1 128 true 22050 1 16 64 true true 64 16 0.5 true 32 true true 16 true false true 0 true true true 64 22050 false