Ticket #8870: audiostream_v2.patch
File audiostream_v2.patch, 2.2 KB (added by , 16 years ago) |
---|
-
audiostream.cpp
102 102 #pragma mark --- LinearMemoryStream --- 103 103 #pragma mark - 104 104 105 inline int32 calculatePlayTime(int rate, int samples) { 106 int32 seconds = samples / rate; 107 int32 milliseconds = (1000 * (samples % rate)) / rate; 108 return seconds * 1000 + milliseconds; 109 } 105 110 106 111 /** 107 112 * A simple raw audio stream, purely memory based. It operates on a single … … 122 127 const byte *_loopEnd; 123 128 const int _rate; 124 129 const byte *_origPtr; 130 const int32 _playtime; 125 131 126 132 public: 127 133 LinearMemoryStream(int rate, const byte *ptr, uint len, uint loopOffset, uint loopLen, bool autoFreeMemory) 128 : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate) {134 : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _playtime(calculatePlayTime(rate, len / (is16Bit ? 2 : 1) / (stereo ? 2 : 1))) { 129 135 130 136 // Verify the buffer sizes are sane 131 137 if (is16Bit && stereo) … … 147 153 } 148 154 int readBuffer(int16 *buffer, const int numSamples); 149 155 150 bool isStereo() const { return stereo; }151 bool endOfData() const { return _ptr >= _end; }156 bool isStereo() const { return stereo; } 157 bool endOfData() const { return _ptr >= _end; } 152 158 153 int getRate() const { return _rate; } 159 int getRate() const { return _rate; } 160 int32 getTotalPlayTime() const { return _playtime; } 154 161 }; 155 162 156 163 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> -
audiostream.h
93 93 * NULL in case of an error (e.g. invalid/nonexisting file) 94 94 */ 95 95 static AudioStream* openStreamFile(const Common::String &basename, uint32 startTime = 0, uint32 duration = 0, uint numLoops = 1); 96 97 enum { 98 kUnknownPlayTime = -1 99 }; 100 101 /** 102 * Returns total playtime of the AudioStream object. 103 * Note that this does not require to return an playtime, if the 104 * playtime of the AudioStream is unknown it returns 'kUnknownPlayTime'. 105 * @see kUnknownPlayTime 106 * 107 * @return playtime in milliseconds 108 */ 109 int32 getTotalPlayTime() const { return kUnknownPlayTime; } 96 110 }; 97 111 98 112 /**