sound.inc
sound.inc
CPP1/****n* PawnLibs/sound/SND_getAssetId2 * Summary3 * Get a sound ID by the filename.4 * Synopsis5 */6native SND_getAssetId(const name[]);7/*8 * Description9 * Usually an application uses sound IDs to start playback. TBD: SDK should10 * have way to specify ID for sound/image. But sometimes IDs are unknown, e.g.11 * in common libraries, or they change rapidly during development. This12 * interface can be used to get an ID of the sound by its filename in the13 * runtime. Recommended way is to use this function in initialization code.14 * Maximum asset name length is 15 characters remaining symbols are truncated15 * during lookup.16 * Inputs17 * * name - sound filename for which ID is requested18 * Return value19 * The ID of sound with a given filename or -1 in case of error.20 * See also21 * * SND_play()22 * * ON_Init()23 * History24 * * v5.0 - renamed from SND_getId() to SND_getAssetId()25 * * v6.0 - truncate asset name in WASM API26 ******/2728/****n* PawnLibs/sound/SND_play29 * Summary30 * Play sound by ID.31 * Synopsis32 */33native SND_play(const id, const volume);34/*35 * Description36 * Play any sound by its ID. Platform does not support audio mixing, so37 * previously playing sound will be stopped if it has not yet finished.38 * Supported audio formats:39 * * WAV40 * * MP341 * * MIDI42 * Inputs43 * * id - an ID of sound to play44 * * volume - volume of sound in percents to play, range 0..10045 * See also46 * * SND_getAssetId()47 ******/4849/****n* PawnLibs/sound/SND_cacheSounds50 * Summary51 * Force platform to cache application sounds.52 * Synopsis53 */54native SND_cacheSounds(soundList[], size = sizeof(soundList));55/*56 * Description57 * Platform automatically reads and caches sounds from flash when the58 * application plays a sound. Flash operations are synchronous and may cause59 * delays especially when reading large portions of data. To prevent the60 * application from lags it is possible to cache sound data in advance.61 * However if application requests to play a non-cached sound and there is not62 * enough memory then oldest accessed sounds will be removed from cache. Also63 * there is a limit of 256 for a total number of cached sounds.64 * Inputs65 * * soundList - array with IDs of sounds to cache66 * * size - size of soundList array67 * Return value68 * Number of cached sounds or negative value if an error happened. Error69 * codes:70 * * -1 invalid function arguments count71 * * -2 invalid soundList array72 * History73 * * v5.0 - moved from appCtrl module to sound74 ******/7576/****n* PawnLibs/sound/SND_isPlaying77 * Summary78 * Check if audio is playing.79 * Synopsis80 */81native bool:SND_isPlaying();82/*83 * Return value84 * True if audio is playing, false otherwise.85 * History86 * * v6.0 - added87 ******/8889/****n* PawnLibs/sound/SND_stop90 * Summary91 * Stop playing sound if any.92 * Synopsis93 */94native SND_stop();95/*96 * See also97 * * SND_play()98 * History99 * * v6.0 - added100 ******/101102/****n* PawnLibs/sound/SND_getAssetsCount103 * Summary104 * Get the total count of sound assets.105 * Synopsis106 */107native SND_getAssetsCount();108/*109 * Return value110 * Number of sound assets.111 * History112 * * v6.0 - added113 ******/114115 /****f* PawnLibs/sound/PlayRandomSound116 * Summary117 * Play random sound from an array.118 * Synopsis119 */120stock bool:PlayRandomSound(const snd[], const volume, const bool: stopPlaying = true, size = sizeof(snd))121/*122 * Description123 * Play random sound from an array.124 * Inputs125 * * snd - the array of sounds from which the sound will be selected126 * * volume - sound volume127 * * stopPlaying - stop sound playback if it is being played128 * * size - size of the array snd129 * Return value130 * See also131 * * PlayLoopRandomSound()132 * Source133 */134{135 if (SND_isPlaying()) {136 if (stopPlaying) {137 SND_stop();138 } else {139 return false;140 }141 }142143 SND_play(snd[random(0, size - 1)], volume);144 return true;145}146/******/147148/****f* PawnLibs/sound/PlayLoopRandomSound149 * Summary150 * Play random sound from an array in a loop with a specified delay range.151 * Synopsis152 */153stock PlayLoopRandomSound(const snd[], const volume, const delayMin, const delayMax, dt, size = sizeof(snd))154/*155 * Description156 * Play random sound from an array in a loop with a specified delay range.157 * Inputs158 * * snd - the array of sounds from which the sound will be selected159 * * volume - sound volume160 * * delayMin - minimum delay161 * * delayMax - maximum delay162 * * dt - delta time163 * * size - size of the array snd164 * Return value165 * See also166 * * PlayRandomSound()167 * Source168 */169{170 static delay = 0;171172 if (SND_isPlaying())173 return;174175 if (delay <= 0) {176 delay = random(delayMin, delayMax);177 } else {178 delay -= dt;179 }180181 SND_play(snd[random(0, size - 1)], volume);182}183/******/184
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.