mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:49:05 +02:00
Merge pull request #7985 from ZappoMan/addAudioLimiter
add audio peak limiter to audio mixer
This commit is contained in:
commit
62d3b171d7
5 changed files with 35 additions and 11 deletions
|
@ -339,21 +339,18 @@ bool AudioMixer::prepareMixForListeningNode(Node* node) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
int nonZeroSamples = 0;
|
// use the per listner AudioLimiter to render the mixed data...
|
||||||
|
listenerNodeData->audioLimiter.render(_mixedSamples, _clampedSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
// enumerate the mixed samples and clamp any samples outside the min/max
|
// check for silent audio after the peak limitor has converted the samples
|
||||||
// also check if we ended up with a silent frame
|
bool hasAudio = false;
|
||||||
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_STEREO; ++i) {
|
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_STEREO; ++i) {
|
||||||
|
if (_clampedSamples[i] != 0) {
|
||||||
_clampedSamples[i] = int16_t(glm::clamp(int(_mixedSamples[i] * AudioConstants::MAX_SAMPLE_VALUE),
|
hasAudio = true;
|
||||||
AudioConstants::MIN_SAMPLE_VALUE,
|
break;
|
||||||
AudioConstants::MAX_SAMPLE_VALUE));
|
|
||||||
if (_clampedSamples[i] != 0.0f) {
|
|
||||||
++nonZeroSamples;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return hasAudio;
|
||||||
return (nonZeroSamples > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioMixer::sendAudioEnvironmentPacket(SharedNodePointer node) {
|
void AudioMixer::sendAudioEnvironmentPacket(SharedNodePointer node) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
AudioMixerClientData::AudioMixerClientData(const QUuid& nodeID) :
|
AudioMixerClientData::AudioMixerClientData(const QUuid& nodeID) :
|
||||||
NodeData(nodeID),
|
NodeData(nodeID),
|
||||||
|
audioLimiter(AudioConstants::SAMPLE_RATE, AudioConstants::STEREO),
|
||||||
_outgoingMixedAudioSequenceNumber(0),
|
_outgoingMixedAudioSequenceNumber(0),
|
||||||
_downstreamAudioStreamStats()
|
_downstreamAudioStreamStats()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,11 +16,13 @@
|
||||||
|
|
||||||
#include <AABox.h>
|
#include <AABox.h>
|
||||||
#include <AudioHRTF.h>
|
#include <AudioHRTF.h>
|
||||||
|
#include <AudioLimiter.h>
|
||||||
#include <UUIDHasher.h>
|
#include <UUIDHasher.h>
|
||||||
|
|
||||||
#include "PositionalAudioStream.h"
|
#include "PositionalAudioStream.h"
|
||||||
#include "AvatarAudioStream.h"
|
#include "AvatarAudioStream.h"
|
||||||
|
|
||||||
|
|
||||||
class AudioMixerClientData : public NodeData {
|
class AudioMixerClientData : public NodeData {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -61,6 +63,8 @@ public:
|
||||||
// uses randomization to have the AudioMixer send a stats packet to this node around every second
|
// uses randomization to have the AudioMixer send a stats packet to this node around every second
|
||||||
bool shouldSendStats(int frameNumber);
|
bool shouldSendStats(int frameNumber);
|
||||||
|
|
||||||
|
AudioLimiter audioLimiter;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void injectorStreamFinished(const QUuid& streamIdentifier);
|
void injectorStreamFinished(const QUuid& streamIdentifier);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
namespace AudioConstants {
|
namespace AudioConstants {
|
||||||
const int SAMPLE_RATE = 24000;
|
const int SAMPLE_RATE = 24000;
|
||||||
|
const int MONO = 1;
|
||||||
|
const int STEREO = 2;
|
||||||
|
|
||||||
|
|
||||||
typedef int16_t AudioSample;
|
typedef int16_t AudioSample;
|
||||||
|
|
||||||
|
|
19
script-archive/tests/audio/testPeakLimiter.js
Normal file
19
script-archive/tests/audio/testPeakLimiter.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
var audioOptions = {
|
||||||
|
volume: 1.0,
|
||||||
|
loop: true,
|
||||||
|
position: MyAvatar.position
|
||||||
|
}
|
||||||
|
|
||||||
|
//var sineWave = Script.resolvePath("./1760sine.wav"); // use relative file
|
||||||
|
var sineWave = "https://s3-us-west-1.amazonaws.com/highfidelity-dev/1760sine.wav"; // use file from S3
|
||||||
|
var sound = SoundCache.getSound(sineWave);
|
||||||
|
var injectorCount = 0;
|
||||||
|
var MAX_INJECTOR_COUNT = 40;
|
||||||
|
|
||||||
|
Script.update.connect(function() {
|
||||||
|
if (sound.downloaded && injectorCount < MAX_INJECTOR_COUNT) {
|
||||||
|
injectorCount++;
|
||||||
|
print("stating injector:" + injectorCount);
|
||||||
|
Audio.playSound(sound, audioOptions);
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue