sound.jamo (built in)

sound: plays WAV files and made-up tones through the speakers, many at once. use "sound.jamo"

Sound goes out through waveOut, 44100 frames a second in 16-bit stereo, as six short buffers that take turns: while the speakers play some, update() mixes the next ones. Windows reads those buffers and writes their headers whenever it likes, so they live in memory from VirtualAlloc, which the memory cleaner never sees, and only close() gives it back. The block: six 48-byte headers, then at 512 the six buffers of 2048 bytes each. A clip keeps its frames as 16-bit stereo with 32768 added, so each sample reads back with peek_u16.

structClip

struct Clip
    samples: int
    frames: int
end

structVoice

struct Voice
    clip: Clip
    place: int
    volume: float
    looping: bool
    playing: bool
end

structSound

struct Sound
    device: int
    block: int
    next: int
    mix: int
    voices: [Voice]
    volume: float
    gaps: int
    started: bool
    silent: bool
    open: bool
    closed_by_program: bool
end

funcstart_sound

func start_sound(): Sound

Opens the PC's default speakers

funcstart_sound_device

func start_sound_device(number: int): Sound

Opens one sound device by number, from 0. A PC without it runs on in silence, with a note saying so

funcSound.quiet

func Sound.quiet()

Keeps tests silent: the speakers still play, at no volume. If Windows can't turn the volume down, only silence goes out

funcSound.must_be_open

func Sound.must_be_open()

funcSound.has_device

func Sound.has_device(): bool

True when sound really reaches a device

funcSound.close

func Sound.close()

Stops every sound and lets the speakers go

funcSound.play

func Sound.play(clip: Clip): Voice

funcSound.play_loop

func Sound.play_loop(clip: Clip): Voice

Plays a clip over and over until it's stopped

funcSound.start_voice

func Sound.start_voice(clip: Clip, looping: bool): Voice

funcSound.set_volume

func Sound.set_volume(volume: float)

Sets the volume of everything, from 0.0 to 1.0. Above 1.0 makes it louder, up to 4.0

funcSound.stop_all

func Sound.stop_all()

funcSound.playing

func Sound.playing(): int

How many sounds are playing now

funcSound.gaps

func Sound.gaps(): int

How many times the speakers ran out of sound, because update() wasn't called often enough

funcSound.played

func Sound.played(): int

How many frames the speakers have played since the start

funcVoice.stop

func Voice.stop()

funcVoice.is_playing

func Voice.is_playing(): bool

funcVoice.set_volume

func Voice.set_volume(volume: float)

funcsound_volume

func sound_volume(volume: float): float

funcSound.update

func Sound.update()

Mixes the next sound for the speakers. Call it once a frame

funcSound.fill

func Sound.fill(data: int)

Mixes 512 frames into one buffer

funcClip.seconds

func Clip.seconds(): float

How long a clip lasts, in seconds

functone

func tone(frequency: float, seconds: float, wave: string): Clip

Makes a tone: "sine", "square", "saw", "triangle" or "noise", fading in and out over 5 ms

funcsilence

func silence(seconds: float): Clip

A clip of silence, to mix other clips into, like a song made from notes

funcClip.mix

func Clip.mix(other: Clip, at: float, volume: float)

Adds another clip into this one, starting at a time in seconds, at a volume from 0.0 to 4.0. The part that goes past the end is left off, and loud parts are kept from wrapping around

funcsound_sine

func sound_sine(x: float): float

The sine of a whole turn times x, for x from 0.0 to 1.0

funcsound_damaged

func sound_damaged(path: string, why: string)

funcsound_number

func sound_number(data: string, place: int, size: int): int

funcsound_power

func sound_power(i: int): int

funcload_sound

func load_sound(path: string): Clip

Reads a WAV file: 8, 16, 24 or 32-bit, or 32-bit float, in mono or stereo, at any rate

funcsound_sample

func sound_sample(raw: int, at: int, kind: int, bits: int): int

One sample as a 16-bit number