CanDecode
#func CanDecode(format: int): boolTrue when this build can read that format. Today that is WAV, AIFF and au; the others are being written.
import audio
import audio.codec
import compress
import filepath
import mem
import os
func main:
println codec.CanDecode(audio.FormatWAV), codec.CanEncode(audio.FormatWAV)
println codec.CanDecode(audio.FormatMP3), codec.CanEncode(audio.FormatFLAC)
println codec.Formats().Len(), codec.Formats().Get(0) == audio.FormatWAV
mut c := audio.New(22050, 2, 64)
audio.SetSample(c, 5, 0, 0.5)
audio.SetSample(c, 5, 1, -0.25)
path := filepath.Join(os.TempDir(), "salam_codec_open.wav")
defer mem.Free(path as void*)
println codec.Save(c, path)
mut ok := false
mut back := codec.Open(path, ok)
println ok, back.frames, back.channels, back.rate, back.bits
println audio.Sample(back, 5, 0), audio.Sample(back, 5, 1)
mut pok := false
info := codec.ProbeFile(path, pok)
println pok, audio.FormatName(info.format), info.frames, info.bits, info.lossless
mut buf := codec.Encode(c, audio.FormatWAV)
println compress.BufLen(buf) == 44 + 64 * 2 * 2
mut mok := false
mut mem_back := codec.Decode(buf.data, buf.len, mok)
println mok, mem_back.frames
mut iok := false
mem_info := codec.Probe(buf.data, buf.len, iok)
println iok, mem_info.channels
mp3 := filepath.Join(os.TempDir(), "salam_codec_open.mp3")
defer mem.Free(mp3 as void*)
println codec.Save(c, mp3)
println compress.BufLen(codec.Encode(c, audio.FormatMP3))
mut bad := false
mut junk := compress.NewByteBuf()
mut i := 0
until i < 16:
compress.BufPush(junk, i)
i++
end
codec.Decode(junk.data, junk.len, bad)
println bad
mut gone := false
nope := filepath.Join(os.TempDir(), "salam_codec_nope.wav")
defer mem.Free(nope as void*)
codec.Open(nope, gone)
println gone
compress.BufFree(buf)
compress.BufFree(junk)
audio.Free(c)
audio.Free(back)
audio.Free(mem_back)
endtrue true false true 4 true true true 64 2 22050 16 0.5 -0.25 true wav 64 16 true true true 64 true 2 false 0 false false