noise-suppression-for-voice
noise-suppression-for-voice copied to clipboard
Voice crackling on custom implementation of RnNoiseCommonPlugin for UE4
I'm developing a NoiseCancelling module for Unreal Engine 4 and for that I've been using your implementation from the RNoise library.
What is happening to me is that output audio is cancelling correctly claps and other noisy audio but a continuous Voice Crackling is happening when I talk. This Crackling seems to be related to voicebuffer since when I send small chunks of audio voice tends to crack more often.
Below is the integration of the plugin to the UE4 environment:
void FNoiseCancelling::NoiseCancel(TArray<uint8>& InVoiceData, TArray<uint8>& OutVoiceData, float threshold)
{
int16* intPtr = reinterpret_cast<int16*>(InVoiceData.GetData());
std::vector<float> in;
for (int i = 0; i < InVoiceData.Num() / 2; i++)
in.push_back(FromIntToFloat(intPtr[i]));
std::vector<float> out;
out.resize(in.size());
std::memcpy(&out[0], &in[0], in.size() * sizeof(float));
Rnoise.process(&in[0], &out[0], (int32_t)in.size(), threshold);
std::vector<int16> resultBuffer;
for (int i = 0; i < out.size(); i++)
resultBuffer.push_back(FromFloatToInt(out[i]));
uint8* bytePtr = reinterpret_cast<uint8*>(&resultBuffer[0]);
std::memcpy(OutVoiceData.GetData(), bytePtr, resultBuffer.size() * sizeof(int16));
}
This is happening inside an event that is called every time new voice is generated and before sending the raw data to the Audio Output device.
As you can see, I'm not doing anything aside from "forwarding" the raw data to the plugin.
Note1: I've made sure that InVoiceData is divisible of 480 so it matches frameSizes.
Note2: Rnoise.Init() is happening in another event that is called when the parent module is initialized. RNoise.DeInit() is not happening for now.
If you could link documentation for the input params engine passes in this function - it would help.
What does FromIntToFloat
/FromFloatToInt
do? ::process
expects floats to be in [-1;1]
range.
What happens if instead of ::process
you just copy from in
to out
?
What rate are you using? 48000 Hz or 44000 would be fine, but I'm not sure what happens with bigger deviations.
Anyway, if input is in the correct range and its rate doesn't deviate too much - rnnoise wouldn't produce any crackling.