ScummVM API documentation
audio.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 TWP_AUDIO_H
23
#define TWP_AUDIO_H
24
25
#include "common/str.h"
26
#include "common/array.h"
27
#include "common/stream.h"
28
#include "audio/mixer.h"
29
#include "twp/ggpack.h"
30
31
namespace
Audio
{
32
33
class
SeekableAudioStream;
34
}
35
36
namespace
Twp
{
37
38
enum
{
39
NUM_AUDIO_SLOTS = 32
40
};
41
42
class
AudioChannel;
43
class
SoundDefinition;
44
45
class
SoundDefinition;
46
class
SoundStream
:
public
Common::SeekableReadStream
{
47
public
:
48
void
open(
Common::SharedPtr<SoundDefinition>
sndDef);
49
50
virtual
uint32 read(
void
*dataPtr, uint32 dataSize)
override
;
51
virtual
bool
eos()
const override
;
52
53
virtual
int64 pos()
const override
;
54
virtual
int64 size()
const override
;
55
virtual
bool
seek(int64 offset,
int
whence = SEEK_SET)
override
;
56
57
private
:
58
MemStream
_stream;
59
};
60
61
class
SoundDefinition
{
62
public
:
63
friend
class
SoundStream
;
64
65
public
:
66
SoundDefinition
(
const
Common::String
&name);
67
68
void
load();
69
int
getId()
const
{
return
_id; }
70
Common::String
getName()
const
{
return
_name; }
71
72
private
:
73
int
_id;
// identifier for this sound
74
Common::String
_name;
// name of the sound to load
75
Common::Array<byte>
_buffer;
// buffer containing the sound data
76
bool
_loaded =
false
;
// indicates whether or not the sound buffer has been loaded
77
};
78
79
struct
AudioSlot
{
80
Audio::SoundHandle
handle;
// handle returned when this sound has been played
81
Common::SharedPtr<SoundDefinition>
sndDef;
// sound definition associated to this slot
82
SoundStream
stream;
// audio stream
83
bool
busy =
false
;
// is sound active
84
float
volume = 1.f;
// actual volume for this slot
85
float
fadeInTimeMs = 0.f;
// fade-in time in milliseconds
86
float
fadeOutTimeMs = 0.f;
// fade-out time in milliseconds
87
int
total = 0;
// duration of the sound in milliseconds
88
int
id
= 0;
// unique sound ID
89
int
objId = 0;
// object ID or 0 if none
90
int
loopTimes = 0;
// specified number of times to loop
91
Audio::Mixer::SoundType
soundType =
Audio::Mixer::kPlainSoundType
;
// sound type: plain, music, sfx, speech
92
};
93
94
class
AudioSystem
{
95
public
:
96
int
play(
Common::SharedPtr<SoundDefinition>
sndDef,
Audio::Mixer::SoundType
cat,
int
loopTimes = 0,
float
fadeInTimeMs = 0.f,
float
volume = 1.f,
int
objId = 0);
97
98
bool
playing(
int
id
)
const
;
99
bool
playing(
Common::SharedPtr<SoundDefinition>
soundDef)
const
;
100
101
void
fadeOut(
int
id
,
float
fadeTime);
102
void
stop(
int
id
);
103
104
void
setMasterVolume(
float
vol);
105
float
getMasterVolume()
const
;
106
void
setVolume(
int
id
,
float
vol);
107
108
int
getElapsed(
int
id
)
const
;
109
int
getDuration(
int
id
)
const
;
110
111
void
update(
float
elapsed);
112
113
Common::Array<Common::SharedPtr<SoundDefinition>
> _soundDefs;
114
AudioSlot
_slots[NUM_AUDIO_SLOTS];
115
Common::SharedPtr<SoundDefinition>
_soundHover;
// not used yet, should be used in the GUI
116
117
private
:
118
void
updateVolume(
AudioSlot
*slot);
119
AudioSlot
*getFreeSlot();
120
121
private
:
122
float
_masterVolume = 1.f;
123
};
124
125
}
// End of namespace Twp
126
127
#endif // TWP_H
Common::String
Definition:
str.h:59
Common::Array< byte >
Twp::MemStream
Definition:
ggpack.h:42
Common::SeekableReadStream
Definition:
stream.h:745
Twp::SoundDefinition
Definition:
audio.h:61
Audio::SoundHandle
Definition:
mixer.h:49
Audio::Mixer::SoundType
SoundType
Definition:
mixer.h:62
Twp::SoundStream
Definition:
audio.h:46
Twp::AudioSystem
Definition:
audio.h:94
Common::SharedPtr
Definition:
ptr.h:159
Twp::AudioSlot
Definition:
audio.h:79
Audio
Definition:
system.h:38
Audio::Mixer::kPlainSoundType
Definition:
mixer.h:63
Twp
Definition:
achievements_tables.h:27
engines
twp
audio.h
Generated on Fri Nov 22 2024 09:05:34 for ScummVM API documentation by
1.8.13