Giter Site home page Giter Site logo

soloudmodule's Introduction

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.

soloudmodule's People

Contributors

siudesu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

soloudmodule's Issues

Typo error in AUDIO.dispose.

filename_ should be fileName_.

function M.dispose(fileName_)
-- Solar2D API: audio.dispose( audioHandle )
	
-- Note: Destroying the audio will also stop the audio.
-- !Unlike the audio API, it is possible to destroy (without errors) an audio while it's already playing.
	
	-- Destroy audio if it exists.
	if cache[fileName_] then cache[fileName_].wavObj:destroy() end
	
	-- All channels that were playing the audio will be clear.
	-- clearAllChannels(filename_)
        clearAllChannels(fileName_)
	
	-- Clear cache.
	cache[fileName_] = nil
end

`AUDIO.findFreeChannel` should start with 1 in Lua when `startChannel_` is nil.

findFreeChannel should start with 1 in Lua when startChannel_ is nil.

function M.findFreeChannel(startChannel_)
	-- Solar2D API: audio.findFreeChannel( [ startChannel ] )
	-- Search will increase upwards from this channel. 0 or no parameter begins searching at the lowest possible value.
	-- The search does not include reserved channels.

	-- Returns 0 if no available channel found, else it returns next available channel.
	-- return getNextAvailableChannel(startChannel_ or 0) or 0
	return getNextAvailableChannel(startChannel_ or 1) or 0
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.