summaryrefslogtreecommitdiff
path: root/arm7/lib
diff options
context:
space:
mode:
Diffstat (limited to 'arm7/lib')
-rw-r--r--arm7/lib/include/SND_lfo.h13
-rw-r--r--arm7/lib/include/SND_util.h3
-rw-r--r--arm7/lib/src/SND_lfo.c43
3 files changed, 58 insertions, 1 deletions
diff --git a/arm7/lib/include/SND_lfo.h b/arm7/lib/include/SND_lfo.h
new file mode 100644
index 00000000..065e0ed6
--- /dev/null
+++ b/arm7/lib/include/SND_lfo.h
@@ -0,0 +1,13 @@
+#ifndef GUARD_SND_LFO_H
+#define GUARD_SND_LFO_H
+
+#include "nitro/types.h"
+
+#include "nitro/SND_main_shared.h"
+
+void SND_InitLfoParam(struct SNDLfoParam *lfoParam);
+void SND_StartLfo(struct SNDLfo *lfo);
+void SND_UpdateLfo(struct SNDLfo *lfo);
+s32 SND_LfoGetValue(struct SNDLfo *lfo);
+
+#endif //GUARD_SND_LFO_H
diff --git a/arm7/lib/include/SND_util.h b/arm7/lib/include/SND_util.h
index 1bfdb7a8..d9bc56c0 100644
--- a/arm7/lib/include/SND_util.h
+++ b/arm7/lib/include/SND_util.h
@@ -5,7 +5,8 @@
#define SND_DECIBEL_SQUARE_TABLE_COUNT
-u32 SND_CalcRandom(void);
+u16 SND_CalcRandom(void);
+s8 SND_SinIdx(s32 index);
u16 SND_CalcChannelVolume(s32 value);
u16 SND_CalcTimer(s32 timer, s32 pitch);
diff --git a/arm7/lib/src/SND_lfo.c b/arm7/lib/src/SND_lfo.c
new file mode 100644
index 00000000..eca98197
--- /dev/null
+++ b/arm7/lib/src/SND_lfo.c
@@ -0,0 +1,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;
+ }
+}