gb.sound.play

Description

// wav file:
int8_t gb.sound.play( [const] char* filename [, bool loop = false] )
// pattern:
int8_t gb.sound.play( [const] uint16_t* pattern [, bool loop = false] )
// raw buffer:
int8_t gb.sound.play( [const] uint8_t* buffer [, uint32_t length] [, bool loop = false] )
// custom handler:
int8_t gb.sound.play( Sound_Handler* handler [, bool loop = false] )

gb.sound.play will start playing sound from various sources. They return a track identifier or -1 if failed (no available channel).

  • Wav file Plays an 8-bit unsigned wav file with a bitrate of 44.1kHz (max. sound frequency of 22050Hz)
  • Pattern Plays a pattern
  • Raw Buffer Plays a raw unsigned 8-bit buffer. The length of the buffer is determined automatically. If that fails (as in, your program won't compile) manually specify the length.
  • Custom Handler Play a custom sound handler

Parameters

  • (mixed) source: see above
  • bool loop: if true the sound will loop over and over forever

Returns

int8_t: track identifier on success or -1 on failure

Example

#include <Gamebuino-Meta.h>

void setup() { gb.begin(); }

void loop() { while(!gb.update()); if (gb.buttons.pressed(BUTTON_A)) { // let's play TEST.WAV from the sd card! gb.sound.play("TEST.WAV"); } }