2
# Copyright (C) 2001-2002 Jean-Baptiste LAMY
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
# Lesson 116: 3D Sound
20
# In this lesson, we integrate 3D sounds by using OpenAL and PyOpenAL.
21
# PyOpenAL includes a special module for using it along with Soya.
23
# You need to install OpenAL and PyOpenAL before running this lesson !
24
# You may need to stop artsd daemon too (typically for KDE user)
26
# The lesson draws a moving cube that play a 3D sound.
28
import os, os.path, sys
30
import soya, soya.soya3d as soya3d, soya.model as model, soya.cube as cube
33
scene = soya3d.World()
35
camera = soya3d.Camera(scene)
39
soya.set_root_widget(camera)
44
import pyopenal, pyopenal.openal4soya as openal4soya
46
# Inits the OpenAL for Soya module, and pass to it the location of the listener
47
# (usually the camera).
49
openal4soya.init(camera)
51
# Define the sound directory
53
openal4soya.PATH = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "data")
58
cube = soya3d.Volume(scene, cube.Cube().shapify())
60
# The cube continuously play a sound
62
# The parameters for play are:
63
# - the sound file name (supported format: Wave, and Ogg Vorbis if PyVorbis is installed)
64
# - the sound position
65
# - the sound speed (a Vector, optional)
66
# the speed is automatically computed if omitted
67
# - 1 for looping (0 else)
68
# - 1 to load the sound asynchronously (if not already cached)
70
openal4soya.play("test.wav", cube, None, 1)
73
light = soya3d.Light(scene)
74
light.set_xyz(1.5, 2.0, 2.2)
83
# The sound's source is automagically moved with the cube.
86
cube.set_xyz(3.0 * math.cos(angle), 0.0, 3.0 * math.sin(angle))