Gnash  0.8.10
EmbedSoundInst.h
Go to the documentation of this file.
00001 // EmbedSoundInst.h - instance of an embedded sound, for gnash
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 // 
00006 // This program 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 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program 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 this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 #ifndef SOUND_EMBEDSOUNDINST_H
00021 #define SOUND_EMBEDSOUNDINST_H
00022 
00023 #include <memory>
00024 #include <cassert>
00025 #include <boost/cstdint.hpp> // For C99 int types
00026 
00027 #include "LiveSound.h"
00028 #include "AudioDecoder.h" 
00029 #include "SoundEnvelope.h" 
00030 #include "EmbedSound.h" 
00031 #include "sound_handler.h" 
00032 
00033 // Forward declarations
00034 namespace gnash {
00035     namespace sound {
00036         class EmbedSound;
00037     }
00038     namespace media {
00039         class MediaHandler;
00040     }
00041 }
00042 
00043 namespace gnash {
00044 namespace sound {
00045 
00047 class EmbedSoundInst : public LiveSound
00048 {
00049 public:
00050 
00052     //
00067     EmbedSoundInst(EmbedSound& def, media::MediaHandler& mh,
00068             unsigned int inPoint, unsigned int outPoint,
00069             const SoundEnvelopes* envelopes, int loopCount);
00070 
00071     // See dox in sound_handler.h (InputStream)
00072     virtual bool eof() const;
00073 
00075     //
00077     virtual ~EmbedSoundInst();
00078 
00079 private:
00080 
00081     virtual size_t checkEarlierEnd(size_t bytesAhead, size_t pos) const {
00082         if (_outPoint < std::numeric_limits<unsigned long>::max()) {
00083             const size_t toCustomEnd = _outPoint - pos;
00084             return std::min(toCustomEnd, bytesAhead);
00085         }
00086         return bytesAhead;
00087     }
00088 
00089     virtual bool moreData();
00090 
00092     //
00109     void applyEnvelopes(boost::int16_t* samples, unsigned int nSamples,
00110             unsigned int firstSampleNum, const SoundEnvelopes& env);
00111 
00112     bool reachedCustomEnd() const;
00113 
00115     virtual bool decodingCompleted() const {
00116         return (decodingPosition >= _soundDef.size());
00117     }
00118 
00120     //
00122     virtual void decodeNextBlock();
00123 
00125     unsigned long decodingPosition;
00126 
00129     long loopCount;
00130 
00133     const unsigned long _outPoint;
00134 
00137     const SoundEnvelopes* envelopes;
00138 
00140     boost::uint32_t current_env;
00141 
00143     //
00147     EmbedSound& _soundDef;
00148 
00149 };
00150 
00151 
00152 } // gnash.sound namespace 
00153 } // namespace gnash
00154 
00155 #endif // SOUND_EMBEDSOUNDINST_H