libmsx
C library for MSX
|
Old PSG sound driver APIs. More...
Data Structures | |
struct | sound_fragment |
The sound fragment structure. More... | |
struct | sound_clip |
The sound clip structure. More... | |
Macros | |
#define | SOUND_CHANNEL_A (1 << 0) |
The bit-mask to specify PSG channel A. | |
#define | SOUND_CHANNEL_B (1 << 1) |
The bit-mask to specify PSG channel B. | |
#define | SOUND_CHANNEL_C (1 << 2) |
The bit-mask to specify PSG channel C. | |
#define | SOUND_CHANNEL_ALL (SOUND_CHANNEL_A | SOUND_CHANNEL_B | SOUND_CHANNEL_C) |
The bit-mask to specify all PSG channels. | |
#define | SOUND_SPEED_1X (4) |
The value of the playback speed multiplier for 1.0x speed. | |
#define | SOUND_SPEED_MIN (1) |
Minimum value of playback speed multiplier. | |
#define | SOUND_SPEED_MAX (8) |
Maximum value of playback speed multiplier. | |
Functions | |
void | sound_init (void) |
MSX This function initializes the PSG and the sound driver. | |
void | sound_set_speed (uint8_t multiplier) |
MSX Sets the playback speed multiplier for background music. | |
void | sound_set_volume (uint8_t volume) |
MSX Set main volume level. | |
void | sound_set_repeat (bool repeat) |
MSX Turn on/off the auto-repeat of the BGM. | |
void | sound_set_mute (uint8_t mute) |
MSX Mute/unmute for each sound channel. | |
void | sound_effect (const struct sound_clip *s) |
MSX Plays the specified music clip as sound effect. | |
void | sound_set_bgm (const struct sound_clip *s) |
MSX Sets the specified music clip as BGM in the sound driver. | |
void | sound_start (void) |
MSX Start the BGM. | |
void | sound_stop (void) |
MSX Stop the BGM. | |
void | sound_pause (void) |
MSX Pause the BGM. | |
void | sound_player (void) |
MSX Main routine of the sound driver. | |
Old PSG sound driver APIs.
struct sound_fragment |
The sound fragment structure.
The sound fragment structure represents a section of music. It is used to define reusable sections of music, such as intros, choruses, outros, etc.
The sound fragment structure holds a list of pointers to the sound data stream for each channel.
Each sound data stream shall be in the following format.
x*
means zero or more x
.x+
means one or more x
.b
(e.g. 1111b
), it means a binary number.-
in a binary number means an unused bit.:y
(e.g. foo:5
), it means that the term is a binary number with y
bits.The structure of chunk
:
Data Fields | ||
---|---|---|
uint8_t * | streams[3] | A list of pointers to the sound data stream for each channel. |
struct sound_clip |
The sound clip structure.
The sound clip structure is a list of sound fragments. It represents the entire logical data stream of music.
This structure also stores the priority order when the sound clip is used as a sound effect. (If the sound clip is to be used as background music, its priority has no meaning and will be ignored.)
Data Fields | ||
---|---|---|
uint16_t | priority | Priority for using this sound clip as a sound effect. |
size_t | num_fragments | Number of sound fragments. |
struct sound_fragment ** | fragments |
Pointer to an array of pointers to sound fragments. The pair of |
#define SOUND_CHANNEL_A (1 << 0) |
#define SOUND_CHANNEL_B (1 << 1) |
#define SOUND_CHANNEL_C (1 << 2) |
#define SOUND_CHANNEL_ALL (SOUND_CHANNEL_A | SOUND_CHANNEL_B | SOUND_CHANNEL_C) |
#define SOUND_SPEED_1X (4) |
The value of the playback speed multiplier for 1.0x speed.
#define SOUND_SPEED_MIN (1) |
Minimum value of playback speed multiplier.
Equivalent to SOUND_SPEED_1X / 4
(i.e., 0.25x speed).
#define SOUND_SPEED_MAX (8) |
Maximum value of playback speed multiplier.
Equivalent to SOUND_SPEED_1X * 2
(i.e., 2.0x speed).
void sound_init | ( | void | ) |
MSX
This function initializes the PSG and the sound driver.
This function must be called at least once. In particular, it must be called before the first call to sound_player().
void sound_set_speed | ( | uint8_t | multiplier | ) |
MSX
Sets the playback speed multiplier for background music.
This function is used to control the playback speed of background music.
The playback speed multiplier is specified by a value of 4 times. For example, a value of 4 means a playback speed of 1.0x, and a value of 6 means 1.5x.
multiplier
is 4 (i.e. 1.0x).multiplier
is 1 (i.e. 0.25x).multiplier
is 8 (i.e. 2.0x).multiplier | 4 times the playback speed multiplier |
void sound_set_volume | ( | uint8_t | volume | ) |
MSX
Set main volume level.
volume | main volume level (0..15) |
void sound_set_repeat | ( | bool | repeat | ) |
MSX
Turn on/off the auto-repeat of the BGM.
repeat | true : turn on, false : turn off |
void sound_set_mute | ( | uint8_t | mute | ) |
MSX
Mute/unmute for each sound channel.
The parameter mute
is a bit-set of the mute switches.
If a bit is 1
, the corresponding channel is muted; if a bit is 0
, the corresponding channel is unmuted.
mute | the bit-set of the mute switches. |
void sound_effect | ( | const struct sound_clip * | s | ) |
MSX
Plays the specified music clip as sound effect.
Priority of the sound effect
The priority of the sound effect is specified by s->priority
. The larger the value, the higher the priority. This priority determines whether or not the sound driver will play the specified sound clip, as follows
Auto-mute of the background music
While the sound effect is playing, some channels of the background music will be automatically muted (if they conflict with the sound effect) and those channels will be used to play the sound effect.
When the sound effect finishes playing, all channels will be used for the background music again.
s | Pointer to the music clip structure to be played as sound effect. |
void sound_set_bgm | ( | const struct sound_clip * | s | ) |
MSX
Sets the specified music clip as BGM in the sound driver.
s | Pointer to the music clip structure to be played as BGM. |
void sound_start | ( | void | ) |
MSX
Start the BGM.
void sound_stop | ( | void | ) |
MSX
Stop the BGM.
void sound_pause | ( | void | ) |
MSX
Pause the BGM.
void sound_player | ( | void | ) |
MSX
Main routine of the sound driver.
To play the background music and/or sound effects, you need to call this function at every VSYNC timing. The easiest way is to set this function as the VSYNC interrupt handler by calling set_vsync_handler().