Are you a musician?
Register here
Mobilmenu

Working with Audio in ACE on Amiga

Amiga C Engine aka ACE is a game engine / framework / support library written totally in C for classic Amiga hardware.

ACE provides audio capabilities through integrated PTPlayer by Frank Wille rewritten to C for better integration with ACE features. The basic capabilities are:

You can also combine it with 3rd party audio mixers for squeezing out more out of the audio playback.

Using ptplayerSetChannelsForPlayer() will limit ptplayer channel management to only few channels, leaving others intact for e.g. audio mixer to use.

Amiga-Specific Considerations

Initialization and Configuration

In your main or gamestate create function, do the following:

// Initialize (1 = PAL mode, 0 = NTSC) ptplayerCreate(1); // Optional: Configure which channels are reserved for music ptplayerSetMusicChannelMask(0b0011); // Reserves channels 0 and 1 for music // Optional: Set master volume ptplayerSetMasterVolume(48); // Range is 0-64 // Optional: Configure song repeat behavior ptplayerConfigureSongRepeat(1, onSongEnd);

To play the music in your game, in your main or gamestate create function:

// Load a MOD file tPtplayerMod *pMod = ptplayerModCreateFromPath("music.mod"); // Start playback (2nd parameter is NULL to use samples from inside the MOD file, set start position to 0) ptplayerLoadMod(pMod, NULL, 0); // Enable music playback ptplayerEnableMusic(1);

While in the game loop, you might want to:

At the end of the gamestage or the game itself, do the following:

ptplayerStop(); ptplayerModDestroy(pMod); // When done with all audio ptplayerDestroy();

Playback performance will vary depending on:

Playing Sound Effects

To load a sound effect, be sure to have a .sfx file generated by audio_conv tool.

Manage the sound effect by calling:

tPtplayerSfx *pSfx = ptplayerSfxCreateFromPath("explosion.sfx", 0); // When done with the sound effect, after your game loop ends: ptplayerSfxDestroy(pSfx);

To play the sound effect:

ptplayerSfxPlay(pSfx, PTPLAYER_SFX_CHANNEL_ANY, PTPLAYER_VOLUME_MAX, 10); The SFX volume takes into account the volume set by ptplayerSetMasterVolume(). Setting the sfx volume to half of the range (32) with master volume set to 48 will scale it accordingly to 24.

You can also set the specific channel, as well as set the sound effect priority. When using PTPLAYER_SFX_CHANNEL_ANY, PTPlayer will use any free channel, if possible.

Higher priority sound effects will replace lower priority ones if needed.< By default, PTPlayer prioritizes sound effects over music - if you play the sound effect on a channel which is used by the .mod file, some music notes won't play. Because of that, it is strongly recommended to use PTPlayer to only play music on some channels and use a software audio mixer to play back the samples in remaining channel(s)

You can also stop the sound effects playing on given channel by calling ptplayerSfxStopOnChannel().

Advanced Features

Find more guides at github


Back to table of contents