Gnash 0.8.9
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00003 // 2011 Free Software 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 #ifndef SOUND_HANDLER_H 00020 #define SOUND_HANDLER_H 00021 00022 #ifdef HAVE_CONFIG_H 00023 #include "gnashconfig.h" 00024 #endif 00025 00026 #include "dsodefs.h" // for DSOEXPORT 00027 #include "MediaHandler.h" // for inlined ctor 00028 #include "SoundEnvelope.h" // for SoundEnvelopes typedef 00029 #include "AuxStream.h" // for aux_stramer_ptr typedef 00030 #include "WAVWriter.h" // for dtor visibility 00031 00032 #include <string> 00033 #include <vector> 00034 #include <memory> 00035 #include <cassert> 00036 #include <cstring> 00037 #include <limits> 00038 #include <set> // for composition 00039 #include <boost/scoped_ptr.hpp> 00040 00041 namespace gnash { 00042 namespace media { 00043 class SoundInfo; 00044 } 00045 namespace sound { 00046 class EmbedSound; 00047 class InputStream; 00048 } 00049 class SimpleBuffer; 00050 } 00051 00052 namespace gnash { 00053 00055 // 00059 namespace sound { 00060 00062 // 00080 class DSOEXPORT sound_handler 00081 { 00082 public: 00083 00085 // 00088 typedef unsigned long StreamBlockId; 00089 00091 // 00105 virtual int create_sound( 00106 std::auto_ptr<SimpleBuffer> data, 00107 std::auto_ptr<media::SoundInfo> sinfo 00108 ); 00109 00111 // 00136 virtual StreamBlockId addSoundBlock(unsigned char* data, 00137 unsigned int dataBytes, 00138 unsigned int sampleCount, 00139 int streamId); 00140 00144 // 00153 virtual media::SoundInfo* get_sound_info(int soundHandle); 00154 00156 // 00187 void startSound(int id, int loops, 00188 const SoundEnvelopes* env, 00189 bool allowMultiple, unsigned int inPoint=0, 00190 unsigned int outPoint=std::numeric_limits<unsigned int>::max()); 00191 00193 // 00202 void playStream(int id, StreamBlockId blockId); 00203 00205 virtual void stop_all_sounds(); 00206 00208 // 00217 virtual int get_volume(int sound_handle); 00218 00220 // 00224 int getFinalVolume() { return _volume; } 00225 00227 // 00238 virtual void set_volume(int sound_handle, int volume); 00239 00241 // 00245 void setFinalVolume(int v) { _volume=v; } 00246 00248 // 00253 // 00257 virtual void stop_sound(int sound_handle); 00258 00260 // 00264 virtual void delete_sound(int sound_handle); 00265 00266 // Stop and delete all sounds 00267 virtual void delete_all_sounds(); 00268 00272 // 00278 virtual void reset(); 00279 00281 virtual void mute(); 00282 00284 virtual void unmute(); 00285 00287 // 00290 virtual bool is_muted() const; 00291 00293 virtual void pause() { _paused=true; } 00294 00296 virtual void unpause() { _paused=false; } 00297 00299 bool isPaused() const { return _paused; } 00300 00302 // 00336 virtual InputStream* attach_aux_streamer(aux_streamer_ptr ptr, void* udata); 00337 00339 // 00343 // 00348 virtual void unplugInputStream(InputStream* id); 00349 00350 virtual ~sound_handler() {}; 00351 00355 // 00361 virtual unsigned int get_duration(int sound_handle); 00362 00366 // 00372 virtual unsigned int tell(int sound_handle); 00373 00375 // 00378 size_t numSoundsStarted() const { return _soundsStarted; } 00379 00381 // 00384 size_t numSoundsStopped() const { return _soundsStopped; } 00385 00387 // 00406 virtual void fetchSamples(boost::int16_t* to, unsigned int nSamples); 00407 00409 // 00433 virtual void mix(boost::int16_t* outSamples, boost::int16_t* inSamples, 00434 unsigned int nSamples, float volume) = 0; 00435 00436 00438 // 00442 void setAudioDump(const std::string& wavefile); 00443 00444 protected: 00445 00446 00447 sound_handler(media::MediaHandler* m) 00448 : 00449 _soundsStarted(0), 00450 _soundsStopped(0), 00451 _paused(false), 00452 _muted(false), 00453 _volume(100), 00454 _sounds(), 00455 _inputStreams(), 00456 _mediaHandler(m) 00457 { 00458 } 00459 00461 // 00465 virtual void plugInputStream(std::auto_ptr<InputStream> in); 00466 00468 virtual void unplugAllInputStreams(); 00469 00471 bool hasInputStreams() const; 00472 00473 private: 00474 00476 size_t _soundsStarted; 00477 00479 size_t _soundsStopped; 00480 00482 bool _paused; 00483 00485 bool _muted; 00486 00488 int _volume; 00489 00490 typedef std::vector<EmbedSound*> Sounds; 00491 00493 // 00496 Sounds _sounds; 00497 00499 void stopEmbedSoundInstances(EmbedSound& def); 00500 00501 typedef std::set< InputStream* > InputStreams; 00502 00504 // 00507 InputStreams _inputStreams; 00508 00509 media::MediaHandler* _mediaHandler; 00510 00512 void unplugCompletedInputStreams(); 00513 00515 // 00549 void playSound(int id, int loops, 00550 unsigned int inPoint, 00551 unsigned int outPoint, 00552 StreamBlockId blockId, const SoundEnvelopes* env, 00553 bool allowMultiple); 00554 00556 // 00570 unsigned int swfToOutSamples(const media::SoundInfo& sinfo, 00571 unsigned int swfSamples); 00572 00573 boost::scoped_ptr<WAVWriter> _wavWriter; 00574 00575 }; 00576 00577 // TODO: move to appropriate specific sound handlers 00578 00579 #ifdef SOUND_SDL 00580 00581 DSOEXPORT sound_handler* create_sound_handler_sdl(media::MediaHandler* m); 00582 #elif defined(SOUND_AHI) 00583 00584 DSOEXPORT sound_handler* create_sound_handler_aos4(media::MediaHandler* m); 00585 #elif defined(SOUND_MKIT) 00586 00587 DSOEXPORT sound_handler* create_sound_handler_mkit(media::MediaHandler* m); 00588 #endif 00589 00590 } // gnash.sound namespace 00591 } // namespace gnash 00592 00593 #endif // SOUND_HANDLER_H 00594 00595 00596 // Local Variables: 00597 // mode: C++ 00598 // indent-tabs-mode: t 00599 // End: