Difference between revisions of "Sound"

From GiderosMobile
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Sound -->
 
<!-- GIDEROSOBJ:Sound -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/>
+
'''Inherits from:''' [[Object]]<br/>
  
=== <translate>Description</translate> ===
+
=== Description ===
The [[Special:MyLanguage/Sound|Sound]] class lets you load and play WAV, MP3, MOD, XM, S3M and IT sound files.
+
The '''Sound''' class lets you load and play WAV, MP3, MOD, XM, S3M and IT sound files.
  
Control of the playing sound is performed through the [[Special:MyLanguage/SoundChannel|SoundChannel]] object.
+
Control of the playing sound is performed through the [[SoundChannel]] object.
  
=== <translate>Examples</translate> ===
+
=== Example ===
<source lang="lua">
+
'''Play a background music in loop'''
local sound = Sound.new("music.mp3")
+
<syntaxhighlight lang="lua">
local channel = sound:play()
+
--local sound = Sound.new("bgmusicloop.wav")
 +
local sound = Sound.new("bgmusicloop.mp3")
  
-- after some time --
+
print(sound:getLength())
channel:stop()
+
 
</source>
+
local channel = sound:play(26000, true, false)
 +
 
 +
print(channel:getPosition())
 +
channel:setPosition(20000)
 +
print(channel:getPosition())
 +
channel:setPaused(false)
 +
 
 +
channel:addEventListener(Event.COMPLETE, function() print("complete") end)
 +
 
 +
local function onTimer()
 +
-- print(channel:getPosition(), sound:getLength())
 +
collectgarbage()
 +
end
 +
 
 +
local t = Timer.new(100)
 +
t:addEventListener(Event.TIMER, onTimer)
 +
t:start()
 +
 
 +
stage:addEventListener(Event.MOUSE_DOWN, function()
 +
channel:setPaused(not channel:isPaused())
 +
channel:setPosition(10000)
 +
-- channel:setPitch(1.5)
 +
end)
 +
</syntaxhighlight>
 +
 
 +
=== See also ===
 +
'''[[SoundChannel]]'''<br/>
 +
'''[[Playing_Sound_and_Music]]'''
  
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Sound.new|Sound.new]] ''<translate>creates a new Sound object</translate>''<br/>
+
[[Sound.new]] ''creates a new Sound object from a file''<br/><!--GIDEROSMTD:Sound.new(filename) creates a new Sound object from a file-->
<!-- GIDEROSMTD:Sound.new(filename) creates a new Sound object -->
+
[[Sound.new]] ''creates a new Sound object from a table''<br/><!--GIDEROSMTD:Sound.new(data,rate,stereo) creates a new Sound object from a table-->
[[Special:MyLanguage/Sound.setListenerPosition|Sound.setListenerPosition]] <br/>
+
[[Sound.setListenerPosition]] ''sets the position, velocity and orientation of the listener''<br/><!--GIDEROSMTD:Sound.setListenerPosition(x,y,z,vx,vy,vz,dx,dy,dz,ux,uy,uz) sets the position, velocity and orientation of the listener-->
<!-- GIDEROSMTD:Sound.setListenerPosition(x,y,z,vx,vy,vz,dx,dy,dz,ux,uy,uz) -->
+
[[Sound:getLength]] ''gets the sound duration''<br/><!--GIDEROSMTD:Sound:getLength() gets the sound duration-->
 
+
[[Sound:play]] ''creates a new SoundChannel object to play the sound''<br/><!--GIDEROSMTD:Sound:play(startTime,looping,paused) creates a new SoundChannel object to play the sound-->
[[Special:MyLanguage/Sound:getLength|Sound:getLength]] ''Get the duration of this sound'' <br/>
 
<!-- GIDEROSMTD:Sound:getLength() Get the duration of this sound -->
 
[[Special:MyLanguage/Sound:play|Sound:play]] ''<translate>creates a new SoundChannel object to play the sound</translate>''<br/>
 
<!-- GIDEROSMTD:Sound:play(startTime,looping,paused) creates a new SoundChannel object to play the sound -->
 
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
  
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 07:41, 31 August 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6
Inherits from: Object

Description

The Sound class lets you load and play WAV, MP3, MOD, XM, S3M and IT sound files.

Control of the playing sound is performed through the SoundChannel object.

Example

Play a background music in loop

--local sound = Sound.new("bgmusicloop.wav")
local sound = Sound.new("bgmusicloop.mp3")

print(sound:getLength())

local channel = sound:play(26000, true, false)

print(channel:getPosition())
channel:setPosition(20000)
print(channel:getPosition())
channel:setPaused(false)

channel:addEventListener(Event.COMPLETE, function() print("complete") end)

local function onTimer()
--	print(channel:getPosition(), sound:getLength())
	collectgarbage()
end

local t = Timer.new(100)
t:addEventListener(Event.TIMER, onTimer)
t:start()

stage:addEventListener(Event.MOUSE_DOWN, function()
	channel:setPaused(not channel:isPaused())
	channel:setPosition(10000)
--	channel:setPitch(1.5)
end)

See also

SoundChannel
Playing_Sound_and_Music

Methods

Sound.new creates a new Sound object from a file
Sound.new creates a new Sound object from a table
Sound.setListenerPosition sets the position, velocity and orientation of the listener
Sound:getLength gets the sound duration
Sound:play creates a new SoundChannel object to play the sound

Events

Constants