Skip to content

Commit

Permalink
Merge remote-tracking branch 'nikez/master' into master-pub
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed May 2, 2021
2 parents d588610 + 60acf03 commit c746257
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
61 changes: 61 additions & 0 deletions code/components/voip-mumble/src/MumbleAudioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <MumbleClientImpl.h>
#include <ksmedia.h>

#include <ICoreGameInit.h>
#include <ScriptEngine.h>

#pragma comment(lib, "avrt.lib")

extern "C"
Expand All @@ -27,6 +30,14 @@ MumbleAudioInput::MumbleAudioInput()

}

enum class InputIntentMode {
SPEECH,
MUSIC
};

static InputIntentMode g_curInputIntentMode = InputIntentMode::SPEECH;
static InputIntentMode g_lastIntentMode = InputIntentMode::SPEECH;

void MumbleAudioInput::Initialize()
{
m_bitrateVar = std::make_shared<ConVar<int>>("voice_inBitrate", ConVar_None, m_curBitrate, &m_curBitrate);
Expand Down Expand Up @@ -118,6 +129,28 @@ void MumbleAudioInput::ThreadFunc()
lastLikelihood = m_likelihood;
}

if (g_curInputIntentMode != g_lastIntentMode)
{
switch (g_curInputIntentMode)
{
case InputIntentMode::MUSIC:
{
m_apm->noise_suppression()->Enable(false);
m_apm->high_pass_filter()->Enable(false);
break;
}
case InputIntentMode::SPEECH:
default:
{
m_apm->noise_suppression()->Enable(true);
m_apm->high_pass_filter()->Enable(true);
break;
}
};
g_lastIntentMode = g_curInputIntentMode;
}


if (lastDevice != m_deviceId)
{
recreateDevice = true;
Expand Down Expand Up @@ -637,3 +670,31 @@ void MumbleAudioInput::ThreadStart(MumbleAudioInput* instance)
mmcssHandle = AvSetMmThreadCharacteristics(L"Pro Audio", &mmcssTaskIndex);
instance->ThreadFunc();
}

static InitFunction initFunction([]()
{
fx::ScriptEngine::RegisterNativeHandler("MUMBLE_SET_AUDIO_INPUT_INTENT", [](fx::ScriptContext& scriptContext)
{
uint32_t intent = scriptContext.GetArgument<uint32_t>(0);

switch (intent)
{
case HashString("music"):
{
g_curInputIntentMode = InputIntentMode::MUSIC;
break;
}
case HashString("speech"):
default:
{
g_curInputIntentMode = InputIntentMode::SPEECH;
break;
}
};
});

Instance<ICoreGameInit>::Get()->OnShutdownSession.Connect([]()
{
g_curInputIntentMode = InputIntentMode::SPEECH;
});
});
30 changes: 30 additions & 0 deletions ext/native-decls/MumbleSetAudioInputIntent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
ns: CFX
apiset: client
game: gta5
---
## MUMBLE_SET_AUDIO_INPUT_INTENT

```c
void MUMBLE_SET_AUDIO_INPUT_INTENT(Hash intentHash);
```
Use this native to disable noise suppression and high pass filters.
The possible intents for this are as follows (backticks are used to represent hashes):
| Index | Description |
|-|-|
| \`speech\` | Default intent |
| \`music\` | Disable noise suppression and high pass filter |
## Parameters
* **intentHash**: The intent hash.
## Examples
```lua
-- disable noise suppression and high pass filter
MumbleSetAudioInputIntent(`music`)
-- set the default intent (enable noise suppression and high pass filter)
MumbleSetAudioInputIntent(`speech`)
```

0 comments on commit c746257

Please sign in to comment.