![]() |
CRM64Pro GDK v0.18.0
A free cross-platform game development kit built on top of SDL 3.0
|
Audio Track Manager and AudioTrack objects for sound effects and music playback [v26.06.1].
The Audio Track module provides a unified audio system for loading and playing both short sound effects and long music tracks. Once the audio system is initialized using ConfigMgr::audioInit() or ConfigMgr::load(), you can load audio from external files, memory buffers, or CDC archives.
There are no longer fixed "channels". Tracks are allocated dynamically as needed, allowing for high polyphony (limited by CPU/RAM and the mixer/device capacity).
| Playback | Play (supports multiple overlapping instances), stop, pause and resume |
|---|---|
| Transitions | Fade out and fade in on a given time |
| Playback control | Pitch/speed, repeat playback, loop points and seeking active playback |
| Effects | Volume, panning, spatial distance and angular position |
Choose the appropriate loading strategy based on your audio content type and performance requirements:
| Preload (RAM) | Best for SFX. Decodes the entire source to memory for low-latency playback. Limited to INT32_MAX source bytes (2 GiB) |
|---|---|
| Stream (Disk) | Best for Music and very large files. Decodes chunks from external files on-demand to save memory |
CDC AudioTrack resources and memory buffers use preload/RAM loading logic. CDC streaming is not supported.
| Raw streams | AIFF, WAV and VOC |
|---|---|
| Compressed | FLAC, OGG and MP3 |
| Modules (52) | 669, abk, amf, arch, asylum, chip, coco, dbm, digi, dt, emod, far, flt, fnk, gal4, gal5, gdm, hmn, ice, imf, ims, it, liq, masi, masi16, mdl, med2, med3, med4, mfp, mgt, mmd1, mmd3, mod, mtm, muse, no, okt, pt3, ptm, rtm, s3m, sfx, st, stim, stm, stx, sym, ult, umx, xm, xmf |
This is a sharing manager: it can share an AudioTrack ID with a group of owners when they request to open an already opened object based on the name as the key.
| Default behavior | Returns a shared AudioTrack ID. Control methods (stop/volume) affect all instances sharing this ID |
|---|---|
| Unique instance | Request via load(..., bForceNew = true). Creates a standalone object with independent control while efficiently sharing the underlying decoded/preloaded audio resource when the source key matches |
Resource names are restricted to prevent collisions with system assets. The characters '#' and '@' are reserved for internal engine use. Any attempt to create or rename a resource starting with these characters will be rejected (returning a negative error code).
Classes | |
| struct | CRM64Pro::AudioInfo |
| Audio metadata information. More... | |
| class | CRM64Pro::AudioTrack |
| Audio Track object class. More... | |
| class | CRM64Pro::AudioTrackMgr |
| Audio Track Manager class. More... | |
Enumerations | |
| enum | CRM64Pro::eAudioTrackTag : Sint32 { CRM64Pro::ATT_MUSIC = 1 , CRM64Pro::ATT_SFX , CRM64Pro::ATT_VOICE , CRM64Pro::ATT_CUSTOM } |
| Audio track category tag for grouping and batch operations. One value must be selected; values are not bitmask flags. More... | |
| enum | CRM64Pro::eAudioType : Sint32 { CRM64Pro::AT_NONE = 0 , CRM64Pro::AT_WAV = 1 , CRM64Pro::AT_MOD = 2 , CRM64Pro::AT_OGG = 3 , CRM64Pro::AT_MP3 = 4 , CRM64Pro::AT_FLAC = 5 , CRM64Pro::AT_UNKNOWN = 6 } |
| Audio codec/format type. More... | |
| enum | CRM64Pro::eAudioLoadMode : Sint32 { CRM64Pro::ALM_AUTO = 0 , CRM64Pro::ALM_PRELOAD = 1 , CRM64Pro::ALM_STREAM = 2 } |
| Audio loading strategy. More... | |
Functions | |
| bool | CRM64Pro::AudioTrack::info (Sint32 iMode=0) override |
| Request AudioTrack information. | |
| const string & | CRM64Pro::AudioTrack::getName () const override |
| Get the name. | |
| Sint32 | CRM64Pro::AudioTrack::getID () const override |
| Get the ID. | |
| bool | CRM64Pro::AudioTrack::getInfo (string *sType, AudioInfo *pAI) const |
| Get AudioTrack detailed information. | |
| Sint32 | CRM64Pro::AudioTrack::play (Sint32 iRepeats=0) |
| Play the track. | |
| Sint32 | CRM64Pro::AudioTrack::fadeIn (Sint32 iTimeMS=1000, Sint32 iRepeats=0) |
| Play the track with a fade-in effect. | |
| bool | CRM64Pro::AudioTrack::fadeOut (Sint32 iTimeMS=1000) |
| Fade out all instances of this track to silence, then stop. | |
| bool | CRM64Pro::AudioTrack::stop () |
| Immediately stop all instances of this track. | |
| bool | CRM64Pro::AudioTrack::pause () |
| Pause all instances of this track. | |
| bool | CRM64Pro::AudioTrack::resume () |
| Resume all instances of this track. | |
| ePlaybackStatus | CRM64Pro::AudioTrack::status () const |
| Get the playback status. | |
| Sint32 | CRM64Pro::AudioTrack::getPlaybackPosition () const |
| Get the current playback position. | |
| bool | CRM64Pro::AudioTrack::seek (Sint32 iTimeMS) |
| Seek the active playback instance. | |
| bool | CRM64Pro::AudioTrack::setPitch (float fPitch) |
| Set Pitch (Frequency Ratio). | |
| float | CRM64Pro::AudioTrack::getPitch () const |
| Get current pitch property. | |
| bool | CRM64Pro::AudioTrack::setPanning (Uint8 iLeft, Uint8 iRight) |
| Set Stereo Panning. | |
| bool | CRM64Pro::AudioTrack::getPanning (Uint8 *iLeft, Uint8 *iRight) const |
| Get stereo panning. | |
| bool | CRM64Pro::AudioTrack::setLoopPoints (double dStartSec, double dEndSec) |
| Set Loop Points. | |
| bool | CRM64Pro::AudioTrack::getLoopPoints (double *dStartSec, double *dEndSec) const |
| Get loop points. | |
| bool | CRM64Pro::AudioTrack::setSpatialDistance (Uint8 iDistance) |
| Set spatial distance attenuation. | |
| Uint8 | CRM64Pro::AudioTrack::getSpatialDistance () const |
| Get spatial distance attenuation. | |
| bool | CRM64Pro::AudioTrack::setSpatialPosition (Sint16 iAngle, Uint8 iDistance) |
| Set spatial position. | |
| bool | CRM64Pro::AudioTrack::getSpatialPosition (Sint16 *iAngle, Uint8 *iDistance) const |
| Get spatial position. | |
| bool | CRM64Pro::AudioTrack::setTag (eAudioTrackTag eTag) |
| Set audio tag category. | |
| eAudioTrackTag | CRM64Pro::AudioTrack::getTag () const |
| Get audio tag category. | |
| Sint32 | CRM64Pro::AudioTrack::saveToFile (const string &sFile) |
| Export the AudioTrack to an external file. | |
| Sint32 | CRM64Pro::AudioTrack::save (const string &sCDCFile, const string &sResourceName="") |
| Save the AudioTrack into a CDC file. | |
| Sint32 | CRM64Pro::AudioTrack::save (Sint32 idCDC, const string &sResourceName="") |
| Save the AudioTrack into a CDC file. | |
| bool | CRM64Pro::AudioTrackMgr::info (Sint32 iMode=0) override |
| Request AudioTrack Manager information. | |
| Sint32 | CRM64Pro::AudioTrackMgr::close (Sint32 idAudio=0) override |
| Close and destroy an AudioTrack. | |
| Sint32 | CRM64Pro::AudioTrackMgr::getCount () const override |
| Get number of loaded objects. | |
| Sint32 | CRM64Pro::AudioTrackMgr::setName (Sint32 idAudio, const string &sName) override |
| Change the object name. | |
| AudioTrack * | CRM64Pro::AudioTrackMgr::get (Sint32 idAudio) |
| Get a pointer to the AudioTrack using its handle. | |
| bool | CRM64Pro::AudioTrackMgr::stopAll () |
| Immediately stop all active audio tracks. | |
| bool | CRM64Pro::AudioTrackMgr::fadeOutAll (Sint32 iTimeMS=1000) |
| Fade out all active audio tracks to silence, then stop. | |
| bool | CRM64Pro::AudioTrackMgr::pauseAll () |
| Pause all active audio tracks. | |
| bool | CRM64Pro::AudioTrackMgr::resumeAll () |
| Resume all paused audio tracks. | |
| bool | CRM64Pro::AudioTrackMgr::stopTag (eAudioTrackTag eTag) |
| Stop all tracks with the given audio track tag. | |
| bool | CRM64Pro::AudioTrackMgr::fadeOutTag (eAudioTrackTag eTag, Sint32 iTimeMS=1000) |
| Fade out all tracks with the given audio track tag. | |
| bool | CRM64Pro::AudioTrackMgr::pauseTag (eAudioTrackTag eTag) |
| Pause all tracks with the given audio track tag. | |
| bool | CRM64Pro::AudioTrackMgr::resumeTag (eAudioTrackTag eTag) |
| Resume all tracks with the given audio track tag. | |
| bool | CRM64Pro::AudioTrackMgr::setKeepSourceData (bool bKeep) |
| Set the global policy for keeping raw source data in memory. | |
| bool | CRM64Pro::AudioTrackMgr::getKeepSourceData () const |
| Get the current policy for keeping raw source data. | |
| Sint32 | CRM64Pro::AudioTrackMgr::loadFromFile (const string &sFile, const string &sName="", eAudioTrackTag eTag=ATT_SFX, eAudioLoadMode eMode=ALM_AUTO, bool bForceNew=false) |
| Load an AudioTrack from an external file. | |
| Sint32 | CRM64Pro::AudioTrackMgr::load (const string &sCDCFile, const string &sName, bool bForceNew=false) |
| Load an AudioTrack from a CDC file (by file name). | |
| Sint32 | CRM64Pro::AudioTrackMgr::load (Sint32 idCDC, const string &sName, bool bForceNew=false) |
| Load an AudioTrack from a CDC file (by ID). | |
| Sint32 | CRM64Pro::AudioTrackMgr::loadFromBuffer (const void *pBuffer, Sint32 iSize, const string &sName, const string &sFormat, eAudioTrackTag eTag=ATT_SFX) |
| Load an AudioTrack from a raw memory buffer. | |
| Sint32 | CRM64Pro::AudioTrackMgr::remove (Sint32 idCDC, const string &sName) |
| Remove an AudioTrack stored in a CDC file. | |
| bool | CRM64Pro::AudioTrackMgr::exists (Sint32 idCDC, const string &sName) const |
| Check if an AudioTrack is stored in a CDC file. | |
| bool | CRM64Pro::AudioTrackMgr::exists (const string &sCDCFile, const string &sName) const |
| Check if an AudioTrack is stored in a CDC file. | |
| enum CRM64Pro::eAudioTrackTag : Sint32 |
| enum CRM64Pro::eAudioType : Sint32 |
| enum CRM64Pro::eAudioLoadMode : Sint32 |
|
override |
Request AudioTrack information.
Writes information to the default log.
| iMode | Reserved for future use. Pass 0. |
|
override |
Get the name.
|
override |
Get the ID.
| bool CRM64Pro::AudioTrack::getInfo | ( | string * | sType, |
| AudioInfo * | pAI ) const |
Get AudioTrack detailed information.
| sType | a string pointer filled with the input file extension. If nullptr, this value is not retrieved. |
| pAI | a pointer to an AudioInfo struct. If nullptr, this struct is not retrieved. |
| Sint32 CRM64Pro::AudioTrack::play | ( | Sint32 | iRepeats = 0 | ) |
Play the track.
| iRepeats | Number of extra repeats after the first play. 0 plays once, -1 repeats forever. |
| Sint32 CRM64Pro::AudioTrack::fadeIn | ( | Sint32 | iTimeMS = 1000, |
| Sint32 | iRepeats = 0 ) |
Play the track with a fade-in effect.
Creates a new hardware track, assigns the audio data, applies current properties (Gain, Pitch, Pan), and starts playback.
| iTimeMS | Time in milliseconds for the fade-in effect. 0 for instant playback. |
| iRepeats | Number of extra repeats after the first play. 0 plays once, -1 repeats forever. |
| bool CRM64Pro::AudioTrack::fadeOut | ( | Sint32 | iTimeMS = 1000 | ) |
Fade out all instances of this track to silence, then stop.
| iTimeMS | Time in milliseconds for the fade-out effect. |
| bool CRM64Pro::AudioTrack::stop | ( | ) |
Immediately stop all instances of this track.
| bool CRM64Pro::AudioTrack::pause | ( | ) |
Pause all instances of this track.
| bool CRM64Pro::AudioTrack::resume | ( | ) |
Resume all instances of this track.
| ePlaybackStatus CRM64Pro::AudioTrack::status | ( | ) | const |
Get the playback status.
| Sint32 CRM64Pro::AudioTrack::getPlaybackPosition | ( | ) | const |
Get the current playback position.
Retrieves the current time position of the active primary playback instance.
| bool CRM64Pro::AudioTrack::seek | ( | Sint32 | iTimeMS | ) |
Seek the active playback instance.
Seeks the active primary playback instance to a specific time in the audio track.
| iTimeMS | The position in milliseconds to seek to. |
| bool CRM64Pro::AudioTrack::setPitch | ( | float | fPitch | ) |
Set Pitch (Frequency Ratio).
Sets the pitch for future playbacks. If the track is currently playing, it updates the sound immediately.
| fPitch | 1.0f = Normal, 0.5f = Half speed, 2.0f = Double speed. |
| float CRM64Pro::AudioTrack::getPitch | ( | ) | const |
Get current pitch property.
| bool CRM64Pro::AudioTrack::setPanning | ( | Uint8 | iLeft, |
| Uint8 | iRight ) |
Set Stereo Panning.
Sets panning for future playbacks. If the track is currently playing, it updates the sound immediately.
| iLeft | 0-255. |
| iRight | 0-255. |
| bool CRM64Pro::AudioTrack::getPanning | ( | Uint8 * | iLeft, |
| Uint8 * | iRight ) const |
Get stereo panning.
Retrieves the stored panning values used for future playback. Spatial positioning takes precedence during playback when spatial distance is greater than 0.
| iLeft | pointer to receive the left panning value [0,255]. |
| iRight | pointer to receive the right panning value [0,255]. |
| bool CRM64Pro::AudioTrack::setLoopPoints | ( | double | dStartSec, |
| double | dEndSec ) |
Set Loop Points.
Sets the loop region for future playbacks. Set both values below 0 to disable loop points. Otherwise the end value must be greater than the start value.
| dStartSec | Start of loop in seconds. |
| dEndSec | End of loop in seconds. |
| bool CRM64Pro::AudioTrack::getLoopPoints | ( | double * | dStartSec, |
| double * | dEndSec ) const |
Get loop points.
Retrieves the loop region used for future playbacks.
| dStartSec | pointer to receive the loop start in seconds, or -1.0 when disabled. |
| dEndSec | pointer to receive the loop end in seconds, or -1.0 when disabled. |
| bool CRM64Pro::AudioTrack::setSpatialDistance | ( | Uint8 | iDistance | ) |
Set spatial distance attenuation.
Sets the distance simulation for future playbacks. If the track is currently playing, it updates the sound immediately. SDL_mixer's distance effect attenuates volume as distance increases.
| iDistance | 0 (closest/loudest) to 255 (farthest/quietest). |
| Uint8 CRM64Pro::AudioTrack::getSpatialDistance | ( | ) | const |
Get spatial distance attenuation.
| bool CRM64Pro::AudioTrack::setSpatialPosition | ( | Sint16 | iAngle, |
| Uint8 | iDistance ) |
Set spatial position.
Sets the spatial audio position for future playbacks. If the track is currently playing, it updates the sound immediately. Simulates sound source direction relative to listener (at center).
| iAngle | Angle in degrees. Values are normalized to [0,359] (0 = front, 90 = right, 180 = back, 270 = left). |
| iDistance | Distance attenuation (0-255). |
| bool CRM64Pro::AudioTrack::getSpatialPosition | ( | Sint16 * | iAngle, |
| Uint8 * | iDistance ) const |
Get spatial position.
Retrieves the stored spatial audio position. Spatial positioning takes precedence over panning during playback when distance is greater than 0.
| iAngle | pointer to receive the normalized angle in degrees [0,359]. |
| iDistance | pointer to receive the distance attenuation [0,255]. |
| bool CRM64Pro::AudioTrack::setTag | ( | eAudioTrackTag | eTag | ) |
Set audio tag category.
Updates the audio tag category (Music, SFX, Voice, Custom) and immediately re-calculates gain for active instances. This allows changing a track from "SFX" to "Music" and having it adopt the Music volume level.
| eTag | The new tag category. |
| eAudioTrackTag CRM64Pro::AudioTrack::getTag | ( | ) | const |
Get audio tag category.
| Sint32 CRM64Pro::AudioTrack::saveToFile | ( | const string & | sFile | ) |
Export the AudioTrack to an external file.
| sFile | string containing the [directory]+filename. Extension is automatically corrected. |
| Sint32 CRM64Pro::AudioTrack::save | ( | const string & | sCDCFile, |
| const string & | sResourceName = "" ) |
Save the AudioTrack into a CDC file.
| sCDCFile | Path to the CDC archive. |
| sResourceName | Optional resource name to use in the CDC. If empty (default), uses the AudioTrack object's internal name. |
| Sint32 CRM64Pro::AudioTrack::save | ( | Sint32 | idCDC, |
| const string & | sResourceName = "" ) |
Save the AudioTrack into a CDC file.
| idCDC | CDC id. |
| sResourceName | Optional resource name to use in the CDC. If empty (default), uses the AudioTrack object's internal name. |
|
override |
Request AudioTrack Manager information.
Writes manager information to the default log.
| iMode | -1 to display only manager information. 0 (default) to display manager and all objects. A specific object ID displays manager information and only that object. |
|
override |
Close and destroy an AudioTrack.
| idAudio | 0 (default) for closing all tracks, or a specific AudioTrack id. If playing, it will be stopped immediately. |
|
override |
Get number of loaded objects.
|
override |
Change the object name.
| idAudio | AudioTrack id. |
| sName | The new name. Must be unique. |
| AudioTrack * CRM64Pro::AudioTrackMgr::get | ( | Sint32 | idAudio | ) |
Get a pointer to the AudioTrack using its handle.
| idAudio | AudioTrack id. |
| bool CRM64Pro::AudioTrackMgr::stopAll | ( | ) |
Immediately stop all active audio tracks.
Stops all playback on the mixer device.
| bool CRM64Pro::AudioTrackMgr::fadeOutAll | ( | Sint32 | iTimeMS = 1000 | ) |
Fade out all active audio tracks to silence, then stop.
| iTimeMS | Time in milliseconds for the fade-out effect. Default 1000ms. |
| bool CRM64Pro::AudioTrackMgr::pauseAll | ( | ) |
Pause all active audio tracks.
| bool CRM64Pro::AudioTrackMgr::resumeAll | ( | ) |
Resume all paused audio tracks.
| bool CRM64Pro::AudioTrackMgr::stopTag | ( | eAudioTrackTag | eTag | ) |
Stop all tracks with the given audio track tag.
Iterates through all managed AudioTrack objects with exactly the given tag and stops them.
| eTag | Single tag category to stop. Combined tag values are invalid. |
| bool CRM64Pro::AudioTrackMgr::fadeOutTag | ( | eAudioTrackTag | eTag, |
| Sint32 | iTimeMS = 1000 ) |
Fade out all tracks with the given audio track tag.
Iterates through all managed AudioTrack objects with exactly the given tag and fades them out.
| eTag | Single tag category to fade out. Combined tag values are invalid. |
| iTimeMS | Time in milliseconds for the fade-out effect. Default 1000ms. |
| bool CRM64Pro::AudioTrackMgr::pauseTag | ( | eAudioTrackTag | eTag | ) |
Pause all tracks with the given audio track tag.
Iterates through all managed AudioTrack objects with exactly the given tag and pauses them.
| eTag | Single tag category to pause. Combined tag values are invalid. |
| bool CRM64Pro::AudioTrackMgr::resumeTag | ( | eAudioTrackTag | eTag | ) |
Resume all tracks with the given audio track tag.
Iterates through all managed AudioTrack objects with exactly the given tag and resumes them.
| eTag | Single tag category to resume. Combined tag values are invalid. |
| bool CRM64Pro::AudioTrackMgr::setKeepSourceData | ( | bool | bKeep | ) |
Set the global policy for keeping raw source data in memory.
If enabled, subsequent load operations will cache the original raw bytes in RAM. This allows the use of AudioTrack::save() and AudioTrack::saveToFile().
| bKeep | true to cache raw data, false to discard it. |
| bool CRM64Pro::AudioTrackMgr::getKeepSourceData | ( | ) | const |
Get the current policy for keeping raw source data.
| Sint32 CRM64Pro::AudioTrackMgr::loadFromFile | ( | const string & | sFile, |
| const string & | sName = "", | ||
| eAudioTrackTag | eTag = ATT_SFX, | ||
| eAudioLoadMode | eMode = ALM_AUTO, | ||
| bool | bForceNew = false ) |
Load an AudioTrack from an external file.
| sFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| sName | Object name. If empty, filename is used (without extension). Must be shorter than 64 characters. |
| eTag | The tag category (SFX, Music, etc). |
| eMode | Loading strategy (Preload to RAM or Stream from disk). |
| bForceNew | true to force a new object creation with a unique generated name, false to return the existing object ID when the name already exists. |
| Sint32 CRM64Pro::AudioTrackMgr::load | ( | const string & | sCDCFile, |
| const string & | sName, | ||
| bool | bForceNew = false ) |
Load an AudioTrack from a CDC file (by file name).
| sCDCFile | Path to the CDC archive file. |
| sName | Object name. |
| bForceNew | true to force a new object creation with a unique generated name, false to return the existing object ID when the name already exists. |
| Sint32 CRM64Pro::AudioTrackMgr::load | ( | Sint32 | idCDC, |
| const string & | sName, | ||
| bool | bForceNew = false ) |
Load an AudioTrack from a CDC file (by ID).
| idCDC | CDC archive ID. |
| sName | Object name stored in the archive. |
| bForceNew | true to force a new object creation with a unique generated name, false to return the existing object ID when the name already exists. |
| Sint32 CRM64Pro::AudioTrackMgr::loadFromBuffer | ( | const void * | pBuffer, |
| Sint32 | iSize, | ||
| const string & | sName, | ||
| const string & | sFormat, | ||
| eAudioTrackTag | eTag = ATT_SFX ) |
Load an AudioTrack from a raw memory buffer.
| pBuffer | Pointer to the raw audio data (WAV, OGG, etc). |
| iSize | Size of the buffer in bytes. |
| sName | Object name. It will be used as source file name together with format. |
| sFormat | Audio format of the buffer (AIFF, WAV, VOC, OGG, FLAC, MP3, MOD, XM, S3M, etc). |
| eTag | The category tag (SFX, Music, etc). |
| Sint32 CRM64Pro::AudioTrackMgr::remove | ( | Sint32 | idCDC, |
| const string & | sName ) |
Remove an AudioTrack stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the AudioTrack name (shorter than 64 characters). |
| bool CRM64Pro::AudioTrackMgr::exists | ( | Sint32 | idCDC, |
| const string & | sName ) const |
Check if an AudioTrack is stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the AudioTrack name (shorter than 64 characters). |
| bool CRM64Pro::AudioTrackMgr::exists | ( | const string & | sCDCFile, |
| const string & | sName ) const |
Check if an AudioTrack is stored in a CDC file.
| sCDCFile | Path to the CDC archive file. |
| sName | string with the AudioTrack name (shorter than 64 characters). |