summaryrefslogtreecommitdiff
path: root/src/nw4r/snd/snd_WaveSound.cpp
blob: 345500a2f81e4fad2609fc37246eb6b134682419 (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
100
101
102
103
104
105
#include "nw4r/snd/snd_WaveSound.h"

/* Original source:
 * kiwi515/ogws
 * src/nw4r/snd/snd_WaveSound.cpp
 */

/*******************************************************************************
 * headers
 */

#include "common.h"

#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundInstanceManager.h"
#include "nw4r/snd/snd_WaveSoundHandle.h"
#include "nw4r/snd/snd_WsdPlayer.h"

#include "nw4r/ut/ut_RuntimeTypeInfo.h"

#include "nw4r/NW4RAssert.hpp"

/*******************************************************************************
 * variables
 */

namespace nw4r { namespace snd { namespace detail
{
	// .sbss
	ut::detail::RuntimeTypeInfo const WaveSound::typeInfo(
		&BasicSound::typeInfo);
}}} // namespace nw4r::snd::detail

/*******************************************************************************
 * functions
 */

namespace nw4r { namespace snd { namespace detail {

WaveSound::WaveSound(SoundInstanceManager<WaveSound> *manager, int priority,
                     int ambientPriority) :
	BasicSound			(priority, ambientPriority),
	mTempSpecialHandle	(nullptr),
	mManager			(manager),
	mPreparedFlag		(false)
{
}

bool WaveSound::Prepare(void const *waveSoundBase, s32 waveSoundOffset,
                        WsdPlayer::StartOffsetType startOffsetType, s32 offset,
                        WsdPlayer::WsdCallback const *callback,
                        u32 callbackData)
{
	NW4RAssertPointerNonnull_Line(74, waveSoundBase);
	NW4RAssertPointerNonnull_Line(75, callback);

	InitParam();

	bool result =
		mWsdPlayer.Prepare(waveSoundBase, waveSoundOffset, startOffsetType,
	                       offset, GetVoiceOutCount(), callback, callbackData);
	if (!result)
		return false;

	mPreparedFlag = true;
	return true;
}

void WaveSound::Shutdown()
{
	BasicSound::Shutdown();

	mManager->Free(this);
}

void WaveSound::SetChannelPriority(int priority)
{
	// specifically not the source variant
	NW4RAssertHeaderClampedLRValue_Line(124, priority, BasicSound::PRIORITY_MIN,
	                                    BasicSound::PRIORITY_MAX);

	mWsdPlayer.SetChannelPriority(priority);
}

void WaveSound::SetReleasePriorityFix(bool flag)
{
	mWsdPlayer.SetReleasePriorityFix(flag);
}

void WaveSound::OnUpdatePlayerPriority()
{
	mManager->UpdatePriority(this, CalcCurrentPlayerPriority());
}

bool WaveSound::IsAttachedTempSpecialHandle()
{
	return mTempSpecialHandle != nullptr;
}

void WaveSound::DetachTempSpecialHandle()
{
	mTempSpecialHandle->DetachSound();
}

}}} // namespace nw4r::snd::detail