Ticket #8870: audiostream.patch
File audiostream.patch, 5.0 KB (added by , 16 years ago) |
---|
-
audiostream.cpp
99 99 } 100 100 101 101 #pragma mark - 102 #pragma mark --- FixedLengthAudioStream --- 103 #pragma mark - 104 105 uint32 FixedLengthAudioStream::getPlayTime(int rate) const { 106 const uint32 samples = getSampleCount(); 107 uint32 usedRate = (rate == -1) ? getRate() : rate; 108 109 uint32 seconds = samples / usedRate; 110 uint32 milliseconds = (1000 * (samples % usedRate)) / usedRate; 111 112 return 1000 * seconds + milliseconds; 113 } 114 115 #pragma mark - 102 116 #pragma mark --- LinearMemoryStream --- 103 117 #pragma mark - 104 118 … … 114 128 * case. This results in a total of 12 versions of the code being generated. 115 129 */ 116 130 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> 117 class LinearMemoryStream : public AudioStream {131 class LinearMemoryStream : public FixedLengthAudioStream { 118 132 protected: 119 133 const byte *_ptr; 120 134 const byte *_end; 121 135 const byte *_loopPtr; 122 136 const byte *_loopEnd; 123 137 const int _rate; 138 uint _samples; 124 139 const byte *_origPtr; 125 140 126 141 public: 127 142 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) {143 : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate), _samples(len) { 129 144 130 145 // Verify the buffer sizes are sane 131 146 if (is16Bit && stereo) … … 133 148 else if (is16Bit || stereo) 134 149 assert((len & 1) == 0 && (loopLen & 1) == 0); 135 150 151 if (is16Bit) 152 _samples /= 2; 153 if (stereo) 154 _samples /= 2; 155 136 156 if (loopLen) { 137 157 _loopPtr = _ptr + loopOffset; 138 158 _loopEnd = _loopPtr + loopLen; … … 151 171 bool endOfData() const { return _ptr >= _end; } 152 172 153 173 int getRate() const { return _rate; } 174 175 uint getSampleCount() const { return _samples; } 154 176 }; 155 177 156 178 template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE> … … 172 194 return numSamples-samples; 173 195 } 174 196 175 176 197 #pragma mark - 177 198 #pragma mark --- Input stream factory --- 178 199 #pragma mark - … … 195 216 } else \ 196 217 return new LinearMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree) 197 218 198 AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd) {219 FixedLengthAudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd) { 199 220 const bool isStereo = (flags & Audio::Mixer::FLAG_STEREO) != 0; 200 221 const bool is16Bit = (flags & Audio::Mixer::FLAG_16BITS) != 0; 201 222 const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0; -
voc.cpp
156 156 return loadVOCFromStream(stream, size, rate, loops, begin_loop, end_loop); 157 157 } 158 158 159 AudioStream *makeVOCStream(Common::ReadStream &stream) {159 FixedLengthAudioStream *makeVOCStream(Common::ReadStream &stream) { 160 160 int size, rate; 161 161 byte *data = loadVOCFromStream(stream, size, rate); 162 162 -
audiostream.h
96 96 }; 97 97 98 98 /** 99 * An audio stream with fixed length 100 */ 101 class FixedLengthAudioStream : public Audio::AudioStream { 102 public: 103 104 /** 105 * Returns the number of samples of the stream. 106 */ 107 virtual uint getSampleCount() const = 0; 108 109 /** 110 * Returns play time in milliseconds. 111 * 112 * @param rate sample rate the stream will be played at, -1 is sample rate from the stream itself 113 */ 114 virtual uint32 getPlayTime(int rate = -1) const; 115 }; 116 117 /** 99 118 * Factory function for a raw linear AudioStream, which will simply treat all data 100 119 * in the buffer described by ptr and len as raw sample data in the specified 101 120 * format. It will then simply pass this data directly to the mixer, after converting 102 121 * it to the sample format used by the mixer (i.e. 16 bit signed native endian). 103 122 * Optionally supports (infinite) looping of a portion of the data. 104 123 */ 105 AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd);124 FixedLengthAudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd); 106 125 107 126 /** 108 127 * An audio stream to which additional data can be appended on-the-fly. … … 134 153 */ 135 154 AppendableAudioStream *makeAppendableAudioStream(int rate, byte flags); 136 155 137 138 156 } // End of namespace Audio 139 157 140 158 #endif -
voc.h
32 32 33 33 namespace Audio { 34 34 35 class AudioStream;35 class FixedLengthAudioStream; 36 36 37 37 38 38 #include "common/pack-start.h" // START STRUCT PACKING … … 80 80 * 81 81 * This function uses loadVOCFromStream() internally. 82 82 */ 83 AudioStream *makeVOCStream(Common::ReadStream &stream);83 FixedLengthAudioStream *makeVOCStream(Common::ReadStream &stream); 84 84 85 85 } // End of namespace Audio 86 86