Sound:setFrames

Writes frames to the Sound.

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

Arguments

NameTypeDefaultDescription
ttableA table containing frames to write.
countnumbernilHow many frames to write. If nil, writes as many as possible.
dstOffsetnumber0A frame offset to apply when writing the frames.
srcOffsetnumber0A frame, byte, or index offset to apply when reading frames from the source.

Returns

NameTypeDescription
countnumberThe number of frames written.

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

Arguments

NameTypeDefaultDescription
blobBlobA Blob containing frames to write.
countnumbernilHow many frames to write. If nil, writes as many as possible.
dstOffsetnumber0A frame offset to apply when writing the frames.
srcOffsetnumber0A frame, byte, or index offset to apply when reading frames from the source.

Returns

NameTypeDescription
countnumberThe number of frames written.

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

Arguments

NameTypeDefaultDescription
soundSoundAnother Sound to copy frames from.
countnumbernilHow many frames to write. If nil, writes as many as possible.
dstOffsetnumber0A frame offset to apply when writing the frames.
srcOffsetnumber0A frame, byte, or index offset to apply when reading frames from the source.

Returns

NameTypeDescription
countnumberThe 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