mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
add Audio.inputLevel
This commit is contained in:
parent
ddce665613
commit
497ee3a522
4 changed files with 45 additions and 2 deletions
|
@ -23,9 +23,33 @@ QString Audio::HMD { "VR" };
|
||||||
|
|
||||||
Setting::Handle<bool> enableNoiseReductionSetting { QStringList { Audio::AUDIO, "NoiseReduction" }, true };
|
Setting::Handle<bool> enableNoiseReductionSetting { QStringList { Audio::AUDIO, "NoiseReduction" }, true };
|
||||||
|
|
||||||
|
float Audio::loudnessToLevel(float loudness) {
|
||||||
|
const float LOG2 = log(2.0f);
|
||||||
|
const float METER_LOUDNESS_SCALE = 2.8f / 5.0f;
|
||||||
|
const float LOG2_LOUDNESS_FLOOR = 11.0f;
|
||||||
|
|
||||||
|
float level = 0.0f;
|
||||||
|
|
||||||
|
loudness += 1.0f;
|
||||||
|
float log2loudness = logf(loudness) / LOG2;
|
||||||
|
|
||||||
|
if (log2loudness <= LOG2_LOUDNESS_FLOOR) {
|
||||||
|
level = (log2loudness / LOG2_LOUDNESS_FLOOR) * METER_LOUDNESS_SCALE;
|
||||||
|
} else {
|
||||||
|
level = (log2loudness - (LOG2_LOUDNESS_FLOOR - 1.0f)) * METER_LOUDNESS_SCALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level > 1.0f) {
|
||||||
|
level = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
Audio::Audio() : _devices(_contextIsHMD) {
|
Audio::Audio() : _devices(_contextIsHMD) {
|
||||||
auto client = DependencyManager::get<AudioClient>();
|
auto client = DependencyManager::get<AudioClient>().data();
|
||||||
connect(client.data(), &AudioClient::muteToggled, this, &Audio::onMutedChanged);
|
connect(client, &AudioClient::muteToggled, this, &Audio::onMutedChanged);
|
||||||
|
connect(client, &AudioClient::inputLoudnessChanged, this, &Audio::onInputLoudnessChanged);
|
||||||
connect(this, &Audio::contextChanged, &_devices, &AudioDevices::onContextChanged);
|
connect(this, &Audio::contextChanged, &_devices, &AudioDevices::onContextChanged);
|
||||||
connect(&_devices._inputs, &AudioDeviceList::deviceChanged, this, &Audio::onInputChanged);
|
connect(&_devices._inputs, &AudioDeviceList::deviceChanged, this, &Audio::onInputChanged);
|
||||||
enableNoiseReduction(enableNoiseReductionSetting.get());
|
enableNoiseReduction(enableNoiseReductionSetting.get());
|
||||||
|
@ -88,6 +112,15 @@ void Audio::onInputChanged() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio::onInputLoudnessChanged(float loudness) {
|
||||||
|
float level = loudnessToLevel(loudness);
|
||||||
|
|
||||||
|
if (_inputLevel != level) {
|
||||||
|
_inputLevel = level;
|
||||||
|
emit inputLevelChanged(_inputLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString Audio::getContext() const {
|
QString Audio::getContext() const {
|
||||||
return _contextIsHMD ? Audio::HMD : Audio::DESKTOP;
|
return _contextIsHMD ? Audio::HMD : Audio::DESKTOP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Audio : public AudioScriptingInterface {
|
||||||
Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
|
Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
|
||||||
Q_PROPERTY(bool noiseReduction READ noiseReductionEnabled WRITE enableNoiseReduction NOTIFY noiseReductionChanged)
|
Q_PROPERTY(bool noiseReduction READ noiseReductionEnabled WRITE enableNoiseReduction NOTIFY noiseReductionChanged)
|
||||||
Q_PROPERTY(float inputVolume READ getInputVolume WRITE setInputVolume NOTIFY inputVolumeChanged)
|
Q_PROPERTY(float inputVolume READ getInputVolume WRITE setInputVolume NOTIFY inputVolumeChanged)
|
||||||
|
Q_PROPERTY(float inputLevel READ getInputLevel NOTIFY inputLevelChanged)
|
||||||
Q_PROPERTY(QString context READ getContext NOTIFY contextChanged)
|
Q_PROPERTY(QString context READ getContext NOTIFY contextChanged)
|
||||||
Q_PROPERTY(AudioDevices* devices READ getDevices NOTIFY nop)
|
Q_PROPERTY(AudioDevices* devices READ getDevices NOTIFY nop)
|
||||||
|
|
||||||
|
@ -34,11 +35,14 @@ public:
|
||||||
static QString HMD;
|
static QString HMD;
|
||||||
static QString DESKTOP;
|
static QString DESKTOP;
|
||||||
|
|
||||||
|
static float loudnessToLevel(float loudness);
|
||||||
|
|
||||||
virtual ~Audio() {}
|
virtual ~Audio() {}
|
||||||
|
|
||||||
bool isMuted() const { return _isMuted; }
|
bool isMuted() const { return _isMuted; }
|
||||||
bool noiseReductionEnabled() const { return _enableNoiseReduction; }
|
bool noiseReductionEnabled() const { return _enableNoiseReduction; }
|
||||||
float getInputVolume() const { return _inputVolume; }
|
float getInputVolume() const { return _inputVolume; }
|
||||||
|
float getInputLevel() const { return _inputLevel; }
|
||||||
QString getContext() const;
|
QString getContext() const;
|
||||||
|
|
||||||
void setMuted(bool muted);
|
void setMuted(bool muted);
|
||||||
|
@ -54,12 +58,14 @@ signals:
|
||||||
void mutedChanged(bool isMuted);
|
void mutedChanged(bool isMuted);
|
||||||
void noiseReductionChanged(bool isEnabled);
|
void noiseReductionChanged(bool isEnabled);
|
||||||
void inputVolumeChanged(float volume);
|
void inputVolumeChanged(float volume);
|
||||||
|
void inputLevelChanged(float level);
|
||||||
void contextChanged(const QString& context);
|
void contextChanged(const QString& context);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onMutedChanged();
|
void onMutedChanged();
|
||||||
void onContextChanged();
|
void onContextChanged();
|
||||||
void onInputChanged();
|
void onInputChanged();
|
||||||
|
void onInputLoudnessChanged(float loudness);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Audio must live on a separate thread from AudioClient to avoid deadlocks
|
// Audio must live on a separate thread from AudioClient to avoid deadlocks
|
||||||
|
@ -68,6 +74,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
float _inputVolume { 1.0f };
|
float _inputVolume { 1.0f };
|
||||||
|
float _inputLevel { 0.0f };
|
||||||
bool _isMuted { false };
|
bool _isMuted { false };
|
||||||
bool _enableNoiseReduction;
|
bool _enableNoiseReduction;
|
||||||
bool _contextIsHMD { false };
|
bool _contextIsHMD { false };
|
||||||
|
|
|
@ -1023,6 +1023,8 @@ void AudioClient::handleAudioInput(QByteArray& audioBuffer) {
|
||||||
emit inputReceived(audioBuffer);
|
emit inputReceived(audioBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit inputLoudnessChanged(_lastInputLoudness);
|
||||||
|
|
||||||
// state machine to detect gate opening and closing
|
// state machine to detect gate opening and closing
|
||||||
bool audioGateOpen = (_lastInputLoudness != 0.0f);
|
bool audioGateOpen = (_lastInputLoudness != 0.0f);
|
||||||
bool openedInLastBlock = !_audioGateOpen && audioGateOpen; // the gate just opened
|
bool openedInLastBlock = !_audioGateOpen && audioGateOpen; // the gate just opened
|
||||||
|
|
|
@ -210,6 +210,7 @@ signals:
|
||||||
bool muteToggled();
|
bool muteToggled();
|
||||||
void mutedByMixer();
|
void mutedByMixer();
|
||||||
void inputReceived(const QByteArray& inputSamples);
|
void inputReceived(const QByteArray& inputSamples);
|
||||||
|
void inputLoudnessChanged(float loudness);
|
||||||
void outputBytesToNetwork(int numBytes);
|
void outputBytesToNetwork(int numBytes);
|
||||||
void inputBytesFromNetwork(int numBytes);
|
void inputBytesFromNetwork(int numBytes);
|
||||||
void noiseGateOpened();
|
void noiseGateOpened();
|
||||||
|
|
Loading…
Reference in a new issue