Difference between revisions of "StartSound"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
Line 1: Line 1:
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
+
==startSound==
<span class="bold">Command History</span>
 
<div class="mw-collapsible-content">
 
<div class="alt-bg">Available since v3.8</div>
 
</div></div>
 
  
 +
<div class="command-min-version-info">Available since: <span class="command-min-version">v3.8</span></div>
  
Allows you to play sound files; with optional property values!
+
<div class="command-doc">Plays a sound file.</div>
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
 
<span class="bold">Additional Info</span>
 
<div class="mw-collapsible-content">
 
<div>Properties currently available:
 
<pre>volume, balance, offset & loop</pre>
 
Please note that only mono sounds can be panned using the balance property; all stereo channel sounds will remain centered!</div>
 
</div></div>
 
  
 +
Lua Syntax:
 +
<pre class="command-syntax">startSound(sounditem, {flags=1,
 +
    volume = int,
 +
    balance = int,
 +
    loop = true|false,
 +
    offset = int})</pre>
 +
===Arguments===
 +
====sounditem====
 +
:'''"string" (string should contain 'vispath:' prefix)''' - Relative filename of sound which should be started.
 +
===Flags===
 +
====vol/volume====
  
Syntax:
+
:Sound volume (0 ... mute, 100 ... full volume), default value is 100.
<syntaxhighlight>
+
====bal/balance====
startSound("filename", {flags=1, properties})
+
 
</syntaxhighlight>
+
:Sound balance (-100 ... left, 0 ... center, +100 right), default value is 0.
 +
====lop/loop====
  
 +
:If true then loop sound, otherwise play it only once (default).
 +
====ofs/offset====
  
Example 1: basic play audio file method!
+
:Set the sound to a specific offset (seek) in milliseconds. Default value is 0.
 +
===Return Values===
 +
;soundID
 +
:Unique id referencing the started sound or -1 if the sound could not be started.
 +
===Examples===
 +
Example 1: play audio file, store sound id (for later use) and update sound balance of currently started sound
 
<syntaxhighlight>
 
<syntaxhighlight>
startSound("sounds/example.ogg")
+
local soundId = startSound('vispath:sounds/example.ogg')
 +
setSoundProperty(soundId, {flags=1, balance=40})
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
Example 2: play audio file and set volume, balance and offset
Example 2: again with properties!
 
 
<syntaxhighlight>
 
<syntaxhighlight>
-- play example.ogg at 100% volume level, audio centered, from 1 second mark with loop mode on!
+
startSound('vispath:sounds/example.ogg', {flags=1, volume=70, balance=-10, offset=1000})
startSound("sounds/example.ogg", {flags=1, volume=100, balance=0, offset=1000, loop=true})
 
 
 
--[[
 
let's say you have an audio file with a duration of 00:03:24 & you want to start the audio file at: 2 minutes & 44 seconds;
 
so what we need to do is convert minutes/seconds into ms like so: (2*60)*1000 + (44*1000) = 164000ms
 
 
 
math explanation:
 
2m*60s = 120 seconds * 1000ms = 120,000ms | 44s*1000ms = 44,000ms
 
120,000 + 44,000 = 164,000ms
 
--]]
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
 
<span class="bold underline">Arguments</span>
 
 
<span class="bold">filename</span>: path <br/>
 
The path to the audio file to be played! ("path/filename.type")
 
 
 
<span class="bold underline">Flags</span>
 
 
<span class="bold">properties</span>
 
* volume: allows you to set volume level via an integer value
 
* balance: allows you to set the left/right audio balance via an integer value (-100 to 100, 0 is centered)
 
* offset: allows you to start audio file from x time via an integer value (in ms)
 
* loop: allows you to declare if audio file should loop via a boolean value (true/false)
 
 
 
<span class="bold underline">Return</span>
 
 
none
 
{{i18n|StartSound}} <br/>
 
{| class="tbl-ds"
 
|-
 
|<span class="bold">Relevant Pages</span>: [[GetSoundId|getSoundId]] - [[GetSoundProperty|getSoundProperty]] - [[SetSoundProperty|setSoundProperty]] - [[StopSound|stopSound]] - [[ToggleSoundPause|toggleSoundPause]]
 
|}
 

Revision as of 18:12, 22 November 2013

startSound

Available since: v3.8
Plays a sound file.

Lua Syntax:

startSound(sounditem, {flags=1, 
    volume = int, 
    balance = int, 
    loop = true|false, 
    offset = int})

Arguments

sounditem

"string" (string should contain 'vispath:' prefix) - Relative filename of sound which should be started.

Flags

vol/volume

Sound volume (0 ... mute, 100 ... full volume), default value is 100.

bal/balance

Sound balance (-100 ... left, 0 ... center, +100 right), default value is 0.

lop/loop

If true then loop sound, otherwise play it only once (default).

ofs/offset

Set the sound to a specific offset (seek) in milliseconds. Default value is 0.

Return Values

soundID
Unique id referencing the started sound or -1 if the sound could not be started.

Examples

Example 1: play audio file, store sound id (for later use) and update sound balance of currently started sound

local soundId = startSound('vispath:sounds/example.ogg')
setSoundProperty(soundId, {flags=1, balance=40})

Example 2: play audio file and set volume, balance and offset

startSound('vispath:sounds/example.ogg', {flags=1, volume=70, balance=-10, offset=1000})