X3DSoundSourceNode.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __X3DSOUNDSOURCENODE_H__
00030 #define __X3DSOUNDSOURCENODE_H__
00031 
00032 #include "X3DTimeDependentNode.h"
00033 #include "X3DSoundNode.h"
00034 #include "PeriodicUpdate.h"
00035 #include "H3DSoundStreamNode.h"
00036 #include <list>
00037 #include <fstream>
00038 
00039 #ifdef HAVE_OPENAL
00040 #ifdef WIN32
00041 #include <al.h>
00042 #include <alc.h>
00043 #ifdef _MSC_VER
00044 #pragma comment( lib, "OpenAL32.lib" )
00045 #endif
00046 #elif defined( MACOSX )
00047 #include <OpenAL/al.h>
00048 #include <OpenAL/alc.h>
00049 #else
00050 #include <AL/al.h>
00051 #include <AL/alc.h>
00052 #endif
00053 #endif 
00054 
00055 #define NR_STREAM_BUFFERS 3
00056 #define STREAM_BUFFER_SIZE (4096*8)
00057 
00058 namespace H3D {
00059 
00067   class H3DAPI_API X3DSoundSourceNode : public X3DTimeDependentNode {
00068   public:
00071     class H3DAPI_API TimeHandler: public X3DTimeDependentNode::TimeHandler {
00072     public:
00074       TimeHandler() {}
00075     protected:
00076       virtual void update();
00077     };
00078 
00081     class H3DAPI_API ALSoundBuffer: 
00082       public PeriodicUpdate< Field > {
00083     protected:
00084       virtual void update() {
00085         X3DSoundSourceNode *s = 
00086           static_cast< X3DSoundSourceNode * >( getOwner());
00087         s->ALrender();
00088         event_fields.clear();
00089       }
00090 
00092       virtual void propagateEvent( Event e ) {
00093         Field::propagateEvent( e );
00094         event_fields.insert( e.ptr );
00095       }
00096     public:
00097 
00100       inline bool hasCausedEvent( Field *f ) {
00101         return event_fields.find( f ) != event_fields.end();
00102       }
00103 
00106       template< class FieldType >
00107       inline bool hasCausedEvent( auto_ptr< FieldType > &f ) {
00108         return hasCausedEvent( f.get() );
00109       }
00110 
00111     protected:
00114       set< Field * > event_fields;
00115     };
00116 
00117 
00119     X3DSoundSourceNode( Inst< SFNode   > _metadata         = 0,
00120                         Inst< SFString > _description      = 0,
00121                         Inst< SFBool   > _loop             = 0,
00122                         Inst< SFTime   > _pauseTime        = 0,
00123                         Inst< SFFloat  > _pitch            = 0,
00124                         Inst< SFTime   > _resumeTime       = 0,
00125                         Inst< StartTime   > _startTime        = 0,
00126                         Inst< StopTime   > _stopTime         = 0,
00127                         Inst< SFTime   > _duration_changed = 0,
00128                         Inst< SFTime   > _elapsedTime      = 0,
00129                         Inst< SFBool   > _isActive         = 0,
00130                         Inst< SFBool   > _isPaused         = 0,
00131                         Inst< TimeHandler > _timeHandler   = 0 );
00132 
00136     virtual void initALBuffers( bool stream );
00137 
00139     virtual void ALrender();
00140 
00143     virtual string defaultXMLContainerField() {
00144       return "source";
00145     }
00146 
00150     virtual void registerSoundNode( X3DSoundNode *n );
00151 
00153     virtual void unregisterSoundNode( X3DSoundNode *n );
00154 
00156     virtual void onPause();
00157 
00159     virtual void onResume();
00160 
00162     virtual void onStart();
00163 
00165     virtual void onStop();
00166 
00173     auto_ptr< SFString > description;
00174 
00183     auto_ptr< SFFloat  > pitch;
00184 
00191     auto_ptr< SFTime   > duration_changed;
00192 
00194     static H3DNodeDatabase database;
00195   protected:
00197     list< X3DSoundNode * > parent_sound_nodes;
00198 
00199 #ifdef HAVE_OPENAL
00200 
00201     ALuint al_buffers[NR_STREAM_BUFFERS];
00202 
00204     ALenum al_format;
00205 #endif
00206 
00208     AutoRef< H3DSoundStreamNode > reader;
00209 
00211     bool sound_as_stream;
00212 
00215     auto_ptr< ALSoundBuffer > sound_buffer;
00216  };
00217 }
00218 
00219 #endif

Generated on Thu Aug 24 12:38:35 2006 for H3D API by  doxygen 1.4.5