background image
C H A P T E R 1 4
Sound
Using Sound
14-9
Pitch Shifting
14
In general, you can set the value of a sound frame's
samplingRate
slot to any
float value less than that specified by the
kFloat22kRate
constant. However, this
usually results in poor sound quality. What generally works best is to take an 11
kHz sound and play it at some higher rate. Of course, 22 kHz sound resources
cannot be played at any higher sampling rate.
You can experiment with pitch shifting by playing sounds in the Inspector using
the
PlaySoundSync
function. You can use any of the ROM sounds or your own
custom sounds. The following example shows how to shift a sound's pitch by
altering the value of the sound frame's
samplingRate
slot. Remember when
setting this slot that
samplingRate
must be a value of type
float
.
// keep a copy of original for future use
origSound := clone(ROM_simpleBeep);
// make a copy to modify
mySound := Clone(origSound);
// play the original sound
PlaySoundSync(mySound);
// play at half original pitch
mySound.samplingRate := origSound.samplingRate/2;
PlaySoundSync(mySound);
// note how easily we can return to normal pitch
mySound.samplingRate := origSound.samplingRate;
// play at twice speed
mySound.samplingRate := origSound.samplingRate*2;
PlaySoundSync(mySound);
By using the output from a control view to alter the value of the sound frame's
samplingRate
slot, you can allow the user to interactively modify the pitch of
playback. The following example code changes the value of the
samplingRate
slot according to the setting of a
protoSlider
view:
theSlider.changedSlider := func()begin
if viewValue = maxValue then
mySound.samplingRate := originalRate
else mySound.samplingRate := (viewValue*1.01);
PlaySoundSync(mySound);
end
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна