~/bend-docscommunity

main.bend checks

raw source on the hub · import 0x05eb91b04a37c34a9abe2324661894f5/main.bend as Main

ezaudio: a Clip is a sample rate, a channel count, a sample format, and interleaved PCM frames. WAV reads and writes RIFF PCM. MP3 reads and writes MPEG-1 Layer III.

3 imports
import Base
import ./wav.bend as Wav
import ./mp3.bend as Mp3

Types

type Format source · line 9 · raw

Data

signed 16-bit PCM, or IEEE 754 binary32

type Clip source · line 14 · raw

Data

one clip. pcm is interleaved. s16 lives in the low 16 bits.

Definitions

def s16 source · line 18 · raw

Format

signed 16-bit little-endian PCM

def f32 source · line 22 · raw

Format

IEEE 754 binary32, stored as its bits

def kind.of source · line 25 · raw

@fmt:Format -> U32

def fmt.of source · line 32 · raw

@+kind:U32 -> Format

def wav.clip source · line 39 · raw

@w:0x05eb91b04a37c34a9abe2324661894f5/wav.Wav -> Clip

def fmt.same source · line 44 · raw

@aa:Format -> @bb:Format -> Bool

def clip source · line 56 · raw

@+rate:U32 -> @+channels:U32 -> @format:Format -> @frames:List<&2, U32> -> Clip

a clip from its rate, channel count, format, and interleaved frames

def rate source · line 60 · raw

@c:Clip -> U32

the sample rate, in hertz

def channels source · line 66 · raw

@c:Clip -> U32

how many channels are interleaved

def format source · line 72 · raw

@c:Clip -> Format

s16 or f32

def frames source · line 78 · raw

@c:Clip -> List<&2, U32>

the interleaved frames

def count.of source · line 83 · raw

@+channels:U32 -> @+nsamples:U32 -> U32

def count source · line 91 · raw

@c:Clip -> U32

how many frames. zero channels count as none.

def fill source · line 97 · raw

@+rate:U32 -> @+channels:U32 -> @format:Format -> @+sample:U32 -> @+nframes:U32 -> Clip

one sample, repeated across nframes frames

def ls.drop source · line 100 · raw

@hop:Nat -> @xs:List<&2, U32> -> List<&2, U32>

def ls.take source · line 111 · raw

@hop:Nat -> @xs:List<&2, U32> -> @acc:List<&2, U32> -> List<&2, U32>

def ls.slice source · line 122 · raw

@xs:List<&2, U32> -> @+dropn:U32 -> @+taken:U32 -> List<&2, U32>

def trim.go source · line 125 · raw

@ok:Bool -> @+rate:U32 -> @+channels:U32 -> @format:Format -> @frames:List<&2, U32> -> @+start:U32 -> @+nframes:U32 -> Maybe<&2, Clip>

def trim source · line 142 · raw

@c:Clip -> @+start:U32 -> @+nframes:U32 -> Maybe<&2, Clip>

frames [start, start + nframes). none when that span passes the end.

def eq.all source · line 148 · raw

@ar:Bool -> @ac:Bool -> @af:Bool -> Bool

def concat.go source · line 159 · raw

@ok:Bool -> @+rate:U32 -> @+channels:U32 -> @format:Format -> @left:List<&2, U32> -> @right:List<&2, U32> -> Maybe<&2, Clip>

def concat.pair source · line 173 · raw

@+rate:U32 -> @+channels:U32 -> @+format:Format -> @left:List<&2, U32> -> @other:Clip -> Maybe<&2, Clip>

def concat source · line 180 · raw

@left:Clip -> @right:Clip -> Maybe<&2, Clip>

the frames of both clips, or none when rate, channels, or format differ

def list.empty source · line 185 · raw

@xs:List<&2, U32> -> Bool

def wav.bytes source · line 192 · raw

@empty:Bool -> @+rate:U32 -> @+channels:U32 -> @+kind:U32 -> @frames:List<&2, U32> -> Maybe<&2, List<&2, U32>>

def wav.parsed source · line 199 · raw

@got:Maybe<&2, 0x05eb91b04a37c34a9abe2324661894f5/wav.Wav> -> Maybe<&2, Clip>

def decode_wav source · line 207 · raw

@xs:List<&2, U32> -> Maybe<&2, Clip>

a RIFF WAVE clip, or none when the bytes are not mono or stereo PCM or float

def encode_wav source · line 211 · raw

@c:Clip -> Maybe<&2, List<&2, U32>>

a RIFF WAVE file. none when there are no frames, or the rate or channels are unfit.

def mp3.clip source · line 216 · raw

@p:0x05eb91b04a37c34a9abe2324661894f5/mp3.Pcm -> Clip

def mp3.parsed source · line 221 · raw

@got:Maybe<&2, 0x05eb91b04a37c34a9abe2324661894f5/mp3.Pcm> -> Maybe<&2, Clip>

def decode_mp3 source · line 229 · raw

@xs:List<&2, U32> -> Maybe<&2, Clip>

MPEG-1 Layer III to f32 frames. Layer I, Layer II, joint stereo, and a CRC are none.

def encode_mp3 source · line 233 · raw

@c:Clip -> Maybe<&2, List<&2, U32>>

MPEG-1 Layer III at 320 kbit/s. rates are 32000, 44100, and 48000. none when unfit or empty.