summaryrefslogtreecommitdiff
path: root/arm7/lib/src/SND_lfo.c
blob: eca98197b3a5dfd09ca03e4c732de624af1124b4 (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
#include "SND_lfo.h"

#include "SND_util.h"
#include "SND_exChannel.h"

void SND_InitLfoParam(struct SNDLfoParam *lfoParam) {
    lfoParam->target = SND_LFO_PITCH;
    lfoParam->depth = 0;
    lfoParam->range = 1;
    lfoParam->speed = 16;
    lfoParam->delay = 0;
}

void SND_StartLfo(struct SNDLfo *lfo) {
    lfo->counter = 0;
    lfo->delayCounter = 0;
}

void SND_UpdateLfo(struct SNDLfo *lfo) {
    if (lfo->delayCounter < lfo->param.delay) {
        lfo->delayCounter++;
    } else {
        u32 tmp = lfo->counter;
        tmp += lfo->param.speed << 6;
        tmp >>= 8;
        while (tmp >= 0x80) {
            tmp -= 0x80;
        }
        lfo->counter += lfo->param.speed << 6;
        lfo->counter &= 0xFF;
        lfo->counter |= tmp << 8;
    }
}

s32 SND_GetLfoValue(struct SNDLfo *lfo) {
    if (lfo->param.depth == 0) {
        return 0;
    } else if (lfo->delayCounter < lfo->param.delay) {
        return 0;
    } else {
        return SND_SinIdx((s32)((u32)lfo->counter >> 8)) * lfo->param.depth * lfo->param.range;
    }
}