summaryrefslogtreecommitdiff
path: root/src/libultra/voice/voicecontrolgain.c
blob: 0acdf86dbd6f2b476cb08833b3d405447cf658c7 (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
/**
 * File: voicecontrolgain.c
 *
 * Adjusts the input gain of the Voice Recognition System
 */

#include "PR/controller_voice.h"
#include "PR/os_voice.h"
#include "PR/controller.h"
#include "macros.h"

u8 sDigitalTable[] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0 };

s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) {
    s32 errorCode;
    u8 cmd;

    if (analog == 0) {
        cmd = 0x18;
    } else {
        cmd = 0x98;
    }

    errorCode = __osVoiceSetADConverter(hd->__mq, hd->__channel, cmd);
    if (errorCode != 0) {
        return errorCode;
    }

    if ((digital < ARRAY_COUNT(sDigitalTable)) && (digital >= 0)) {
        cmd = sDigitalTable[digital] + 2;
    } else {
        return CONT_ERR_INVALID;
    }

    errorCode = __osVoiceSetADConverter(hd->__mq, hd->__channel, cmd);
    if (errorCode != 0) {
        return errorCode;
    }

    return errorCode;
}