diff --git a/include/functions.h b/include/functions.h index d915a3e7d..23c537f0b 100644 --- a/include/functions.h +++ b/include/functions.h @@ -245,7 +245,7 @@ void osStopThread(OSThread* t); s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags); OSIntMask osSetIntMask(OSIntMask im); // OSIntMask osGetIntMask(void); -// void osVoiceSetWord(void); +s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word); // void guScale(void); f32 __sinf(f32 __x); s16 sins(u16 x); @@ -287,7 +287,7 @@ void osCreateThread(OSThread* t, OSId id, void* entry, void* arg, void* sp, OSPr s32 osContStartReadData(OSMesgQueue* mq); void osContGetReadData(OSContPad* data); void __osPackReadData(void); -// void osVoiceGetReadData(void); +s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result); uintptr_t osVirtualToPhysical(void* vaddr); u32 __osGetSR(void); void __osSetSR(u32 value); @@ -452,7 +452,7 @@ void viMgrMain(OSDevMgr* iParm1); __OSViContext* __osViGetCurrentContext(void); void osWritebackDCacheAll(void); OSThread* __osGetCurrFaultedThread(void); -// void osVoiceMaskDictionary(void); +s32 osVoiceMaskDictionary(OSVoiceHandle* hd, u8* maskPattern, s32 size); void guMtxF2L(float mf[4][4], Mtx* m); void osStartThread(OSThread* param_1); void osViSetYScale(f32 value); @@ -465,7 +465,7 @@ double __ll_to_d(long long l); float __ll_to_f(long long l); double __ull_to_d(unsigned long long l); float __ull_to_f(unsigned long long l); -// void osVoiceCheckWord(void); +s32 osVoiceCheckWord(u8* word); s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital); s32 osVoiceStartReadData(OSVoiceHandle* hd); void* osViGetCurrentFramebuffer(void); diff --git a/include/os.h b/include/os.h index 47a419d6b..1a4712bff 100644 --- a/include/os.h +++ b/include/os.h @@ -122,6 +122,23 @@ typedef struct { /* 0xC */ u32* text_end; } OSProf; // size = 0x10 +#define VOICE_STATUS_READY 0 /* stop/end */ +#define VOICE_STATUS_START 1 /* Voice Undetected (no voice input) */ +#define VOICE_STATUS_CANCEL 3 /* Cancel (cancel extraneous noise) */ +#define VOICE_STATUS_BUSY 5 /* Detected/Detecting (voice being input, recognition processing under way) */ +#define VOICE_STATUS_END 7 /* End recognition processing (enable execution of Get Recognition Results command) */ + +#define VOICE_WARN_TOO_SMALL 0x400 /* Voice level is too low (100 < Voice Level < 150) */ +#define VOICE_WARN_TOO_LARGE 0x800 /* Voice level is too high (Voice Level > 3500) */ +#define VOICE_WARN_NOT_FIT 0x4000 /* No words match recognition word (No. 1 Candidate Distance Value > 1600) */ +#define VOICE_WARN_TOO_NOISY 0x8000 /* Too much ambient noise (Relative Voice Level =< 400) */ + +// #define CONT_ERR_NO_CONTROLLER +// #define CONT_ERR_DEVICE +// #define CONT_ERR_CONTRFAIL +// #define CONT_ERR_VOICE_NO_RESPONSE +// #define CONT_ERR_INVALID + typedef struct { /* 0x0 */ OSMesgQueue* mq; /* 0x4 */ s32 port; /* Controller port */ diff --git a/src/libultra/voice/voicecheckresult.c b/src/libultra/voice/voicecheckresult.c index a20c88461..97af48094 100644 --- a/src/libultra/voice/voicecheckresult.c +++ b/src/libultra/voice/voicecheckresult.c @@ -1,21 +1,21 @@ #include "global.h" s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* status) { - s32 phi_v1; + s32 errorCode; u8 sp20[2]; - if (phi_v1 = __osVoiceGetStatus(hd->mq, hd->port, status), phi_v1 == 0) { + if (errorCode = __osVoiceGetStatus(hd->mq, hd->port, status), errorCode == 0) { if (*status & 1) { - phi_v1 = 0xF; - } else if (phi_v1 = __osVoiceContRead2(hd->mq, hd->port, 0, sp20), phi_v1 == 0) { + errorCode = 0xF; + } else if (errorCode = __osVoiceContRead2(hd->mq, hd->port, 0, sp20), errorCode == 0) { hd->status = sp20[0] & 7; if (sp20[0] & 0x40) { - phi_v1 = 0xF; + errorCode = 0xF; } else { - phi_v1 = sp20[1] << 8; + errorCode = sp20[1] << 8; } } } - return phi_v1; + return errorCode; } diff --git a/src/libultra/voice/voicecleardictionary.c b/src/libultra/voice/voicecleardictionary.c index 4de1eef59..92114809d 100644 --- a/src/libultra/voice/voicecleardictionary.c +++ b/src/libultra/voice/voicecleardictionary.c @@ -5,11 +5,11 @@ s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { u8* registration_word; u8 status; s32 sp24; - s32 temp_v0; + s32 errorCode; - temp_v0 = __osVoiceGetStatus(hd->mq, hd->port, &status); - if (temp_v0 != 0) { - return temp_v0; + errorCode = __osVoiceGetStatus(hd->mq, hd->port, &status); + if (errorCode != 0) { + return errorCode; } registration_word = &sp24; @@ -20,14 +20,15 @@ s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { sp24 = 0x2000000; registration_word[2] = words; - temp_v0 = __osVoiceContWrite4(hd->mq, hd->port, 0, registration_word); - if (temp_v0 != 0) { - return temp_v0; + errorCode = __osVoiceContWrite4(hd->mq, hd->port, 0, registration_word); + if (errorCode != 0) { + return errorCode; } - temp_v0 = __osVoiceCheckResult(hd, &status); - if ((temp_v0 & 0xFF00) != 0) { - temp_v0 = 5; + errorCode = __osVoiceCheckResult(hd, &status); + if ((errorCode & 0xFF00) != 0) { + errorCode = 5; } - return temp_v0; + + return errorCode; } diff --git a/src/libultra/voice/voicecontrolgain.c b/src/libultra/voice/voicecontrolgain.c index cfca63fbb..b0a66284a 100644 --- a/src/libultra/voice/voicecontrolgain.c +++ b/src/libultra/voice/voicecontrolgain.c @@ -4,7 +4,7 @@ extern u8 D_80098180[]; // Adjusts the input gain of the Voice Recognition System s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { - s32 ret; + s32 errorCode; u8 phi_a2; @@ -14,9 +14,9 @@ s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { phi_a2 = 0x98; } - ret = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); - if (ret != 0) { - return ret; + errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); + if (errorCode != 0) { + return errorCode; } if (!((digital < 8) && (digital >= 0))){ @@ -30,10 +30,10 @@ s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { return 5; } - ret = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); - if (ret != 0) { - return ret; + errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); + if (errorCode != 0) { + return errorCode; } - return ret; + return errorCode; } diff --git a/src/libultra/voice/voicestartreaddata.c b/src/libultra/voice/voicestartreaddata.c index e0e696749..88c77dc2c 100644 --- a/src/libultra/voice/voicestartreaddata.c +++ b/src/libultra/voice/voicestartreaddata.c @@ -2,16 +2,16 @@ // Start voice recognition by the Voice Recognition System s32 osVoiceStartReadData(OSVoiceHandle* hd) { - s32 ret; - u8 sp2B; + s32 errorCode; + u8 status; s32 sp24; - ret = __osVoiceGetStatus(hd->mq, hd->port, &sp2B); - if (ret != 0) { - return ret; + errorCode = __osVoiceGetStatus(hd->mq, hd->port, &status); + if (errorCode != 0) { + return errorCode; } - if ((sp2B & 2) != 0) { + if (status & 2) { return 0xF; } @@ -20,17 +20,17 @@ s32 osVoiceStartReadData(OSVoiceHandle* hd) { } sp24 = 0x5000000; - ret = __osVoiceContWrite4(hd->mq, hd->port, 0, &sp24); + errorCode = __osVoiceContWrite4(hd->mq, hd->port, 0, &sp24); - if (ret == 0) { - ret = __osVoiceCheckResult(hd, &sp2B); + if (errorCode == 0) { + errorCode = __osVoiceCheckResult(hd, &status); - if ((ret & 0xFF00) != 0) { - ret = 5; + if (errorCode & 0xFF00) { + errorCode = 5; } else { hd->mode = 1; } } - return ret; + return errorCode; }