Ticket #8870: audiostream.patch

File audiostream.patch, 5.0 KB (added by lordhoto, 16 years ago)

patch against current svn

  • audiostream.cpp

     
    9999}
    100100
    101101#pragma mark -
     102#pragma mark --- FixedLengthAudioStream ---
     103#pragma mark -
     104
     105uint32 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 -
    102116#pragma mark --- LinearMemoryStream ---
    103117#pragma mark -
    104118
     
    114128 * case. This results in a total of 12 versions of the code being generated.
    115129 */
    116130template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
    117 class LinearMemoryStream : public AudioStream {
     131class LinearMemoryStream : public FixedLengthAudioStream {
    118132protected:
    119133        const byte *_ptr;
    120134        const byte *_end;
    121135        const byte *_loopPtr;
    122136        const byte *_loopEnd;
    123137        const int _rate;
     138        uint _samples;
    124139        const byte *_origPtr;
    125140
    126141public:
    127142        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) {
    129144
    130145                // Verify the buffer sizes are sane
    131146                if (is16Bit && stereo)
     
    133148                else if (is16Bit || stereo)
    134149                        assert((len & 1) == 0 && (loopLen & 1) == 0);
    135150
     151                if (is16Bit)
     152                        _samples /= 2;
     153                if (stereo)
     154                        _samples /= 2;
     155
    136156                if (loopLen) {
    137157                        _loopPtr = _ptr + loopOffset;
    138158                        _loopEnd = _loopPtr + loopLen;
     
    151171        bool endOfData() const          { return _ptr >= _end; }
    152172
    153173        int getRate() const                     { return _rate; }
     174
     175        uint getSampleCount() const     { return _samples; }
    154176};
    155177
    156178template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
     
    172194        return numSamples-samples;
    173195}
    174196
    175 
    176197#pragma mark -
    177198#pragma mark --- Input stream factory ---
    178199#pragma mark -
     
    195216                } else \
    196217                        return new LinearMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree)
    197218
    198 AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd) {
     219FixedLengthAudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd) {
    199220        const bool isStereo   = (flags & Audio::Mixer::FLAG_STEREO) != 0;
    200221        const bool is16Bit    = (flags & Audio::Mixer::FLAG_16BITS) != 0;
    201222        const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0;
  • voc.cpp

     
    156156        return loadVOCFromStream(stream, size, rate, loops, begin_loop, end_loop);
    157157}
    158158
    159 AudioStream *makeVOCStream(Common::ReadStream &stream) {
     159FixedLengthAudioStream *makeVOCStream(Common::ReadStream &stream) {
    160160        int size, rate;
    161161        byte *data = loadVOCFromStream(stream, size, rate);
    162162
  • audiostream.h

     
    9696};
    9797
    9898/**
     99 * An audio stream with fixed length
     100 */
     101class FixedLengthAudioStream : public Audio::AudioStream {
     102public:
     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/**
    99118 * Factory function for a raw linear AudioStream, which will simply treat all data
    100119 * in the buffer described by ptr and len as raw sample data in the specified
    101120 * format. It will then simply pass this data directly to the mixer, after converting
    102121 * it to the sample format used by the mixer (i.e. 16 bit signed native endian).
    103122 * Optionally supports (infinite) looping of a portion of the data.
    104123 */
    105 AudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd);
     124FixedLengthAudioStream *makeLinearInputStream(const byte *ptr, uint32 len, int rate, byte flags, uint loopStart, uint loopEnd);
    106125
    107126/**
    108127 * An audio stream to which additional data can be appended on-the-fly.
     
    134153 */
    135154AppendableAudioStream *makeAppendableAudioStream(int rate, byte flags);
    136155
    137 
    138156} // End of namespace Audio
    139157
    140158#endif
  • voc.h

     
    3232
    3333namespace Audio {
    3434
    35 class AudioStream;
     35class FixedLengthAudioStream;
    3636
    3737
    3838#include "common/pack-start.h"  // START STRUCT PACKING
     
    8080 *
    8181 * This function uses loadVOCFromStream() internally.
    8282 */
    83 AudioStream *makeVOCStream(Common::ReadStream &stream);
     83FixedLengthAudioStream *makeVOCStream(Common::ReadStream &stream);
    8484
    8585} // End of namespace Audio
    8686