blob: d6ab1bac3e8cc854163a366897e3b57df39a1aef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#include "common.h"
#include "d/snd/d_snd_calc_pitch.h"
#include "d/snd/d_snd_sound.h"
#include "nw4r/snd/snd_SeqSoundHandle.h"
#include "nw4r/snd/snd_StrmSoundHandle.h"
// I'm not super happy with these base class function in a separate file,
// but either we add another intermediate class or this is ok. It's weird
// that d_snd_sound has dSndControl_c::configure though
void dSndControl_c::reset() {
mCurrValue = mResetValue;
mStartValue = mResetValue;
mTargetValue = mResetValue;
mDuration = 0;
mTimer = 0;
}
void dSndControl_c::stop() {
mStartValue = mCurrValue;
mTargetValue = mCurrValue;
mDuration = 0;
mTimer = 0;
}
void dSndControl_c::set(f32 value, s32 frames) {
stop();
f32 clamped = value;
if (clamped > mMax) {
clamped = mMax;
} else if (clamped < mMin) {
clamped = mMin;
}
if (clamped != mCurrValue) {
mTargetValue = clamped;
if (frames == 0) {
mCurrValue = clamped;
} else {
mDuration = frames;
mTimer = 0;
}
}
}
void dSndControl_c::calc() {
if (mTimer < mDuration) {
mTimer++;
if (mTimer == mDuration) {
mCurrValue = mTargetValue;
} else {
mCurrValue = mStartValue + (mTimer * (mTargetValue - mStartValue) / mDuration);
}
}
}
void dSndControlSoundVolume_c::apply(dSndSound_c *sound) {
sound->SetVolume(mCurrValue, 0);
}
void dSndControlSoundPitch_c::apply(dSndSound_c *sound) {
sound->SetPitch(mCurrValue);
}
void d_snd_control_sound_float_order() {
-24.0f;
24.0f;
}
dSndControlSoundPitchLinear_c::dSndControlSoundPitchLinear_c() : dSndControlSound_c(0.0f, -24.0f, 24.0f) {
mpOtherControl = nullptr;
}
void dSndControlSoundPitchLinear_c::set(f32 value, s32 frames) {
if (mpOtherControl != nullptr) {
mCurrValue = pitchIdxTenthsForPitchScale(mpOtherControl->getCurrentValue());
}
dSndControlSound_c::set(value, frames);
}
void dSndControlSoundPitchLinear_c::apply(dSndSound_c *pHandle) {
pHandle->setPitchRelated(pitchScaleForPitchIdxTenths(mCurrValue), 0);
}
void dSndControlSoundSeqTempoRatio_c::apply(dSndSound_c *sound) {
nw4r::snd::SeqSoundHandle handle(sound);
handle.SetTempoRatio(mCurrValue);
}
void dSndControlSoundSeqTrackVolume_c::apply(dSndSound_c *sound) {
nw4r::snd::SeqSoundHandle handle(sound);
handle.SetVolume(mMask, mCurrValue);
}
void dSndControlSoundStrmTrackVolume_c::apply(dSndSound_c *sound) {
nw4r::snd::StrmSoundHandle handle(sound);
handle.SetVolume(mMask, mCurrValue, 0);
}
|