H3D API  2.4.1
Sound.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __SOUND_H__
30 #define __SOUND_H__
31 
32 
33 #include <H3D/X3DSoundNode.h>
34 #include <H3D/X3DSoundSourceNode.h>
35 
36 namespace H3D {
37 
133  class H3DAPI_API Sound : public X3DSoundNode {
134  public:
135 
138  class H3DAPI_API SFSoundSourceNode: public TypedSFNode< X3DSoundSourceNode > {
139  public:
141  ~SFSoundSourceNode() { value = NULL; }
142  protected:
143  virtual void onAdd( Node *n );
144  virtual void onRemove( Node *n );
145  };
146 
149  class ALSoundSetup: public PeriodicUpdate< Field > {
150  public:
151  virtual void update() {
152  Sound *s =
153  static_cast< Sound * >( getOwner());
154  s->ALrender();
155  }
156  };
157 
159  Sound( Inst< SFNode > _metadata = 0,
160  Inst< SFVec3f> _direction = 0,
161  Inst< SFFloat> _intensity = 0,
162  Inst< SFVec3f> _location = 0,
163  Inst< SFFloat> _maxBack = 0,
164  Inst< SFFloat> _maxFront = 0,
165  Inst< SFFloat> _minBack = 0,
166  Inst< SFFloat> _minFront = 0,
167  Inst< SFFloat> _priority = 0,
168  Inst< SFSoundSourceNode > _source = 0,
169  Inst< SFBool > _spatialize = 0,
170  Inst< ALSoundSetup > _soundSetup = 0 );
171 
172  ~Sound();
173 
178  virtual void traverseSG( TraverseInfo &ti );
179 
181  virtual void ALrender();
182 
189  H3DUniquePtr< SFVec3f > direction;
190 
205  H3DUniquePtr< SFFloat > intensity;
206 
214  H3DUniquePtr< SFVec3f > location;
215 
222  H3DUniquePtr< SFFloat > maxBack;
223 
230  H3DUniquePtr< SFFloat > maxFront;
231 
238  H3DUniquePtr< SFFloat > minBack;
239 
246  H3DUniquePtr< SFFloat > minFront;
247 
258  H3DUniquePtr< SFFloat > priority;
259 
267  H3DUniquePtr< SFSoundSourceNode > source;
268 
282  H3DUniquePtr< SFBool > spatialize;
283 
286  protected:
287  public:
288 #ifdef HAVE_OPENAL
289  static bool alut_initialized;
290  static ALCdevice *al_device;
291  static ALCcontext *al_context;
292 #endif
295  H3DUniquePtr< ALSoundSetup > soundSetup;
296 
298  H3DUniquePtr< SFMatrix4f > accForwardMatrix;
299  };
300 }
301 
302 #endif
Header file for X3DSoundNode, X3D scene-graph node.
Header file for X3DSoundSourceNode, X3D scene-graph node.
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
The PeriodicUpdate is a template modifier that changes the way the field is updated.
Definition: PeriodicUpdate.h:74
Field that calls ALrender() when a field routed to it has generated an event.
Definition: Sound.h:149
virtual void update()
This function will be called to update the field if it has a pending event when the upToDate() functi...
Definition: Sound.h:151
The SFSoundSourceNode registers the Sound node in the X3DSoundSourceNode that is put into the field.
Definition: Sound.h:138
~SFSoundSourceNode()
Destructor.
Definition: Sound.h:141
The Sound node specifies the spatial presentation of a sound in a X3D scene.
Definition: Sound.h:133
H3DUniquePtr< SFBool > spatialize
The spatialize field specifies if the sound is perceived as being directionally located relative to t...
Definition: Sound.h:282
H3DUniquePtr< SFFloat > minBack
The minBack field specifies the back value of the inner ellipsoid.
Definition: Sound.h:238
H3DUniquePtr< SFFloat > minFront
The minFront field specifies the front value of the inner ellipsoid.
Definition: Sound.h:246
virtual void ALrender()
Perform the OpenAL calls to render the sound node.
Definition: Sound.cpp:157
H3DUniquePtr< SFFloat > priority
The priority field provides a hint for the browser to choose which sounds to play when there are more...
Definition: Sound.h:258
H3DUniquePtr< SFSoundSourceNode > source
The source field specifies the sound source for the Sound node.
Definition: Sound.h:267
H3DUniquePtr< SFMatrix4f > accForwardMatrix
The matrix from local space to global space.
Definition: Sound.h:298
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: Sound.h:285
H3DUniquePtr< SFVec3f > direction
The direction field specifies the direction of the ellipsoids.
Definition: Sound.h:189
H3DUniquePtr< SFVec3f > location
The location field determines the location of the sound emitter in the local coordinate system.
Definition: Sound.h:214
H3DUniquePtr< SFFloat > maxBack
The maxBack field specifies the back value of the outer ellipsoid.
Definition: Sound.h:222
H3DUniquePtr< SFFloat > maxFront
The maxFront field specifies the front value of the outer ellipsoid.
Definition: Sound.h:230
H3DUniquePtr< ALSoundSetup > soundSetup
Field that calls ALrender() when a field routed to it has generated an event.
Definition: Sound.h:295
H3DUniquePtr< SFFloat > intensity
The intensity field adjusts the loudness (decibels) of the sound emitted by the Sound node.
Definition: Sound.h:205
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
This abstract node type is the base for all Sound nodes.
Definition: X3DSoundNode.h:48
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194