Difference between revisions of "love.audio.newSource"

m
(Notes: - corrections.)
(15 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Creates a new Source from a file.
+
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 ==
 
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( filename, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|filename|The filepath to the audio file.}}
 +
{{param|SourceType|type|Streaming or static source.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio.}}
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 8: Line 22:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|string|file|The file to create a Source from.}}
+
{{param|File|file|A File pointing to an audio file.}}
 +
{{param|SourceType|type|Streaming or static source.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio.}}
 +
 
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( decoder, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|Decoder|decoder|The Decoder to create a Source from.}}
 
{{param|SourceType|type|Streaming or static source.}}
 
{{param|SourceType|type|Streaming or static source.}}
 
=== 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 ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( data, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|FileData|data|The FileData to create a Source from.}}
 +
{{param|SourceType|type|Streaming or static source.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio.}}
 +
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 23: Line 62:
  
 
== Function ==
 
== Function ==
 +
{{oldin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( filename, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|filename|The filepath to the audio file.}}
 +
{{param|SourceType|type ("stream")|Streaming or static source.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio.}}
 +
 +
== Function ==
 +
{{oldin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( file, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|File|file|A File pointing to an audio file.}}
 +
{{param|SourceType|type ("stream")|Streaming or static source.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio.}}
 +
 +
== Function ==
 +
{{oldin|[[11.0]]|110|type=variant}}
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 29: Line 93:
 
=== Arguments ===
 
=== Arguments ===
 
{{param|Decoder|decoder|The Decoder to create a Source from.}}
 
{{param|Decoder|decoder|The Decoder to create a Source from.}}
{{param|SourceType|type|Streaming or static source.}}
+
{{param|SourceType|type ("stream")|Streaming or static source.}}
 +
=== Returns ===
 +
{{param|Source|source|A new Source that can play the specified audio.}}
 +
 
 +
== Function ==
 +
{{oldin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
source = love.audio.newSource( data, type )
 +
</source>
 +
=== Arguments ===
 +
{{param|FileData|data|The FileData to create a Source from.}}
 +
{{param|SourceType|type ("stream")|Streaming or static source.}}
 
=== 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.}}
 +
 +
== Notes ==
 +
From [[11.0]] onwards, if '''queue''' is specified as [[SourceType]] for this specific constructor, it won't error, and getType will return '''stream'''; this is a bug. One should use [[love.audio.newQueueableSource]] for that specific source type instead.
 +
 
== Examples ==
 
== Examples ==
 
=== Load background music and play it ===
 
=== Load background music and play it ===
Line 51: Line 131:
 
<source lang="lua">
 
<source lang="lua">
 
decoder = love.sound.newDecoder("bgm.ogg")
 
decoder = love.sound.newDecoder("bgm.ogg")
bgm = love.audio.newSource(decoder)
+
bgm = love.audio.newSource(decoder, "stream")
 
</source>
 
</source>
 
== See Also ==
 
== See Also ==
Line 57: Line 137:
 
* [[Constructs::Source]]
 
* [[Constructs::Source]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Creates a new Source from a file.
+
{{#set:Description=Creates a new [[Source]] from a file, [[SoundData]], or [[Decoder]].
 
}}
 
}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.audio.newSource}}
 
{{i18n|love.audio.newSource}}

Revision as of 02:06, 29 October 2018

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

Available since LÖVE 11.0
This variant is not supported in earlier versions.

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

Available since LÖVE 11.0
This variant is not supported in earlier versions.

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

Available since LÖVE 11.0
This variant is not supported in earlier versions.

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

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

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

Arguments

FileData data
The FileData 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".

Function

Removed in LÖVE 11.0
This variant is not supported in that and later versions.

Synopsis

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

Arguments

string filename
The filepath to the audio file.
SourceType type ("stream")
Streaming or static source.

Returns

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

Function

Removed in LÖVE 11.0
This variant is not supported in that and later versions.

Synopsis

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

Arguments

File file
A File pointing to an audio file.
SourceType type ("stream")
Streaming or static source.

Returns

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

Function

Removed in LÖVE 11.0
This variant is not supported in that and later versions.

Synopsis

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

Arguments

Decoder decoder
The Decoder to create a Source from.
SourceType type ("stream")
Streaming or static source.

Returns

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

Function

Removed in LÖVE 11.0
This variant is not supported in that and later versions.

Synopsis

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

Arguments

FileData data
The FileData to create a Source from.
SourceType type ("stream")
Streaming or static source.

Returns

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

Notes

From 11.0 onwards, if queue is specified as SourceType for this specific constructor, it won't error, and getType will return stream; this is a bug. One should use love.audio.newQueueableSource for that specific source type instead.

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, "stream")

See Also


Other Languages