Common
#struct CommonWhat an AIFF COMM chunk says, plus where the samples are.
| Name | Type | Description |
|---|---|---|
channels | int = 0 | How many channels. |
frames | int = 0 | How many frames the header claims. |
bits | int = 0 | Bits per sample. |
rate | int = 0 | Frames per second, read from the 80 bit float AIFF stores it in. |
compression | int = 0 | Which Comp number the file uses. Plain AIFF is always CompNone. |
data_offset | int = 0 | Where the samples start, past the SSND header and its offset field. |
data_size | int = 0 | How many bytes of samples there are. |
import audio
import audio.aiff
import compress
import filepath
import mem
import os
func main:
mut c := audio.New(44100, 2, 64)
audio.SetSample(c, 7, 1, 0.5)
mut buf := aiff.EncodeAIFFBits(c, 24)
println aiff.IsAIFF(buf.data, buf.len), aiff.IsAIFF(buf.data, 4)
println audio.FormatName(audio.DetectFormat(buf.data, buf.len))
mut cm := aiff.Common {}
println aiff.ReadCommon(buf.data, buf.len, cm)
println cm.channels, cm.frames, cm.bits, cm.rate
println cm.compression == aiff.CompNone, cm.data_size
mut ok := false
info := aiff.ProbeAIFF(buf.data, buf.len, ok)
println ok, info.rate, info.channels, info.bits, info.frames, info.lossless
mut dok := false
mut back := aiff.DecodeAIFF(buf.data, buf.len, dok)
println dok, back.frames, back.bits, audio.Sample(back, 7, 1)
each rate in [8000, 22050, 44100, 96000]:
mut one := audio.New(rate, 1, 2)
mut probe := aiff.EncodeAIFFBits(one, 16)
mut c2 := aiff.Common {}
aiff.ReadCommon(probe.data, probe.len, c2)
println rate, c2.rate == rate
compress.BufFree(probe)
audio.Free(one)
end
println compress.BufLen(aiff.EncodeAIFFBits(c, 12)),
compress.BufLen(aiff.EncodeAIFF(audio.Clip {}))
path := filepath.Join(os.TempDir(), "salam_aiff_example.aiff")
defer mem.Free(path as void*)
println aiff.SaveAIFFBits(c, path, 16)
println aiff.SaveAIFF(c, path)
mut fok := false
mut disk := aiff.OpenAIFF(path, fok)
println fok, disk.bits, disk.frames
mut gone := false
missing := filepath.Join(os.TempDir(), "salam_aiff_none.aiff")
defer mem.Free(missing as void*)
aiff.OpenAIFF(missing, gone)
println gone
compress.BufFree(buf)
audio.Free(c)
audio.Free(back)
audio.Free(disk)
endtrue false aiff true 2 64 24 44100 true 384 true 44100 2 24 64 true true 64 24 0.5 8000 true 22050 true 44100 true 96000 true 0 0 true true true 16 64 false