ScummVM API documentation
sound.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 MOHAWK_SOUND_H
23 #define MOHAWK_SOUND_H
24 
25 #include "common/array.h"
26 #include "common/scummsys.h"
27 #include "common/str.h"
28 #include "common/stream.h"
29 
30 #include "audio/mixer.h"
31 
32 class MidiDriver;
33 class MidiParser;
34 
35 namespace Audio {
36 class RewindableAudioStream;
37 }
38 
39 namespace Mohawk {
40 
41 #define MAX_CHANNELS 2 // Can there be more than 2?
42 
43 enum SndHandleType {
44  kFreeHandle,
45  kUsedHandle
46 };
47 
48 struct SndHandle {
49  Audio::SoundHandle handle;
50  SndHandleType type;
51  uint samplesPerSecond;
52  uint16 id;
53 };
54 
55 struct ADPCMStatus { // Holds ADPCM status data, but is irrelevant for us.
56  uint32 size;
57  uint16 itemCount;
58  uint16 channels;
59 
60  struct StatusItem {
61  uint32 sampleFrame;
62  struct {
63  int16 last;
64  uint16 stepIndex;
65  } channelStatus[MAX_CHANNELS];
66  } *statusItems;
67 };
68 
69 struct CueListPoint {
70  uint32 sampleFrame;
71  Common::String name;
72 };
73 
74 struct CueList {
75  uint32 size;
76  uint16 pointCount;
78 };
79 
80 enum {
81  kCodecRaw = 0,
82  kCodecADPCM = 1,
83  kCodecMPEG2 = 2
84 };
85 
86 struct DataChunk {
87  uint16 sampleRate;
88  uint32 sampleCount;
89  byte bitsPerSample;
90  byte channels;
91  uint16 encoding;
92  uint16 loopCount; // 0 == no looping, 0xFFFF == infinite loop
93  uint32 loopStart;
94  uint32 loopEnd;
95  Common::SeekableReadStream *audioData;
96 };
97 
98 Audio::RewindableAudioStream *makeMohawkWaveStream(Common::SeekableReadStream *stream, CueList *cueList = nullptr);
99 
100 class MohawkEngine;
101 
102 class Sound {
103 public:
104  explicit Sound(MohawkEngine *vm);
105  ~Sound();
106 
107  // Generic sound functions
108  Audio::SoundHandle *playSound(uint16 id, byte volume = Audio::Mixer::kMaxChannelVolume, bool loop = false, CueList *cueList = NULL);
109  void stopSound();
110  void stopSound(uint16 id);
111  bool isPlaying(uint16 id);
112  bool isPlaying();
113  uint getNumSamplesPlayed(uint16 id);
114 
115 private:
116  MohawkEngine *_vm;
117 
118  static Audio::RewindableAudioStream *makeLivingBooksWaveStream_v1(Common::SeekableReadStream *stream);
119 
120  Common::Array<SndHandle> _handles;
121  SndHandle *getHandle();
122  Audio::RewindableAudioStream *makeAudioStream(uint16 id, CueList *cueList = nullptr);
123 };
124 
125 } // End of namespace Mohawk
126 
127 #endif
Definition: str.h:59
Definition: array.h:52
Definition: stream.h:745
Definition: mididrv.h:309
Definition: mixer.h:49
Definition: sound.h:102
Definition: sound.h:60
Definition: sound.h:48
Definition: sound.h:74
Definition: mohawk.h:54
Definition: sound.h:86
Definition: audiostream.h:109
Definition: mixer.h:71
Definition: sound.h:69
Definition: sound.h:55
Definition: system.h:38
Definition: midiparser.h:289
Definition: bitmap.h:32