Sound:setFrames

Edit

Writes frames to the Sound.

count = Sound:setFrames(source, count, dstOffset, srcOffset)

Arguments

NameTypeDefaultDescription
sourcetable | Blob | Sound A table, Blob, or Sound containing audio frames to write.
countnumbernil How many frames to write. If nil, writes as many as possible.
dstOffsetnumber0 A frame offset to apply when writing the frames.
srcOffsetnumber0 A frame, byte, or index offset to apply when reading frames from the source.

Returns

NameTypeDescription
countnumber The number of frames written.

Example

Generate a sine wave.

function lovr.load()
  local length = 1
  local rate = 48000
  local frames = length * rate
  local frequency = 440
  local volume = 1.0

  sound = lovr.data.newSound(frames, 'f32', 'stereo', rate)

  local data = {}
  for i = 1, frames do
    local amplitude = math.sin((i - 1) * frequency / rate * (2 * math.pi)) * volume
    data[2 * i - 1] = amplitude
    data[2 * i - 0] = amplitude
  end

  sound:setFrames(data)

  source = lovr.audio.newSource(sound)
  source:setLooping(true)
  source:play()
end

See also