Asndlib

From WiiBrew
Jump to navigation Jump to search

ASndlib (also known as sndlib) is a sound library for the Wii, included as part of libogc. It includes a software mixer capable of playing up to 16 voices at once, and one of the voices may be generated from a MOD file (using MODplay) or an OGG file (using libtremor).

Features

  • Mixes internally @ 48000 Hz
  • Handles 16 voices
  • Implementation of voices in Mono or Stereo, 8 or 16 bits (signed), with independent volume adjustment for each channel
  • Pitch control (frequency) for voices from 1Hz to 144000Hz
  • Ability to add a playback delay to create reverb or echo effects, or chaining
  • Dynamic pitch and volume adjustment (for special effects)
  • Two modes: simple and continuous double buffer
  • Various control functions, potential for callbacks, timers, etc
  • Support for MP3, Ogg, and MOD playback

Usage

Asndlib is included in the latest release of libogc under the name asnd. Just add -lasnd in your Makefile, and add #include <asndlib.h> to your list of headers, and then you can start using ASND_ functions!

Audio Format

The primary audio format accepted by asndlib is 16-bit, 2-channel (stereo), big-endian RAW PCM.

  • To convert a file into this format using the command-line tool sox (Linux/OSX/Windows), use a command like the following:
    • sox input.wav -t raw -b 16 --endian big -c 2 output.raw
  • To export one of these files using GoldWave (Windows), choose the RAW format when saving.

MP3, Ogg, and MOD Playback

See the examples/audio folder included with devkitPro for examples of how to play MP3, Ogg, and MOD files on the Wii using asnd.

Simple mode

Run a voice program only once, allows you to adjust the format, frequency, delay, and volume of each channel. Ideal for sound effects.

Continuous double buffer mode

Schedule a voice similarly to simple mode, but add a callback function to be invoked when the voice can add new samples, using a special function.

Ideal for music players (eg Modplay, which I have already adapted to work with this, or libtremor to play Ogg).

songlib

Hermes' original sndlib also included a "musical note" feature called songlib for dynamic song generation. It has not been integrated into libogc, and unfortunately the source code has not been updated to work with the most recent libogc. However, the code remains here, as someone may still find it valuable, in whole or in part.

Uses a special function that allows you to specify a sample to be played in a loop, and then used by another function that lets you adjust the frequency, delay, attack, support, drop, and volume of the note. Ideal for small musical performances, improvised music, etc.

Demo

The first example runs a MOD in the background using voice 0 and mixes it with some sound effects played on the other voices. The second example runs an OGG in the background using voice 0 and mixes it with some sound effects played on the other voices. If you include a file named "sample.ogg" in the root directory, it will alternate playing it and the original file.

Free mode: (Wiimote): Use A and B for mixing sound effect voices. Use - and + to change the playback speed for Ogg / Mod, and use 1 and 2 to activate the different background tracks. On the DPad, press Left / Right to move forward or backward within the Ogg (only works for the Ogg example).

Press Home or RESET to exit the application.

The example also shows 900 rotating cubes in the background along with 900 sections of "land" and lighting composed of three "Spot" light sources to show that Rocky can still handle it!

See Also

Homebrew using Asndlib