summaryrefslogtreecommitdiff
path: root/libs/JSystem/src/JAudio2/JASDrumSet.cpp
blob: 4e944c4fe2514ed096211525d22cf81d7cd2a505 (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
106
107
108
109
110
111
112
113
114
#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JAudio2/JASDrumSet.h"
#include "JSystem/JAudio2/JASCalc.h"
#include "JSystem/JKernel/JKRHeap.h"


JASDrumSet::JASDrumSet() {
    mPercArray = NULL;
    mPercNumMax = 0;
}

JASDrumSet::~JASDrumSet() {
}

void JASDrumSet::newPercArray(u8 num, JKRHeap* heap) {
    if (num) {
        JUT_ASSERT(39, num <= 128);
        mPercNumMax = num;
        mPercArray = new (heap, 0) TPerc*[mPercNumMax];
        JASCalc::bzero(mPercArray, mPercNumMax * sizeof(TPerc*));
    }
}

bool JASDrumSet::getParam(int key, int param_1, JASInstParam* param_2) const {
    UNUSED(param_1);
    JUT_ASSERT(48, key >= 0);
    if (mPercArray == NULL) {
        return false;
    }

    if (key >= mPercNumMax) {
        JUT_WARN(54, "JASDrumSet: key %d >= PERC_MAX %d\n", key, mPercNumMax);
        return false;
    }

    TPerc* perc = mPercArray[key];
    if (perc == NULL) {
        return false;
    }

    param_2->field_0x1c = 0;
    param_2->field_0x1e = 1;
    param_2->mVolume = perc->mVolume;
    param_2->mPitch = perc->mPitch;
    param_2->mPan = perc->mPan;
    param_2->field_0x18 = u16(perc->field_0xc);

    static JASOscillator::Data osc;

    osc.mTarget = 0;
    osc.mRate = 1.0f;
    osc.mTable = NULL;
    osc.rel_table = NULL;
    osc.mScale = 1.0f;
    osc.mVertex = 0.0f;

    static JASOscillator::Data* oscp = &osc;

    param_2->field_0x14 = &oscp;
    param_2->field_0x1d = 1;
    param_2->mVolume *= perc->field_0x10;
    param_2->mPitch *= perc->field_0x14;
    param_2->field_0x1a = u16(perc->field_0xe);
    return true;
}

void JASDrumSet::setPerc(int index, JASDrumSet::TPerc* param_1) {
    JUT_ASSERT(123, index >= 0);
    JUT_ASSERT(125, index < mPercNumMax);
    JUT_ASSERT(126, mPercArray);
    JUT_ASSERT(127, mPercArray[index] == 0);
    mPercArray[index] = param_1;
}

JASDrumSet::TPerc* JASDrumSet::getPerc(int index) {
    if (index < 0) {
        return NULL;
    }
    if (index >= mPercNumMax) {
        return NULL;
    }
    if (!mPercArray) {
        return NULL;
    }
    return mPercArray[index];
}

JASDrumSet::TPerc* JASDrumSet::getPerc(int index) const {
    if (index < 0) {
        return NULL;
    }
    if (index >= mPercNumMax) {
        return NULL;
    }
    if (!mPercArray) {
        return NULL;
    }
    return mPercArray[index];
}

JASDrumSet::TPerc::TPerc() {
    mVolume = 1.0f;
    mPitch = 1.0f;
    mPan = 0.5f;
    field_0xc = 1000;
}

void JASDrumSet::TPerc::setRelease(u32 release) {
    JUT_ASSERT(224, release < 0x10000);
    field_0xc = release;
}

u32 JASDrumSet::getType() const { return 'PERC'; }