Ticket #8870: audiostream_v2.patch

File audiostream_v2.patch, 2.2 KB (added by lordhoto, 16 years ago)

patch against current svn (Fingolfin's suggestion)

  • audiostream.cpp

     
    102102#pragma mark --- LinearMemoryStream ---
    103103#pragma mark -
    104104
     105inline int32 calculatePlayTime(int rate, int samples) {
     106        int32 seconds = samples / rate;
     107        int32 milliseconds = (1000 * (samples % rate)) / rate;
     108        return seconds * 1000 + milliseconds;
     109}
    105110
    106111/**
    107112 * A simple raw audio stream, purely memory based. It operates on a single
     
    122127        const byte *_loopEnd;
    123128        const int _rate;
    124129        const byte *_origPtr;
     130        const int32 _playtime;
    125131
    126132public:
    127133        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))) {
    129135
    130136                // Verify the buffer sizes are sane
    131137                if (is16Bit && stereo)
     
    147153        }
    148154        int readBuffer(int16 *buffer, const int numSamples);
    149155
    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; }
    152158
    153         int getRate() const                     { return _rate; }
     159        int getRate() const                             { return _rate; }
     160        int32 getTotalPlayTime() const  { return _playtime; }
    154161};
    155162
    156163template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
  • audiostream.h

     
    9393         *                      NULL in case of an error (e.g. invalid/nonexisting file)
    9494         */
    9595        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; }
    96110};
    97111
    98112/**