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 /*
23  * This code is based on original Soltys source code
24  * Copyright (c) 1994-1995 Janusz B. Wisniewski and L.K. Avalon
25  */
26 
27 #ifndef CGE_SOUND_H
28 #define CGE_SOUND_H
29 
30 #include "cge/fileio.h"
31 #include "audio/midiplayer.h"
32 #include "audio/mixer.h"
33 #include "common/memstream.h"
34 
35 namespace Audio {
36 class RewindableAudioStream;
37 }
38 
39 namespace CGE {
40 
41 class CGEEngine;
42 
43 // sample info
44 struct SmpInfo {
45  const uint8 *_saddr; // address
46  uint16 _slen; // length
47  uint16 _span; // left/right pan (0-15)
48  int _counter; // number of time the sample should be played
49 };
50 
51 class DataCk {
52  byte *_buf;
53  int _ckSize;
54 public:
55  DataCk(byte *buf, int bufSize);
56  ~DataCk();
57  inline const byte *addr() {
58  return _buf;
59  }
60  inline int size() {
61  return _ckSize;
62  }
63 };
64 
65 class Sound {
66 public:
67  SmpInfo _smpinf;
68 
69  Sound(CGEEngine *vm);
70  ~Sound();
71  void open();
72  void close();
73  void play(DataCk *wav, int pan);
74  int16 getRepeat();
75  void setRepeat(int16 count);
76  void stop();
77 private:
78  int _soundRepeatCount;
79  CGEEngine *_vm;
80  Audio::SoundHandle _soundHandle;
81  Audio::RewindableAudioStream *_audioStream;
82 
83  void sndDigiStart(SmpInfo *PSmpInfo);
84  void sndDigiStop(SmpInfo *PSmpInfo);
85 };
86 
87 class Fx {
88  CGEEngine *_vm;
89  struct Handler {
90  int _ref;
91  DataCk *_wav;
92  } *_cache;
93  int _size;
94 
95  DataCk *load(int idx, int ref);
96  DataCk *loadWave(EncryptedStream *file);
97  int find(int ref);
98 public:
99  DataCk *_current;
100 
101  Fx(CGEEngine *vm, int size);
102  ~Fx();
103  void clear();
104  void preload(int ref0);
105  DataCk *operator[](int ref);
106 };
107 
109 private:
110  CGEEngine *_vm;
111  byte *_data;
112  int _dataSize;
113  bool _isGM;
114 
115  // Start MIDI File
116  void sndMidiStart();
117 
118  // Stop MIDI File
119  void sndMidiStop();
120 public:
121  MusicPlayer(CGEEngine *vm);
122  ~MusicPlayer() override;
123 
124  void loadMidi(int ref);
125  void killMidi();
126 
127  void send(uint32 b) override;
128  void sendToChannel(byte channel, uint32 b) override;
129 };
130 
131 } // End of namespace CGE
132 
133 #endif
134 
Definition: midiplayer.h:63
Definition: sound.h:51
Definition: sound.h:44
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: sound.h:87
Definition: cge.h:150
Definition: mixer.h:49
Definition: fileio.h:98
Definition: sound.h:108
Definition: audiostream.h:109
Definition: bitmap.h:33
Definition: sound.h:65
Definition: system.h:38