SetPitch
This function modulates the frequency of a playing sound. This affects the speed it plays at, as well as the perceived pitch.
Syntax
Parameters
- pitch: the new pitch to set.
Example
--Create a window
window = Window:Create()
context = Context:Create(window)
--Load a sound
local sound = Sound:Load("Sound/Music/menutheme.wav")
source = Source:Create()
source:SetSound(sound)
sound:Release()
source:SetLoopMode(true)
source:Play()
while true do
--Press up/down keys to alter pitch
local pitch = source:GetPitch()
if (window:KeyDown(Key.Up))then pitch=pitch+Time:GetSpeed()*0.01 end
if (window:KeyDown(Key.Down))then pitch=pitch-Time:GetSpeed()*0.01 end
source:SetPitch(pitch)
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
context:SetColor(0,0,0)
context:Clear()
context:SetColor(1,1,1)
context:SetBlendMode(Blend.Alpha)
context:DrawText("Pitch: "..source:GetPitch(),2,2)
context:Sync()
end