ScummVM API documentation
audio_process.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 ULTIMA8_AUDIO_AUDIOPROCESS_H
23 #define ULTIMA8_AUDIO_AUDIOPROCESS_H
24 
25 #include "ultima/ultima8/kernel/process.h"
26 #include "ultima/ultima8/usecode/intrinsics.h"
27 #include "ultima/shared/std/string.h"
28 #include "ultima/ultima8/misc/classtype.h"
29 
30 namespace Ultima {
31 namespace Ultima8 {
32 
33 class AudioSample;
34 
35 class AudioProcess : public Process {
36 public:
37 
38  static const uint32 PITCH_SHIFT_NONE;
39 
40  struct SampleInfo {
41  int32 _sfxNum;
42  int32 _priority;
43  ObjId _objId;
44  int32 _loops;
45  int32 _channel;
46  Std::string _barked;
47  uint32 _curSpeechStart, _curSpeechEnd;
48  uint32 _pitchShift; // PITCH_SHIFT_NONE is normal
49  uint16 _volume; // 0-255
50  int16 _calcVol;
51  int8 _balance;
52  bool _ambient;
53 
54  SampleInfo() : _sfxNum(-1) { }
55  SampleInfo(int32 s, int32 p, ObjId o, int32 l, int32 c, uint32 ps, uint16 v, int16 cv, int8 bal, bool ambient) :
56  _sfxNum(s), _priority(p), _objId(o), _loops(l), _channel(c),
57  _pitchShift(ps), _volume(v), _calcVol(cv), _balance(bal),
58  _curSpeechStart(0), _curSpeechEnd(0), _ambient(ambient) { }
59  SampleInfo(const Std::string &b, int32 shpnum, ObjId o, int32 c,
60  uint32 s, uint32 e, uint32 ps, uint16 v, int16 cv, int8 bal, bool ambient) :
61  _sfxNum(-1), _priority(shpnum), _objId(o), _loops(0), _channel(c), _barked(b),
62  _curSpeechStart(s), _curSpeechEnd(e), _pitchShift(ps), _volume(v),
63  _calcVol(cv), _balance(bal), _ambient(ambient) { }
64  };
65 
66  Std::list<SampleInfo> _sampleInfo;
67 public:
68  // p_dynamic_class stuff
69  ENABLE_RUNTIME_CLASSTYPE()
70 
71  AudioProcess(void);
72  ~AudioProcess(void) override;
73 
76  return _theAudioProcess;
77  }
78 
79  INTRINSIC(I_playSFX);
80  INTRINSIC(I_playAmbientSFX);
81  INTRINSIC(I_playSFXCru);
82  INTRINSIC(I_playAmbientSFXCru);
83  INTRINSIC(I_isSFXPlaying);
84  INTRINSIC(I_isSFXPlayingForObject);
85  INTRINSIC(I_setVolumeSFX);
86  INTRINSIC(I_setVolumeForObjectSFX);
87  INTRINSIC(I_stopSFX);
88  INTRINSIC(I_stopSFXCru);
89  INTRINSIC(I_stopAllSFX);
90 
91  void run() override;
92 
93  void playSFX(int sfxNum, int priority, ObjId objId, int loops,
94  bool no_duplicates, uint32 pitchShift,
95  uint16 volume, int16 calcVol, int8 balance,
96  bool ambient);
97 
98  void playSFX(int sfxNum, int priority, ObjId objId, int loops,
99  bool no_duplicates = false, uint32 pitchShift = PITCH_SHIFT_NONE,
100  uint16 volume = 0x80, bool ambient = false) {
101  playSFX(sfxNum, priority, objId, loops, no_duplicates, pitchShift, volume, -1, 0, ambient);
102  }
103 
105  void stopSFX(int sfxNum, ObjId objId);
106  bool isSFXPlaying(int sfxNum);
107  bool isSFXPlayingForObject(int sfxNum, ObjId objId);
108  void setVolumeSFX(int sfxNum, uint8 volume);
109  void setVolumeForObjectSFX(ObjId objId, int sfxNum, uint8 volume);
110 
111  bool playSpeech(const Std::string &barked, int shapenum, ObjId objId,
112  uint32 pitchShift = PITCH_SHIFT_NONE, uint16 volume = 255);
113  void stopSpeech(const Std::string &barked, int shapenum, ObjId objId);
114  bool isSpeechPlaying(const Std::string &barked, int shapenum);
115 
117  uint32 getSpeechLength(const Std::string &barked, int shapenum) const;
118 
121  int playSample(AudioSample *sample, int priority, int loops, bool isSpeech = false,
122  uint32 pitchShift = PITCH_SHIFT_NONE, int16 volume = 255,
123  int8 balance = 0, bool ambient = false);
124 
126  void pauseAllSamples();
128  void unpauseAllSamples();
129 
131  void stopAllExceptSpeech();
132 
133  bool loadData(Common::ReadStream *rs, uint32 version);
134  void saveData(Common::WriteStream *ws) override;
135 
136 private:
137  uint32 _paused;
138 
142  bool continueSpeech(SampleInfo &si);
143 
144  bool calculateSoundVolume(ObjId objId, int16 &volume, int8 &balance) const;
145 
146  static AudioProcess *_theAudioProcess;
147 };
148 
149 } // End of namespace Ultima8
150 } // End of namespace Ultima
151 
152 #endif
void saveData(Common::WriteStream *ws) override
save Process data
Definition: stream.h:77
Definition: audio_process.h:35
Definition: process.h:34
uint32 getSpeechLength(const Std::string &barked, int shapenum) const
get length (in milliseconds) of speech
int playSample(AudioSample *sample, int priority, int loops, bool isSpeech=false, uint32 pitchShift=PITCH_SHIFT_NONE, int16 volume=255, int8 balance=0, bool ambient=false)
Definition: detection.h:27
void pauseAllSamples()
pause all currently playing samples
Definition: string.h:30
Definition: containers.h:200
void unpauseAllSamples()
unpause all currently playing samples
Definition: stream.h:385
void stopSFX(int sfxNum, ObjId objId)
stop sfx on object. set sfxNum = -1 to stop all for object.
Definition: audio_sample.h:32
static AudioProcess * get_instance()
Get the current instance of the Audio Processes.
Definition: audio_process.h:75
void stopAllExceptSpeech()
stop all samples except speech
Definition: audio_process.h:40