summaryrefslogtreecommitdiff
path: root/src/d/snd/d_snd_se_sound.cpp
blob: 45cb097710e5837421a00e018b4af3530118f342 (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
#include "d/snd/d_snd_se_sound.h"

#include "common.h"
#include "d/snd/d_snd_source.h"

dSndSeSound_c::dSndSeSound_c()
    : mpSource(nullptr),
      mpSoundHandle(&mSound),
      mHandleType(SE_HANDLE_TYPE_1),
      mSoundId(-1),
      field_0x114(-1),
      field_0x11C(1),
      field_0x11D(0),
      field_0x11E(0),
      mpStartCallback(nullptr),
      mpCalcCallback(nullptr) {
    mpCtxParam = new dSndSoundCtxParam[10];
}

dSndSeSound_c::~dSndSeSound_c() {
    delete[] mpCtxParam;
}

void dSndSeSound_c::setSource(dSoundSource_c *source, u32 soundId) {
    clear();
    mSoundId = soundId;
    field_0x114 = 0;
    dSndSoundCtxParam* s = mpCtxParam;
    while (s < &mpCtxParam[10]) {
        s->intParam = 0;
        s->floatParam = 0.0f;
        s++;
    }

    mpCalcCallback = nullptr;
    mpStartCallback = nullptr;
    field_0x11D = 0;
    field_0x11E = 0;
}

void dSndSeSound_c::clear() {
    field_0x114 = -1;
    mpSource = nullptr;
    mpCalcCallback = nullptr;
    mpStartCallback = nullptr;
    mpSoundHandle = &mSound;
    field_0x11C = 1;
    field_0x11D = 0;
    mSound.cancel();
}

void dSndSeSound_c::calc(dSoundSource_c *source) {
    onCalc(source);
    if (mpSoundHandle->IsPause() && mpSoundHandle->GetRemainingFadeFrames() == 0) {
        return;
    }
    field_0x114++;
}

void dSndSeSound_c::shiftParam(const dSndSoundCtxParam *pParam) {
    if (pParam == nullptr) {
        return;
    }

    for (int i = 9; i > 0; i--) {
        mpCtxParam[i] = mpCtxParam[i - 1];
    }
    mpCtxParam[0] = *pParam;
}

void dSndSeSound_c::shiftFloatParam(f32 value) {
    for (int i = 9; i > 0; i--) {
        mpCtxParam[i].floatParam = mpCtxParam[i - 1].floatParam;
    }
    mpCtxParam[0].floatParam = value;
}

void dSndSeSound_c::onStart(dSoundSource_c *source) {
    if (mpStartCallback != nullptr) {
        (mpStartCallback)(this, source, *mpSoundHandle);
    }
}

void dSndSeSound_c::onCalc(dSoundSource_c *source) {
    if (mpCalcCallback != nullptr) {
        (mpCalcCallback)(this, source, *mpSoundHandle);
    }
}