mirror of
https://github.com/overte-org/overte.git
synced 2025-08-19 09:28:26 +02:00
cleanup separated AudioNoiseGate
This commit is contained in:
parent
f982f5a538
commit
d83718fe8d
3 changed files with 20 additions and 13 deletions
|
@ -64,8 +64,9 @@ Audio::Audio() :
|
|||
_inputRingBuffer(0),
|
||||
_receivedAudioStream(0, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES, InboundAudioStream::Settings()),
|
||||
_isStereoInput(false),
|
||||
_averagedLatency(0.0),
|
||||
_lastInputLoudness(0),
|
||||
_averagedLatency(0.0f),
|
||||
_lastInputLoudness(0.0f),
|
||||
_timeSinceLastClip(-1.0f),
|
||||
_muted(false),
|
||||
_shouldEchoLocally(false),
|
||||
_shouldEchoToServer(false),
|
||||
|
|
|
@ -9,23 +9,27 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <AudioConstants.h>
|
||||
|
||||
#include "AudioNoiseGate.h"
|
||||
|
||||
const int NUMBER_OF_NOISE_SAMPLE_FRAMES = 300;
|
||||
const float AudioNoiseGate::CLIPPING_THRESHOLD = 0.90f;
|
||||
|
||||
AudioNoiseGate::AudioNoiseGate() {
|
||||
// Create the noise sample array
|
||||
_sampleFrames = new float[NUMBER_OF_NOISE_SAMPLE_FRAMES];
|
||||
}
|
||||
|
||||
AudioNoiseGate::~AudioNoiseGate() {
|
||||
delete[] _sampleFrames;
|
||||
AudioNoiseGate::AudioNoiseGate() :
|
||||
_inputFrameCounter(0),
|
||||
_lastLoudness(0.0f),
|
||||
_quietestFrame(std::numeric_limits<float>::max()),
|
||||
_loudestFrame(0.0f),
|
||||
_timeSinceLastClip(-1.0f),
|
||||
_dcOffset(0.0f),
|
||||
_measuredFloor(0.0f),
|
||||
_sampleCounter(0),
|
||||
_isOpen(false),
|
||||
_framesToClose(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
||||
|
@ -112,7 +116,7 @@ void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
|||
float averageOfAllSampleFrames = 0.0f;
|
||||
_sampleFrames[_sampleCounter++] = _lastLoudness;
|
||||
if (_sampleCounter == NUMBER_OF_NOISE_SAMPLE_FRAMES) {
|
||||
float smallestSample = FLT_MAX;
|
||||
float smallestSample = std::numeric_limits<float>::max();
|
||||
for (int i = 0; i <= NUMBER_OF_NOISE_SAMPLE_FRAMES - NOISE_GATE_FRAMES_TO_AVERAGE; i += NOISE_GATE_FRAMES_TO_AVERAGE) {
|
||||
float thisAverage = 0.0f;
|
||||
for (int j = i; j < i + NOISE_GATE_FRAMES_TO_AVERAGE; j++) {
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
const int NUMBER_OF_NOISE_SAMPLE_FRAMES = 300;
|
||||
|
||||
class AudioNoiseGate {
|
||||
public:
|
||||
AudioNoiseGate();
|
||||
|
@ -35,7 +37,7 @@ private:
|
|||
float _timeSinceLastClip;
|
||||
float _dcOffset;
|
||||
float _measuredFloor;
|
||||
float* _sampleFrames;
|
||||
float _sampleFrames[NUMBER_OF_NOISE_SAMPLE_FRAMES];
|
||||
int _sampleCounter;
|
||||
bool _isOpen;
|
||||
int _framesToClose;
|
||||
|
|
Loading…
Reference in a new issue