Difference between revisions of "love.audio.newSource"

m
Line 1: Line 1:
Creates a new [[Source]] from a filepath, [[File]], [[SoundData]], or [[Decoder]].
+
Creates a new [[Source]] from a filepath, [[File]], [[Decoder]] or [[SoundData]].
 
Sources created from SoundData are always static.
 
Sources created from SoundData are always static.
 
{{newobjectnotice}}
 
{{newobjectnotice}}
 +
== Function ==
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( filename )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|filename|The filepath to the audio file.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio. The [[SourceType]] of the returned audio is "stream".}}
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 12: Line 21:
 
=== Returns ===
 
=== Returns ===
 
{{param|Source|source|A new Source that can play the specified audio.}}
 
{{param|Source|source|A new Source that can play the specified audio.}}
 +
== Function ==
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( file )
 +
</source>
 +
=== Arguments ===
 +
{{param|File|file|A File pointing to an audio file.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio. The [[SourceType]] of the returned audio is "stream".}}
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 25: Line 43:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
source = love.audio.newSource( data )
+
source = love.audio.newSource( decoder )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|SoundData|data|The SoundData to create a Source from.}}
+
{{param|Decoder|decoder|The Decoder to create a Source from.}}
 
=== Returns ===
 
=== Returns ===
{{param|Source|source|A new Source that can play the specified audio. The [[SourceType]] of the returned audio is "static".}}
+
{{param|Source|source|A new Source that can play the specified audio. The [[SourceType]] of the returned audio is "stream".}}
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 41: Line 59:
 
=== Returns ===
 
=== Returns ===
 
{{param|Source|source|A new Source that can play the specified audio.}}
 
{{param|Source|source|A new Source that can play the specified audio.}}
 +
== Function ==
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( data )
 +
</source>
 +
=== Arguments ===
 +
{{param|SoundData|data|The SoundData to create a Source from.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio. The [[SourceType]] of the returned audio is "static".}}
 
== Examples ==
 
== Examples ==
 
=== Load background music and play it ===
 
=== Load background music and play it ===

Revision as of 22:05, 7 October 2012

Creates a new Source from a filepath, File, Decoder or SoundData. Sources created from SoundData are always static.

O.png This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!  



Function

Synopsis

source = love.audio.newSource( filename )

Arguments

string filename
The filepath to the audio file.

Returns

Source source
A new Source that can play the specified audio. The SourceType of the returned audio is "stream".

Function

Synopsis

source = love.audio.newSource( filename, type )

Arguments

string filename
The filepath to the audio file.
SourceType type
Streaming or static source.

Returns

Source source
A new Source that can play the specified audio.

Function

Synopsis

source = love.audio.newSource( file )

Arguments

File file
A File pointing to an audio file.

Returns

Source source
A new Source that can play the specified audio. The SourceType of the returned audio is "stream".

Function

Synopsis

source = love.audio.newSource( file, type )

Arguments

File file
A File pointing to an audio file.
SourceType type
Streaming or static source.

Returns

Source source
A new Source that can play the specified audio.

Function

Synopsis

source = love.audio.newSource( decoder )

Arguments

Decoder decoder
The Decoder to create a Source from.

Returns

Source source
A new Source that can play the specified audio. The SourceType of the returned audio is "stream".

Function

Synopsis

source = love.audio.newSource( decoder, type )

Arguments

Decoder decoder
The Decoder to create a Source from.
SourceType type
Streaming or static source.

Returns

Source source
A new Source that can play the specified audio.

Function

Synopsis

source = love.audio.newSource( data )

Arguments

SoundData data
The SoundData to create a Source from.

Returns

Source source
A new Source that can play the specified audio. The SourceType of the returned audio is "static".

Examples

Load background music and play it

bgm = love.audio.newSource("bgm.ogg", "stream")
love.audio.play(bgm)

Load a sound effect and play it

sfx = love.audio.newSource("sfx.wav", "static")
love.audio.play(sfx)

Load SoundData and create a Source

data = love.sound.newSoundData("sfx.wav")
sfx = love.audio.newSource(data)

Load Decoder and create a Source

decoder = love.sound.newDecoder("bgm.ogg")
bgm = love.audio.newSource(decoder)

See Also


Other Languages