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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#include "nw4r/snd/snd_StrmSound.h"
/* Original source:
* kiwi515/ogws
* src/nw4r/snd/snd_StrmSound.cpp
*/
/*******************************************************************************
* headers
*/
#include "common.h"
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundInstanceManager.h"
#include "nw4r/snd/snd_StrmPlayer.h"
#include "nw4r/snd/snd_StrmSoundHandle.h"
#include "nw4r/snd/snd_MoveValue.h"
#include "nw4r/ut/ut_Lock.h"
#include "nw4r/ut/ut_RuntimeTypeInfo.h"
#include "nw4r/NW4RAssert.hpp"
/*******************************************************************************
* types
*/
// forward declarations
namespace nw4r { namespace snd { namespace detail { class StrmBufferPool; }}}
namespace nw4r { namespace ut { class FileStream; }}
/*******************************************************************************
* variables
*/
namespace nw4r { namespace snd { namespace detail
{
// .sbss
ut::detail::RuntimeTypeInfo const StrmSound::typeInfo(
&BasicSound::typeInfo);
}}} // namespace nw4r::snd::detail
/*******************************************************************************
* functions
*/
namespace nw4r { namespace snd { namespace detail {
StrmSound::StrmSound(SoundInstanceManager<StrmSound> *manager, int priority,
int ambientPriority) :
BasicSound (priority, ambientPriority),
mTempSpecialHandle (nullptr),
mManager (manager)
{
}
void StrmSound::InitParam()
{
BasicSound::InitParam();
for (int i = 0; i < ARRAY_LENGTH(mTrackVolume); i++)
{
mTrackVolume[i].InitValue(0.0f);
mTrackVolume[i].SetTarget(1.0f, 1);
}
}
StrmPlayer::SetupResult StrmSound::Setup(StrmBufferPool *bufferPool,
int allocChannelCount,
u16 allocTrackFlag)
{
NW4RAssertPointerNonnull_Line(90, bufferPool);
InitParam();
return mStrmPlayer.Setup(bufferPool, allocChannelCount, allocTrackFlag,
GetVoiceOutCount());
}
bool StrmSound::Prepare(StrmPlayer::StartOffsetType startOffsetType, s32 offset,
ut::FileStream *fileStream)
{
bool result = mStrmPlayer.Prepare(fileStream, startOffsetType, offset);
if (!result)
{
mStrmPlayer.Shutdown();
return false;
}
return true;
}
void StrmSound::UpdateMoveValue()
{
BasicSound::UpdateMoveValue();
for (int trackNo = 0; trackNo < (int)ARRAY_LENGTH(mTrackVolume); trackNo++)
{
if (mStrmPlayer.GetPlayerTrack(trackNo))
mTrackVolume[trackNo].Update();
}
}
void StrmSound::UpdateParam()
{
BasicSound::UpdateParam();
for (int trackNo = 0; trackNo < (int)ARRAY_LENGTH(mTrackVolume); trackNo++)
{
if (mStrmPlayer.GetPlayerTrack(trackNo))
{
mStrmPlayer.SetTrackVolume(1 << trackNo,
mTrackVolume[trackNo].GetValue());
}
}
}
void StrmSound::SetTrackVolume(u32 trackFlags, f32 volume, int fadeFrames)
{
ut::AutoInterruptLock lock;
for (int trackNo = 0; trackNo < (int)ARRAY_LENGTH(mTrackVolume) && trackFlags != 0; trackNo++, trackFlags >>= 1)
{
StrmPlayer::StrmTrack *track = mStrmPlayer.GetPlayerTrack(trackNo);
if (track != NULL && ((trackFlags & 1) != 0))
{
if (volume < 0.0f)
volume = 0.0f;
mTrackVolume[trackNo].SetTarget(volume, fadeFrames);
}
}
}
void StrmSound::Shutdown()
{
BasicSound::Shutdown();
mManager->Free(this);
}
void StrmSound::OnUpdatePlayerPriority()
{
mManager->UpdatePriority(this, CalcCurrentPlayerPriority());
}
bool StrmSound::IsAttachedTempSpecialHandle()
{
return mTempSpecialHandle != nullptr;
}
void StrmSound::DetachTempSpecialHandle()
{
mTempSpecialHandle->DetachSound();
}
}}} // namespace nw4r::snd::detail
|