Litsound - Doge2Dev/LitiumVM GitHub Wiki

Litsound

Is the main function o generate sounds with tones

litsound.newWave()

Generate a simple tone based on pre-defined tones

Usage

litsound.newWave(waveLength, toneid, waveType)
Parameter Description
waveLength How much time the tone will play
toneID the id for a pre-defined tone
waveType wave type

here a list of all supported wave types

Wave types
Square
Sine

here the table for all ID notes

ID Tones Frequency
1 264 C
2 297 D
3 330 E
4 352 F
5 396 G
6 440 A
7 495 B

Example:

function start()
	-- create a noise with length or 3 (represent : 0,09375 ms), tone id with 2 (D) and type "square"
	litsound.newWave(3, 2, "square")
end

litsound.newWaveFrequency()

Generate a sound based on specific frequency Usage

litsound.newWaveFrequency(waveLength, frequency, waveType)
Parameter Description
waveLength How much time the tone will play
frequency define the tone frequency
waveType wave type

here a list of all supported wave types

Wave types
Square
Sine

Example :

function start()
	-- generate a sound with wave length of 3 (which represent 0,09375ms) with frequency 297 (D) and wave type "square"
	litsound.newWaveFrequency(3, 297, "square")
end

litsound.playTrack()

Play a track based on table Usage

litsound.playTrack(tracktable)

Example:

function start()
	myCoolSong = {
		{5, 264, "square", 20},
		{5, 297, "square", 20},
		{5, 330, "square", 20},
		{5, 352, "square", 20},
		{5, 396, "square", 20},
		{5, 440, "square", 20},
		{5, 495, "square", 20}
	}
end
function update()
	litsound.playTrack(myCoolSong)
end

Control Functions

These functions control everything about the module

litsound:pause()

Pause the current song

Example :

litsound:pause()

litsound:resume()

Resume the current song

Example :

litsound:resume()

[Subtopic] - Creating a song table

To create a song table first initialize it

mysong = {}

Now for every note you want add to your song, you need create a new table inside of the main one.

mysong = {
	{param1, param2, param3, param4},	--note 1
	{param1, param2, param3, param4},	--note 2
	{param1, param2, param3, param4}	--note 3
}
Descriptor Parameter Description
param1 Wave Length How much time the tone will play
param2 Tone (Frequency) The frequency of the note
param3 Wave Type The wave type (sqaure or sine)
param4 Delay (ms) How much it need wait berofe play next note

And that is, just fill the parameters for each note, and you have a song (or SFX)

function start()
	mysong = {
		{5, 264, "square", 20},
		{5, 297, "square", 20},
		{5, 330, "square", 20},
		{5, 352, "square", 20},
		{5, 396, "square", 20},
		{5, 440, "square", 20},
		{5, 495, "square", 20}
	}
end