mirror of
https://github.com/overte-org/overte.git
synced 2025-04-17 08:56:36 +02:00
Expose clipping status to audio scripting interface
This commit is contained in:
parent
918e2fc7ab
commit
ba00f95f72
4 changed files with 35 additions and 7 deletions
|
@ -150,18 +150,33 @@ float Audio::getInputLevel() const {
|
|||
});
|
||||
}
|
||||
|
||||
void Audio::onInputLoudnessChanged(float loudness) {
|
||||
bool Audio::isClipping() const {
|
||||
return resultWithReadLock<bool>([&] {
|
||||
return _isClipping;
|
||||
});
|
||||
}
|
||||
|
||||
void Audio::onInputLoudnessChanged(float loudness, bool isClipping) {
|
||||
float level = loudnessToLevel(loudness);
|
||||
bool changed = false;
|
||||
bool levelChanged = false;
|
||||
bool isClippingChanged = false;
|
||||
|
||||
withWriteLock([&] {
|
||||
if (_inputLevel != level) {
|
||||
_inputLevel = level;
|
||||
changed = true;
|
||||
levelChanged = true;
|
||||
}
|
||||
if (_isClipping != isClipping) {
|
||||
_isClipping = isClipping;
|
||||
isClippingChanged = true;
|
||||
}
|
||||
});
|
||||
if (changed) {
|
||||
if (levelChanged) {
|
||||
emit inputLevelChanged(level);
|
||||
}
|
||||
if (isClippingChanged) {
|
||||
emit clippingChanged(isClipping);
|
||||
}
|
||||
}
|
||||
|
||||
QString Audio::getContext() const {
|
||||
|
|
|
@ -41,6 +41,7 @@ class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
|
|||
* above the noise floor.
|
||||
* @property {number} inputLevel - The loudness of the audio input, range <code>0.0</code> (no sound) –
|
||||
* <code>1.0</code> (the onset of clipping). <em>Read-only.</em>
|
||||
* @property {boolean} clipping - <code>true</code> if the audio input is clipping, otherwise <code>false</code>.
|
||||
* @property {number} inputVolume - Adjusts the volume of the input audio; range <code>0.0</code> – <code>1.0</code>.
|
||||
* If set to a value, the resulting value depends on the input device: for example, the volume can't be changed on some
|
||||
* devices, and others might only support values of <code>0.0</code> and <code>1.0</code>.
|
||||
|
@ -58,6 +59,7 @@ class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
|
|||
Q_PROPERTY(bool noiseReduction READ noiseReductionEnabled WRITE enableNoiseReduction NOTIFY noiseReductionChanged)
|
||||
Q_PROPERTY(float inputVolume READ getInputVolume WRITE setInputVolume NOTIFY inputVolumeChanged)
|
||||
Q_PROPERTY(float inputLevel READ getInputLevel NOTIFY inputLevelChanged)
|
||||
Q_PROPERTY(bool clipping READ isClipping NOTIFY clippingChanged)
|
||||
Q_PROPERTY(QString context READ getContext NOTIFY contextChanged)
|
||||
Q_PROPERTY(AudioDevices* devices READ getDevices NOTIFY nop)
|
||||
|
||||
|
@ -74,6 +76,7 @@ public:
|
|||
bool noiseReductionEnabled() const;
|
||||
float getInputVolume() const;
|
||||
float getInputLevel() const;
|
||||
bool isClipping() const;
|
||||
QString getContext() const;
|
||||
|
||||
void showMicMeter(bool show);
|
||||
|
@ -217,6 +220,14 @@ signals:
|
|||
*/
|
||||
void inputLevelChanged(float level);
|
||||
|
||||
/**jsdoc
|
||||
* Triggered when the clipping state of the input audio changes.
|
||||
* @function Audio.clippingChanged
|
||||
* @param {boolean} isClipping - <code>true</code> if the audio input is clipping, otherwise <code>false</code>.
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void clippingChanged(bool isClipping);
|
||||
|
||||
/**jsdoc
|
||||
* Triggered when the current context of the audio changes.
|
||||
* @function Audio.contextChanged
|
||||
|
@ -237,7 +248,7 @@ private slots:
|
|||
void setMuted(bool muted);
|
||||
void enableNoiseReduction(bool enable);
|
||||
void setInputVolume(float volume);
|
||||
void onInputLoudnessChanged(float loudness);
|
||||
void onInputLoudnessChanged(float loudness, bool isClipping);
|
||||
|
||||
protected:
|
||||
// Audio must live on a separate thread from AudioClient to avoid deadlocks
|
||||
|
@ -247,6 +258,7 @@ private:
|
|||
|
||||
float _inputVolume { 1.0f };
|
||||
float _inputLevel { 0.0f };
|
||||
bool _isClipping { false };
|
||||
bool _isMuted { false };
|
||||
bool _enableNoiseReduction { true }; // Match default value of AudioClient::_isNoiseGateEnabled.
|
||||
bool _contextIsHMD { false };
|
||||
|
|
|
@ -1229,8 +1229,9 @@ void AudioClient::handleMicAudioInput() {
|
|||
} else if (_timeSinceLastClip >= 0.0f) {
|
||||
_timeSinceLastClip += AudioConstants::NETWORK_FRAME_SECS;
|
||||
}
|
||||
isClipping = (_timeSinceLastClip >= 0.0f) && (_timeSinceLastClip < 2.0f); // 2 second hold time
|
||||
|
||||
emit inputLoudnessChanged(_lastInputLoudness);
|
||||
emit inputLoudnessChanged(_lastInputLoudness, isClipping);
|
||||
|
||||
if (!_muted) {
|
||||
possibleResampling(_inputToNetworkResampler,
|
||||
|
|
|
@ -248,7 +248,7 @@ signals:
|
|||
void noiseReductionChanged(bool noiseReductionEnabled);
|
||||
void mutedByMixer();
|
||||
void inputReceived(const QByteArray& inputSamples);
|
||||
void inputLoudnessChanged(float loudness);
|
||||
void inputLoudnessChanged(float loudness, bool isClipping);
|
||||
void outputBytesToNetwork(int numBytes);
|
||||
void inputBytesFromNetwork(int numBytes);
|
||||
void noiseGateOpened();
|
||||
|
|
Loading…
Reference in a new issue