main.bend checks
raw source on the hub · import 0xd2dab0fbc9db2e9ba3da65dae724eb41/main.bend as Main
ezaudio: audio for Bend 2, reading and writing WAV (RIFF PCM) and MP3 (MPEG-1 Layer III).
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 ./src/wav.bend as Wav import ./src/mp3.bend as Mp3
Types
type Format source · line 11 · raw
Data
signed 16-bit PCM, or IEEE 754 binary32
S16Format
FltFormat
type Clip source · line 16 · raw
Data
one clip. pcm is interleaved. s16 lives in the low 16 bits.
Clip@hz:U32 -> @nch:U32 -> @fmt:Format -> @pcm:List<&2, U32> -> Clip
Definitions
def s16 source · line 20 · raw
Format
signed 16-bit little-endian PCM
def f32 source · line 24 · raw
Format
IEEE 754 binary32, stored as its bits
def kind.of source · line 27 · raw
@fmt:Format -> U32
def fmt.of source · line 34 · raw
@+kind:U32 -> Format
def wav.clip source · line 41 · raw
@w:0xd2dab0fbc9db2e9ba3da65dae724eb41/src/wav.Wav -> Clip
def fmt.same source · line 46 · raw
@aa:Format -> @bb:Format -> Bool
def clip source · line 58 · 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 62 · raw
@c:Clip -> U32
the sample rate, in hertz
def channels source · line 68 · raw
@c:Clip -> U32
how many channels are interleaved
def format source · line 74 · raw
@c:Clip -> Format
s16 or f32
def frames source · line 80 · raw
@c:Clip -> List<&2, U32>
the interleaved frames
def count.of source · line 85 · raw
@+channels:U32 -> @+nsamples:U32 -> U32
def count source · line 93 · raw
@c:Clip -> U32
how many frames. zero channels count as none.
def fill source · line 99 · raw
@+rate:U32 -> @+channels:U32 -> @format:Format -> @+sample:U32 -> @+nframes:U32 -> Clip
one sample, repeated across nframes frames
def ls.drop source · line 102 · raw
@hop:Nat -> @xs:List<&2, U32> -> List<&2, U32>
def ls.take source · line 113 · raw
@hop:Nat -> @xs:List<&2, U32> -> @acc:List<&2, U32> -> List<&2, U32>
def ls.slice source · line 124 · raw
@xs:List<&2, U32> -> @+dropn:U32 -> @+taken:U32 -> List<&2, U32>
def trim.go source · line 127 · raw
@ok:Bool -> @+rate:U32 -> @+channels:U32 -> @format:Format -> @frames:List<&2, U32> -> @+start:U32 -> @+nframes:U32 -> Maybe<&2, Clip>
def trim source · line 144 · 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 150 · raw
@ar:Bool -> @ac:Bool -> @af:Bool -> Bool
def concat.go source · line 161 · 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 175 · raw
@+rate:U32 -> @+channels:U32 -> @+format:Format -> @left:List<&2, U32> -> @other:Clip -> Maybe<&2, Clip>
def concat source · line 182 · 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 187 · raw
@xs:List<&2, U32> -> Bool
def wav.bytes source · line 194 · raw
@empty:Bool -> @+rate:U32 -> @+channels:U32 -> @+kind:U32 -> @frames:List<&2, U32> -> Maybe<&2, List<&2, U32>>
def wav.parsed source · line 201 · raw
@got:Maybe<&2, 0xd2dab0fbc9db2e9ba3da65dae724eb41/src/wav.Wav> -> Maybe<&2, Clip>
def decode_wav source · line 209 · 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 213 · 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 218 · raw
@p:0xd2dab0fbc9db2e9ba3da65dae724eb41/src/mp3.Pcm -> Clip
def mp3.parsed source · line 223 · raw
@got:Maybe<&2, 0xd2dab0fbc9db2e9ba3da65dae724eb41/src/mp3.Pcm> -> Maybe<&2, Clip>
def decode_mp3 source · line 231 · 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 235 · 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.