Gnash 0.8.10dev
|
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 // 00197 bool isSoundPlaying(int id) const; 00198 00200 // 00209 void playStream(int id, StreamBlockId blockId); 00210 00212 virtual void stop_all_sounds(); 00213 00215 // 00224 virtual int get_volume(int sound_handle); 00225 00227 // 00231 int getFinalVolume() { return _volume; } 00232 00234 // 00245 virtual void set_volume(int sound_handle, int volume); 00246 00248 // 00252 void setFinalVolume(int v) { _volume=v; } 00253 00255 // 00260 // 00264 virtual void stop_sound(int sound_handle); 00265 00267 // 00271 virtual void delete_sound(int sound_handle); 00272 00273 // Stop and delete all sounds 00274 virtual void delete_all_sounds(); 00275 00279 // 00285 virtual void reset(); 00286 00288 virtual void mute(); 00289 00291 virtual void unmute(); 00292 00294 // 00297 virtual bool is_muted() const; 00298 00300 virtual void pause() { _paused=true; } 00301 00303 virtual void unpause() { _paused=false; } 00304 00306 bool isPaused() const { return _paused; } 00307 00309 // 00343 virtual InputStream* attach_aux_streamer(aux_streamer_ptr ptr, void* udata); 00344 00346 // 00350 // 00355 virtual void unplugInputStream(InputStream* id); 00356 00357 virtual ~sound_handler(); 00358 00362 // 00368 virtual unsigned int get_duration(int sound_handle); 00369 00373 // 00379 virtual unsigned int tell(int sound_handle); 00380 00382 // 00385 size_t numSoundsStarted() const { return _soundsStarted; } 00386 00388 // 00391 size_t numSoundsStopped() const { return _soundsStopped; } 00392 00394 // 00413 virtual void fetchSamples(boost::int16_t* to, unsigned int nSamples); 00414 00416 // 00440 virtual void mix(boost::int16_t* outSamples, boost::int16_t* inSamples, 00441 unsigned int nSamples, float volume) = 0; 00442 00443 00445 // 00449 void setAudioDump(const std::string& wavefile); 00450 00451 protected: 00452 00453 00454 sound_handler(media::MediaHandler* m) 00455 : 00456 _soundsStarted(0), 00457 _soundsStopped(0), 00458 _paused(false), 00459 _muted(false), 00460 _volume(100), 00461 _sounds(), 00462 _inputStreams(), 00463 _mediaHandler(m) 00464 { 00465 } 00466 00468 // 00472 virtual void plugInputStream(std::auto_ptr<InputStream> in); 00473 00475 virtual void unplugAllInputStreams(); 00476 00478 bool hasInputStreams() const; 00479 00480 private: 00481 00483 size_t _soundsStarted; 00484 00486 size_t _soundsStopped; 00487 00489 bool _paused; 00490 00492 bool _muted; 00493 00495 int _volume; 00496 00497 typedef std::vector<EmbedSound*> Sounds; 00498 00500 // 00503 Sounds _sounds; 00504 00506 void stopEmbedSoundInstances(EmbedSound& def); 00507 00508 typedef std::set< InputStream* > InputStreams; 00509 00511 // 00514 InputStreams _inputStreams; 00515 00516 media::MediaHandler* _mediaHandler; 00517 00519 void unplugCompletedInputStreams(); 00520 00522 // 00556 void playSound(int id, int loops, 00557 unsigned int inPoint, 00558 unsigned int outPoint, 00559 StreamBlockId blockId, const SoundEnvelopes* env, 00560 bool allowMultiple); 00561 00563 // 00577 unsigned int swfToOutSamples(const media::SoundInfo& sinfo, 00578 unsigned int swfSamples); 00579 00580 boost::scoped_ptr<WAVWriter> _wavWriter; 00581 00582 }; 00583 00584 // TODO: move to appropriate specific sound handlers 00585 00586 #ifdef SOUND_SDL 00587 00588 DSOEXPORT sound_handler* create_sound_handler_sdl(media::MediaHandler* m); 00589 #elif defined(SOUND_AHI) 00590 00591 DSOEXPORT sound_handler* create_sound_handler_aos4(media::MediaHandler* m); 00592 #elif defined(SOUND_MKIT) 00593 00594 DSOEXPORT sound_handler* create_sound_handler_mkit(media::MediaHandler* m); 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: