Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SOUND_EMBEDSOUNDINST_H
00021 #define SOUND_EMBEDSOUNDINST_H
00022
00023 #include "InputStream.h"
00024 #include "AudioDecoder.h"
00025 #include "SoundEnvelope.h"
00026 #include "SimpleBuffer.h"
00027 #include "EmbedSound.h"
00028 #include "sound_handler.h"
00029
00030 #include <memory>
00031 #include <cassert>
00032 #include <boost/cstdint.hpp>
00033
00034
00035
00036 namespace gnash {
00037 namespace sound {
00038 class EmbedSound;
00039 }
00040 namespace media {
00041 class MediaHandler;
00042 }
00043 }
00044
00045 namespace gnash {
00046 namespace sound {
00047
00049
00056 class EmbedSoundInst : public InputStream
00057 {
00058 public:
00059
00061
00091 EmbedSoundInst(EmbedSound& def, media::MediaHandler& mh,
00092 sound_handler::StreamBlockId blockId,
00093 unsigned int inPoint,
00094 unsigned int outPoint,
00095 const SoundEnvelopes* envelopes,
00096 unsigned int loopCount);
00097
00098
00099 unsigned int fetchSamples(boost::int16_t* to, unsigned int nSamples);
00100
00101
00102 unsigned int samplesFetched() const;
00103
00104
00105 bool eof() const;
00106
00108
00111 ~EmbedSoundInst();
00112
00113 private:
00114
00116 unsigned long decodingPosition;
00117
00119 unsigned long playbackPosition;
00120
00123 long loopCount;
00124
00127 unsigned long _inPoint;
00128
00131 unsigned long _outPoint;
00132
00135 const SoundEnvelopes* envelopes;
00136
00138 boost::uint32_t current_env;
00139
00141 unsigned long _samplesFetched;
00142
00144 const EmbedSound& getSoundData() {
00145 return _soundDef;
00146 }
00147
00149
00156 void appendDecodedData(boost::uint8_t* data, unsigned int size);
00157
00159
00166 void setDecodedData(boost::uint8_t* data, unsigned int size)
00167 {
00168 if ( ! _decodedData.get() )
00169 {
00170 _decodedData.reset( new SimpleBuffer() );
00171 }
00172
00173 _decodedData->resize(0);
00174 _decodedData->append(data, size);
00175 delete [] data;
00176 }
00177
00178 size_t encodedDataSize() const
00179 {
00180 return _soundDef.size();
00181 }
00182
00184
00204 void applyEnvelopes(boost::int16_t* samples, unsigned int nSamples,
00205 unsigned int firstSampleNum,
00206 const SoundEnvelopes& env);
00207
00209
00219 static void adjustVolume(boost::int16_t* samples,
00220 unsigned int nSamples, float volume);
00221
00224
00229 const boost::uint8_t* getEncodedData(unsigned long int pos);
00230
00233 unsigned int decodedSamplesAhead() const
00234 {
00235 unsigned int dds = decodedDataSize();
00236 if ( dds <= playbackPosition ) return 0;
00237 unsigned int bytesAhead = dds - playbackPosition;
00238 assert(!(bytesAhead%2));
00239
00240 if ( _outPoint < std::numeric_limits<unsigned long>::max() )
00241 {
00242 unsigned int toCustomEnd = _outPoint-playbackPosition;
00243 if ( toCustomEnd < bytesAhead ) bytesAhead = toCustomEnd;
00244 }
00245
00246 unsigned int samplesAhead = bytesAhead/2;
00247
00248 return samplesAhead;
00249 }
00250
00251 bool reachedCustomEnd() const;
00252
00254 bool decodingCompleted() const
00255 {
00256
00257
00258
00259 return ( decodingPosition >= encodedDataSize() );
00260 }
00261
00262
00264 std::auto_ptr<media::AudioDecoder> _decoder;
00265
00267
00271 void createDecoder(media::MediaHandler& mediaHandler);
00272
00274 size_t decodedDataSize() const
00275 {
00276 if ( _decodedData.get() )
00277 {
00278 return _decodedData->size();
00279 }
00280 else return 0;
00281 }
00282
00286
00293 boost::int16_t* getDecodedData(unsigned long int pos);
00294
00296
00300 EmbedSound& _soundDef;
00301
00303
00307 std::auto_ptr<SimpleBuffer> _decodedData;
00308
00310
00313 void decodeNextBlock();
00314 };
00315
00316
00317 }
00318 }
00319
00320 #endif // SOUND_EMBEDSOUNDINST_H