• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

sound_handler.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 
00024 
00025 #ifndef SOUND_HANDLER_H
00026 #define SOUND_HANDLER_H
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include "gnashconfig.h"
00030 #endif
00031 
00032 #include "dsodefs.h" // for DSOEXPORT
00033 #include "MediaHandler.h" // for inlined ctor
00034 #include "SoundEnvelope.h" // for SoundEnvelopes typedef
00035 #include "AuxStream.h" // for aux_stramer_ptr typedef
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <memory>
00040 #include <cassert>
00041 #include <cstring>
00042 #include <limits>
00043 #include <set> // for composition
00044 
00045 namespace gnash {
00046     namespace media {
00047         class SoundInfo;
00048     }
00049     namespace sound {
00050         class EmbedSound;
00051         class InputStream;
00052     }
00053     class SimpleBuffer;
00054 }
00055 
00056 namespace gnash {
00057 
00059 //
00063 namespace sound {
00064 
00066 //
00084 class DSOEXPORT sound_handler
00085 {
00086 public:
00087 
00089     //
00092     typedef unsigned long StreamBlockId;
00093 
00095     //
00109     virtual int create_sound(
00110         std::auto_ptr<SimpleBuffer> data,
00111         std::auto_ptr<media::SoundInfo> sinfo
00112         );
00113 
00115     //
00140     virtual StreamBlockId addSoundBlock(unsigned char* data,
00141                                        unsigned int dataBytes,
00142                                        unsigned int sampleCount,
00143                                        int streamId);
00144 
00148     //
00157     virtual media::SoundInfo* get_sound_info(int soundHandle);
00158 
00160     //
00191     void startSound(int id, int loops, 
00192                    const SoundEnvelopes* env,
00193                    bool allowMultiple, unsigned int inPoint=0,
00194                    unsigned int outPoint=std::numeric_limits<unsigned int>::max());
00195 
00197     //
00206     void playStream(int id, StreamBlockId blockId);
00207 
00209     virtual void    stop_all_sounds();
00210 
00212     //
00221     virtual int get_volume(int sound_handle);
00222 
00224     //
00228     int getFinalVolume() { return _volume; }
00229     
00231     //
00242     virtual void set_volume(int sound_handle, int volume);
00243 
00245     //
00249     void setFinalVolume(int v) { _volume=v; }
00250         
00252     //
00257     //
00261     virtual void    stop_sound(int sound_handle);
00262 
00264     //
00268     virtual void delete_sound(int sound_handle);
00269 
00270     // Stop and delete all sounds
00271     virtual void delete_all_sounds();
00272 
00276     //
00282     virtual void reset();
00283         
00285     virtual void mute();
00286 
00288     virtual void unmute();
00289 
00291     //
00294     virtual bool is_muted() const;
00295 
00297     virtual void pause() { _paused=true; }
00298 
00300     virtual void unpause() { _paused=false; }
00301 
00303     bool isPaused() const { return _paused; }
00304 
00306     //
00340     virtual InputStream* attach_aux_streamer(aux_streamer_ptr ptr, void* udata);
00341 
00343     //
00347     //
00352     virtual void unplugInputStream(InputStream* id);
00353 
00354     virtual ~sound_handler() {};
00355     
00359     //
00365     virtual unsigned int get_duration(int sound_handle);
00366 
00370     //
00376     virtual unsigned int tell(int sound_handle);
00377 
00379     //
00382     size_t numSoundsStarted() const { return _soundsStarted; }
00383 
00385     //
00388     size_t numSoundsStopped() const { return _soundsStopped; }
00389 
00391     //
00410     virtual void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00411 
00412 protected:
00413 
00414 
00415     sound_handler(media::MediaHandler* m)
00416         :
00417         _soundsStarted(0),
00418         _soundsStopped(0),
00419         _paused(false),
00420         _muted(false),
00421         _volume(100),
00422         _sounds(),
00423         _inputStreams(),
00424         _mediaHandler(m)
00425     {
00426     }
00427 
00429     //
00433     virtual void plugInputStream(std::auto_ptr<InputStream> in);
00434 
00436     virtual void unplugAllInputStreams();
00437 
00439     bool hasInputStreams() const;
00440 
00442     //
00466     virtual void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
00467                 unsigned int nSamples, float volume);
00468 
00469 private:
00470 
00472     size_t _soundsStarted;
00473 
00475     size_t _soundsStopped;
00476 
00478     bool _paused;
00479 
00481     bool _muted;
00482 
00484     int _volume;
00485 
00486     typedef std::vector<EmbedSound*> Sounds;
00487 
00489     //
00492     Sounds  _sounds;
00493 
00495     void stopEmbedSoundInstances(EmbedSound& def);
00496 
00497     typedef std::set< InputStream* > InputStreams;
00498 
00500     //
00503     InputStreams _inputStreams;
00504 
00505     media::MediaHandler* _mediaHandler;
00506 
00508     void unplugCompletedInputStreams();
00509 
00511     //
00545     void playSound(int id, int loops,
00546                    unsigned int inPoint,
00547                    unsigned int outPoint,
00548                    StreamBlockId blockId, const SoundEnvelopes* env,
00549                    bool allowMultiple);
00550 
00552     //
00566     unsigned int swfToOutSamples(const media::SoundInfo& sinfo,
00567                                           unsigned int swfSamples);
00568 
00569 };
00570 
00571 // TODO: move to appropriate specific sound handlers
00572 
00573 #ifdef SOUND_SDL
00574 
00575 DSOEXPORT sound_handler* create_sound_handler_sdl(media::MediaHandler* m);
00576 
00578 DSOEXPORT sound_handler* create_sound_handler_sdl(media::MediaHandler* m,
00579         const std::string& wave_file);
00580 #elif defined(SOUND_AHI)
00581 
00582 DSOEXPORT sound_handler* create_sound_handler_aos4(media::MediaHandler* m);
00583 
00585 DSOEXPORT sound_handler* create_sound_handler_aos4(media::MediaHandler* m,
00586         const std::string& wave_file);
00587 
00588 #elif defined(SOUND_MKIT)
00589 
00590 DSOEXPORT sound_handler* create_sound_handler_mkit(media::MediaHandler* m);
00591 
00593 DSOEXPORT sound_handler* create_sound_handler_mkit(media::MediaHandler* m,
00594         const std::string& wave_file);
00595 #endif
00596 
00597 } // gnash.sound namespace 
00598 } // namespace gnash
00599 
00600 #endif // SOUND_HANDLER_H
00601 
00602 
00603 // Local Variables:
00604 // mode: C++
00605 // indent-tabs-mode: t
00606 // End:

Generated on Thu Sep 30 2010 14:35:02 for Gnash by  doxygen 1.7.1