ScummVM API documentation
sampleloop.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef VCRUISE_SAMPLELOOP_H
23 #define VCRUISE_SAMPLELOOP_H
24 
25 #include "common/ptr.h"
26 #include "common/mutex.h"
27 
28 #include "audio/audiostream.h"
29 
30 namespace Common {
31 
32 class ReadStream;
33 
34 } // End of namespace Common
35 
36 namespace VCruise {
37 
38 struct SampleLoop {
39  SampleLoop();
40 
41  bool read(Common::ReadStream &stream, uint &availableBytes);
42 
43  uint32 identifier;
44  uint32 type;
45  uint32 start;
46  uint32 end;
47  uint32 fraction;
48  uint32 playCount;
49 };
50 
51 struct SampleChunk {
52  SampleChunk();
53 
54  bool read(Common::ReadStream &stream, uint &availableBytes);
55 
56  uint32 manufacturer;
57  uint32 product;
58  uint32 samplePeriod;
59  uint32 midiUnityNote;
60  uint32 midiPitchFraction;
61  uint32 smpteFormat;
62  uint32 smpteOffset;
63 
64  // uint32 numSampleLoops;
65  // uint32 sizeOfSamplerData;
66 
68  Common::Array<byte> samplerData;
69 };
70 
71 struct SoundLoopInfo {
72  SampleChunk _sampleChunk;
73 
74  static Common::SharedPtr<SoundLoopInfo> readFromWaveFile(Common::SeekableReadStream &stream);
75 };
76 
78 public:
80  virtual ~SampleLoopAudioStream();
81 
82  void stopLooping();
83 
84  int readBuffer(int16 *buffer, const int numSamples) override;
85  bool isStereo() const override;
86  int getRate() const override;
87  bool endOfData() const override;
88 
89 private:
90  struct LoopRange {
91  LoopRange();
92 
93  Audio::Timestamp _restartTimestamp;
94 
95  uint _startSampleInclusive;
96  uint _endSampleExclusive;
97  uint _playCount;
98  };
99 
100  Common::Mutex _mutex;
101 
102  int _currentSampleOffset;
103  int _currentLoop;
104  uint _currentLoopIteration;
105  int _streamFrames;
106  int _streamSamples;
107  bool _terminated;
108  bool _ignoreLoops;
109 
110  Common::Array<LoopRange> _loopRanges;
111 
112  Audio::SeekableAudioStream *_baseStream;
113 };
114 
115 } // End of namespace VCruise
116 
117 #endif
Definition: sampleloop.h:71
Definition: array.h:52
Definition: timestamp.h:83
Definition: stream.h:745
Definition: audiostream.h:212
Definition: ad2044_items.h:27
Definition: sampleloop.h:51
Definition: algorithm.h:29
Definition: mutex.h:67
Definition: audiostream.h:50
Definition: sampleloop.h:38
Definition: stream.h:385
Definition: sampleloop.h:77
Definition: ptr.h:159