This function can be used to change the pitch of a given sound. The sound can either be one referenced from an index for an individual sound being played which has been stored in a variable when using the audio_play_sound or audio_play_sound_at functions, or an actual sound asset from the resource tree. If it is an index of a playing sound, then only that instance will be changed, however when using a sound asset from the resource tree, all further instances being played of that sound will be changed.
The pitch argument is a pitch multiplier, in that the input value multiplies the current pitch by that amount, so the default value of 1 is no pitch change, while a value of less than 1 will lower the pitch and greater than 1 will raise the pitch. 最好对此函数使用小增量,因为任何低于0或大于5的值都可能无法听到。值得注意的是,允许的总音调的变化被钳制到(1/256) - 256个八度音程,因此任何高于或低于此值的变化都不会被记录。
NOTE: The clamped value given above is what GameMaker Studio 2 attempts to clamp the range to, but this value is not guaranteed on all target platforms. 例如,iOS会钳制到(1/256) - 8,因此你可能需要在每个目标平台上进行试验并拥有不同版本的声音资源,如果你需要更高或更低的八度音程值,每个版本都需要预先移位。
audio_sound_pitch(index, pitch);
参数 | 描述 |
---|---|
index | The index of the sound to change. |
音调值 | The pitch multiplier (default 1). |
N/A(无返回值)
var s_engine = audio_play_sound(snd_CarEngine, 10, false);
switch (gear)
{
case 1: audio_sound_pitch(s_engine, 0.8); break;
case 2: audio_sound_pitch(s_engine, 0.9); break;
case 3: audio_sound_pitch(s_engine, 0.95); break;
case 4: audio_sound_pitch(s_engine, 1); break;
case 5: audio_sound_pitch(s_engine, 1.2); break;
}
The above code will change the pitch of the audio played from the sound indexed in the variable "s_engine" based on the value of the variable "gear".