The problem I'm having is that I keep getting an out of range error (note that im using the setSample and getSample with an extra number that respects what channel im operating on)
Code: Select all
local M = {}
M.Name = "Pitch Control"
M.Description = "Slows down, or speeds up a cut."
function M:Operate(Sound)
local Speed = math.random(0.5,2)
local SampleRate = Sound:getSampleRate()
local Duration = Sound:getSampleCount()
local Channels = Sound:getChannelCount()
local NewDuration = math.floor(Duration*Speed)-1
local NewSound = love.sound.newSoundData(
NewDuration,
SampleRate,
Sound:getBitDepth(),
Channels
)
for C=1,Channels,1 do
for I=1,NewDuration,1 do
local NormalizedI = I/NewDuration
local SampleIndex = math.floor(NormalizedI*Duration)
NewSound:setSample(I,C,Sound:getSample(SampleIndex,C))
end
end
return NewSound
end
return M
Code: Select all
NewSound:setSample(I,C,Sound:getSample(SampleIndex,C))