Table of Contents

Class Audio

Namespace
GB
Assembly
GBSharp.Framework.dll

The sound hardware, at register level.

public static class Audio
Inheritance
Audio
Inherited Members

Remarks

This is deliberately not a music engine. It writes the APU registers and stops there: a note plays until something stops it, nothing is sequenced, and there is no mixing. A game that wants music wants a tracker driver, and that is a library rather than a framework concern.

Methods

Disable()

Powers down the APU, silencing everything and clearing its registers.

[Native("gbs_audio_off")]
public static void Disable()

Enable()

Powers up the APU and enables all channels on both speakers.

[Native("gbs_audio_on")]
public static void Enable()

Remarks

The sound hardware ignores every other register while it is off, so this has to come first.

PlayNoise(byte, byte)

Starts noise on channel 4.

[Native("gbs_audio_noise")]
public static void PlayNoise(byte volume, byte period)

Parameters

volume byte
period byte

Remarks

period is the raw polynomial-counter byte: lower values are brighter. Useful for hits and explosions.

PlayTone(Channel, Note, byte, Duty)

Starts a note on a square-wave channel.

[Native("gbs_audio_tone")]
public static void PlayTone(Channel channel, Note note, byte volume, Duty duty)

Parameters

channel Channel
note Note
volume byte
duty Duty

Remarks

channel is a runtime value, so this costs a branch in the shim on top of the register writes. Only Pulse1 and Pulse2 do anything; the note plays until Stop(Channel).

SetMasterVolume(byte, byte)

Sets the master volume for each speaker, 0-7.

[Native("gbs_audio_master_volume")]
public static void SetMasterVolume(byte left, byte right)

Parameters

left byte
right byte

SetRouting(byte)

Sets which channels reach which speaker.

[Native("gbs_audio_routing")]
public static void SetRouting(byte mask)

Parameters

mask byte

Remarks

The low nibble routes channels 1-4 to the right speaker, the high nibble to the left. 0xFF is everything on both.

Stop(Channel)

Silences one channel by dropping its envelope to zero.

[Native("gbs_audio_stop")]
public static void Stop(Channel channel)

Parameters

channel Channel