wiki.sine.space | sinespace

Difference between revisions of "Scripting/SAudioSource"

From wiki.sine.space
Jump to: navigation, search
(Added Volume, Pitch, Time, IsPlaying)
(Added PanStereo, SpatialBlend, Spatialize, SpatializePostEffects)
Line 71: Line 71:
 
Space.Log(hostObject.Audio.IsPlaying);<br>
 
Space.Log(hostObject.Audio.IsPlaying);<br>
 
''-- prints True (by default), if the sound clip is playing, or False, if it doesn't, to the console''}}
 
''-- prints True (by default), if the sound clip is playing, or False, if it doesn't, to the console''}}
 +
 +
{{ScriptFunction|float|PanStereo|{get;set;}|Pans the sound to the left or right. Values range from -1 to 1: 0 is the middle, -1 is full left, 1 is full right. |5=
 +
hostObject = Space.Host.ExecutingObject;<br><br>
 +
Space.Log(hostObject.Audio.PanStereo);<br>
 +
''-- Prints the current Pan Stereo level (0 by default)''<br>
 +
hostObject.Audio.PanStereo = 0.5;<br>
 +
''-- Pans the sound halfway from the middle to the right''}}
 +
 +
{{ScriptFunction|float|SpatialBlend|{get;set;}|The level of impact 3D effects make on the AudioSource. 0 - no impact (full 2D sound), 1 - maximum impact (full 3D sound).|5=
 +
hostObject = Space.Host.ExecutingObject;<br><br>
 +
function spBlendChange ()<br>
 +
:if hostObject.Audio.SpatialBlend < 1 then<br>
 +
::hostObject.Audio.SpatialBlend = hostObject.Audio.SpatialBlend + 0.2;<br>
 +
:else<br>
 +
::hostObject.Audio.SpatialBlend = 0;<br>
 +
:end<br>
 +
:Space.Log(hostObject.Audio.SpatialBlend);<br>
 +
end<br><br>
 +
hostObject.SubscribeToEvents();<br>
 +
hostObject.OnMouseDown(spBlendChange);<br>
 +
''-- Spatial Blend is increased by 0.2 every time the object is clicked, until it reaches 1.''
 +
''-- Then with the next click, it resets back to 0.''}}
 +
 +
{{ScriptFunction|bool|Spatialize|{get;set;}|Is spatialization enabled? |5=
 +
hostObject = Space.Host.ExecutingObject;<br>
 +
Space.Log(hostObject.Audio.Spatialize);<br>
 +
''-- Prints the current state of spatialization (False by default) to the console''<br>
 +
hostObject.Audio.Spatialize = true;<br>
 +
''-- Now spatialization is enabled''}}
 +
 +
{{ScriptFunction|bool|SpatializePostEffects|{get;set;}|Is spatialization enabled before or after other filters are in action? |5=
 +
hostObject = Space.Host.ExecutingObject;<br>
 +
''-- Because enabling this property makes sense only if spatialization itself is enabled, let's enable it first.''<br>
 +
hostObject.Audio.Spatialize = true;<br><br>
 +
if hostObject.Audio.Spatialize then<br>
 +
:hostObject.Audio.SpatializePostEffects = true;<br>
 +
end<br><br>
 +
Space.Log(hostObject.Audio.SpatializePostEffects);<br>
 +
''-- prints "True" to the console''}}

Revision as of 06:32, 20 July 2017

The SAudioSource class deals with the Audio Source component, which allows the object to play sounds in the scene.

Properties

Enabled

bool Enabled {get;set;}

Is the Audio Source component enabled?

hostObject = Space.Host.ExecutingObject;

function audioOnOff ()

hostObject.Audio.Enabled = not hostObject.Audio.Enabled;
Space.Log(hostObject.Audio.Enabled);

end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioOnOff);
-- When the host object is clicked, the Audio Source component gets enabled, if it was disabled,

-- or disabled, if it was enabled, and its new state is printed to the console.


Loop

bool Loop {get;set;}

Is looping of the sound clip enabled?

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.Loop);
-- False by default.

if not hostObject.Audio.Loop then

hostObject.Audio.Loop = true;

end

-- Now it is looping.


DopplerLevel

float DopplerLevel {get;set;}

The Doppler level of the Audio Source. (See: Doppler Effect)

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.DopplerLevel);
-- 1 by default
hostObject.Audio.DopplerLevel = 5;

-- The highest possible value


Volume

float Volume {get;set;}

The Volume level of the Audio Source.

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.Volume);
-- 1 by default

function audioVolumeDecr ()

if hostObject.Audio.Volume > 0 then
hostObject.Audio.Volume = hostObject.Audio.Volume - 0.2;
end
Space.Log(hostObject.Audio.Volume);

end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioVolumeDecr);

-- Now, every time we click this object, the Volume level is decreased by 0.2, until it reaches 0.


Pitch

float Pitch {get;set;}

The Pitch level for the Audio Source.

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.Pitch);
-- 1 by default

function audioPitchChange ()

if hostObject.Audio.Pitch < 3 then
hostObject.Audio.Pitch = hostObject.Audio.Pitch + 0.5;
end
Space.Log(hostObject.Audio.Pitch);

end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioPitchChange);

-- Now, every time we click this object, the Pitch level is increased by 0.5, until it reaches 3.


Time

float Time {get;set;}

Playback position in seconds.

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.Time);
-- 0 by default (the beginning of the sound clip)
hostObject.Audio.Time = 15;
-- jumps to the 0:15 position of the sound clip
hostObject.Audio.Time = 75;

-- jumps to the 1:15 position of the sound clip


IsPlaying

bool IsPlaying {get;}

Is the sound clip playing right now?

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.IsPlaying);

-- prints True (by default), if the sound clip is playing, or False, if it doesn't, to the console


PanStereo

float PanStereo {get;set;}

Pans the sound to the left or right. Values range from -1 to 1: 0 is the middle, -1 is full left, 1 is full right.

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.PanStereo);
-- Prints the current Pan Stereo level (0 by default)
hostObject.Audio.PanStereo = 0.5;

-- Pans the sound halfway from the middle to the right


SpatialBlend

float SpatialBlend {get;set;}

The level of impact 3D effects make on the AudioSource. 0 - no impact (full 2D sound), 1 - maximum impact (full 3D sound).

hostObject = Space.Host.ExecutingObject;

function spBlendChange ()

if hostObject.Audio.SpatialBlend < 1 then
hostObject.Audio.SpatialBlend = hostObject.Audio.SpatialBlend + 0.2;
else
hostObject.Audio.SpatialBlend = 0;
end
Space.Log(hostObject.Audio.SpatialBlend);

end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(spBlendChange);
-- Spatial Blend is increased by 0.2 every time the object is clicked, until it reaches 1.

-- Then with the next click, it resets back to 0.


Spatialize

bool Spatialize {get;set;}

Is spatialization enabled?

hostObject = Space.Host.ExecutingObject;

Space.Log(hostObject.Audio.Spatialize);
-- Prints the current state of spatialization (False by default) to the console
hostObject.Audio.Spatialize = true;

-- Now spatialization is enabled


SpatializePostEffects

bool SpatializePostEffects {get;set;}

Is spatialization enabled before or after other filters are in action?

hostObject = Space.Host.ExecutingObject;

-- Because enabling this property makes sense only if spatialization itself is enabled, let's enable it first.
hostObject.Audio.Spatialize = true;

if hostObject.Audio.Spatialize then

hostObject.Audio.SpatializePostEffects = true;

end

Space.Log(hostObject.Audio.SpatializePostEffects);

-- prints "True" to the console