siudesu / SoLoudModule

Solar2D Lua module to use with SoLoud plugin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SoLoud Module

This Solar2D Lua module aims to be a drop-in replacement for the audio API using the SoLoud plugin.


Features


Limitations

  • Currently, SoLoud plugin is not available for Linux or Switch.
  • stopWithDelay() is not implemented. The same effect can be accomplished outside this module with a timer and AUDIO.stop()
  • fadeOut() is not implemented. The same effect can be accomplished outside this module with AUDIO.fade() and a timer to perform AUDIO.stop().

Requirements

build.settings (Plugins section)

	plugins =
	{
		["plugin.soloud"] = {publisherId = "com.xibalbastudios"},
	}

Usage

Load module and play audio sound:

-- You may replace the original audio library reference with this module without making additional changes to your project:

audio = require( "m_soloud_audio" )

local sfx1 = audio.loadSound( "soundFile.mp3" )
	audio.play( sfx1 )


-- or, load the module with any variable name without replacing the original audio library:

local AUDIO = require( "m_soloud_audio" )

local sfx1 = AUDIO.loadSound( "soundFile.mp3" )
	AUDIO.play( sfx1 )

Loading audio from archive:

-- Assumes a binary archive has been loaded with audio files used below.

-- Load SoLoud Module
local AUDIO = require( "m_soloud_audio" )

-- Fetch audio data from archive and insert it into a table (it's passed by reference)
local BGM_Data = { bin.fetch( "audio/BGM 01.mp3" )}
local SFX_Data = { bin.fetch( "audio/SFX/Ding.ogg" )}

-- Create audio stream object
local BGM1 = AUDIO.loadStreamFromArchive( "audio/BGM 01.mp3", BGM_Data )

-- Create audio sound object using the same filename and path as reference
local SFX1 = AUDIO.loadSoundFromArchive( "audio/SFX/Ding.ogg", SFX_Data )

-- Play BGM on channel 1
AUDIO.play( BGM1, { channel=1 })

-- Play SFX on any available channel
AUDIO.play( SFX1 )

Function List - same as Solar2D audio API:

MODULE.dispose( audioHandle )
MODULE.fade( { channel=num, time=num, volume=num } )
MODULE.findFreeChannel( startChannel )
MODULE.getDuration( audioHandle )
MODULE.getMaxVolume( { channel=num } )
MODULE.getMinVolume( { channel=num } )
MODULE.getVolume( { channel=num } )
MODULE.isChannelActive( channel )
MODULE.isChannelPaused( channel )
MODULE.isChannelPlaying( channel )
MODULE.loadSound( audioFileName )
MODULE.loadStream( audioFileName )
MODULE.pause( channel )
MODULE.play( audioHandle, { channel=num, loops=num, duration=num, fadein=num, onComplete=function, pitch=num } )
MODULE.reserveChannels( channels )
MODULE.resume( channel )
MODULE.rewind( audioHandle or { channel=num } )
MODULE.seek( time, audioHandle or { channel=num } )
MODULE.setMaxVolume( volume, { channel=num } )
MODULE.setMinVolume( volume, { channel=num } )
MODULE.setVolume( volume, { channel=num } )
MODULE.stop( channel )

Extra Audio Functions:

MODULE.setPitch( channel, pitchValue )
MODULE.setSpeed( channel, speedValue )

Binary Archive Functions

MODULE.loadSoundFromArchive( filename, data )
MODULE.loadStreamFromArchive( filename, data )

Properties (Read Only):

MODULE.freeChannels
MODULE.totalChannels
MODULE.unreservedFreeChannels
MODULE.unreservedUsedChannels
MODULE.usedChannels

License

Distributed under the MIT License. See LICENSE for more information.

About

Solar2D Lua module to use with SoLoud plugin.

License:MIT License


Languages

Language:Lua 100.0%