Skip to content

audio.um

Marek Maskarinec edited this page Mar 26, 2021 · 8 revisions

Audio playing library.

example:

fn main() {
  tophat.setup("sound example", 500, 500)
  // some other stuff you want to do.

  s1 := audio.load("file.wav")
  s2 := audio.load("music.mp3")
  s2.looping(true)
  sounds := []audio.sound{ s1, s2 }

  s2.play()

  for 1 {
    tophat.cycle(&w, &h, 0x000000ff, cam)

    if input.isjustpressed(input.KEY_ENTER) {
      s1.play()
    }
    if input.isjustpressed(input.KEY_ESCAPE) {
      s1.stop()
      s2.stop()
    }
  }
  s1.delete()
  s2.delete()
}

type sound

Basic sound type. Don't create by hand

fn load

fn load*(path: str): sound

Loads sound from given path.

fn setsounds

fn setsound*(ss: []sound)

Sets, which sounds are active. You generally want to have all your sounds here.

fn looping

fn (s: ^sound) looping*(l: bool)

Sets, if sound should replay after ending.

fn play

fn (s: ^sound) play*()

Plays the sound. If the sound if already playing, it won't do anything.

fn stop

fn (s: ^sound) stop*()

Stops the playing sound. Doesn't save progress.

fn vol

fn (s: ^sound) vol*(vol: real)

Sets volume of the sound.

fn del

fn (s: ^sound) del*()

Deletes the sound from memory.

Clone this wiki locally