lovesid is a MOS Technology 6581/8580 SID (Sound Interface Device) emulator for use with LÖVE Framework. It may be used to play .sid files or in Commodore 64 emulators (or rather any computer using the chip) to generate sound.
Clone the repo or copy the raw file lovesid.lua into your project and require it. To generate sound, all you have to do is modify the registers and call play on the mixer. The library handles producing and playing the sound via love.audio and love.sound.
Should you use YueScript in your project, you can copy the raw file lovesid.yue and import it.
Below is an example usage with Lua:
-- main.lua
-- this file will play a simple triangle wave on channel 1
local lovesid = require("lovesid")
local Sid = lovesid.Sid
local SidMixer = lovesid.SidMixer
local sid = Sid() -- make a new Sid instance
local mixer = SidMixer()
mixer:addSid(sid) -- add the instance to the mixer
-- initialize the registers
sid[1] = 0x00 -- ch1 freq lo
sid[2] = 0x40 -- ch1 freq hi
sid[5] = 0x11 -- ch1 triangle wave, gate open
sid[6] = 0xa0 -- ch1 attack and decay
sid[7] = 0xf0 -- ch1 sustain and release
sid[25] = 0x0f -- global volume high, no filter
function love.update()
mixer:play() -- call continuously to make sound
endYou can also use the library with YueScript:
-- main.yue (to be transpiled to main.lua)
-- this file will play a simple triangle wave on channel 1
import Sid, SidMixer from "lovesid"
sid = Sid! -- make a new Sid instance
mixer = SidMixer!
mixer\addSid sid -- add the instance to the mixer
-- initialize the registers
sid[1] = 0x00 -- ch1 freq lo
sid[2] = 0x40 -- ch1 freq hi
sid[5] = 0x11 -- ch1 triangle wave, gate open
sid[6] = 0xa0 -- ch1 attack and decay
sid[7] = 0xf0 -- ch1 sustain and release
sid[25] = 0x0f -- global volume high, no filter
love.update = ()->
mixer\play! -- call continuously to make soundIn the Commodore 64, the SID chip's registers start at address $d400, but in lovesid it starts from 1. This necessitates offsetting the address for use when emulating machines.
sid[realAddress - 0xd3ff] = value
You may define as many instances of Sid as you like, which are fully seperated. This may be useful for stereo SID tracks.
- Currently the library is in a shift from plain Lua to YueScript and instancing architecture, so breaking API changes will happen.
- ADSR and filters have inaccuracies for the time being