mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:58:27 +02:00
fix input loudness for a stereo source
This commit is contained in:
parent
ae2f6a3cb6
commit
f6011b65d7
3 changed files with 16 additions and 8 deletions
|
@ -308,8 +308,6 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// stereo buffer - do attenuation but no sample delay for spatialization
|
// stereo buffer - do attenuation but no sample delay for spatialization
|
||||||
qDebug() << "Adding a stereo buffer";
|
|
||||||
|
|
||||||
for (int s = 0; s < NETWORK_BUFFER_LENGTH_SAMPLES_STEREO; s += 4) {
|
for (int s = 0; s < NETWORK_BUFFER_LENGTH_SAMPLES_STEREO; s += 4) {
|
||||||
// use MMX to clamp four additions at a time
|
// use MMX to clamp four additions at a time
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,8 @@ void AudioMixerClientData::pushBuffersAfterFrameSend() {
|
||||||
PositionalAudioRingBuffer* audioBuffer = _ringBuffers[i];
|
PositionalAudioRingBuffer* audioBuffer = _ringBuffers[i];
|
||||||
|
|
||||||
if (audioBuffer->willBeAddedToMix()) {
|
if (audioBuffer->willBeAddedToMix()) {
|
||||||
audioBuffer->shiftReadPosition(NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
audioBuffer->shiftReadPosition(audioBuffer->isStereo()
|
||||||
|
? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO : NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
audioBuffer->setWillBeAddedToMix(false);
|
audioBuffer->setWillBeAddedToMix(false);
|
||||||
} else if (audioBuffer->getType() == PositionalAudioRingBuffer::Injector
|
} else if (audioBuffer->getType() == PositionalAudioRingBuffer::Injector
|
||||||
|
|
|
@ -306,7 +306,7 @@ void linearResampling(int16_t* sourceSamples, int16_t* destinationSamples,
|
||||||
} else {
|
} else {
|
||||||
// this is a 48 to 24 resampling but both source and destination are two channels
|
// this is a 48 to 24 resampling but both source and destination are two channels
|
||||||
// squish two samples into one in each channel
|
// squish two samples into one in each channel
|
||||||
for (int i = 0; i < numSourceSamples; i += 2) {
|
for (int i = 0; i < numSourceSamples; i += 4) {
|
||||||
destinationSamples[i / 2] = (sourceSamples[i] / 2) + (sourceSamples[i + 2] / 2);
|
destinationSamples[i / 2] = (sourceSamples[i] / 2) + (sourceSamples[i + 2] / 2);
|
||||||
destinationSamples[(i / 2) + 1] = (sourceSamples[i + 1] / 2) + (sourceSamples[i + 3] / 2);
|
destinationSamples[(i / 2) + 1] = (sourceSamples[i + 1] / 2) + (sourceSamples[i + 3] / 2);
|
||||||
}
|
}
|
||||||
|
@ -585,6 +585,14 @@ void Audio::handleAudioInput() {
|
||||||
_lastInputLoudness = 0;
|
_lastInputLoudness = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
float loudness = 0.0f;
|
||||||
|
|
||||||
|
for (int i = 0; i < NETWORK_BUFFER_LENGTH_SAMPLES_STEREO; i++) {
|
||||||
|
loudness += fabsf(networkAudioSamples[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastInputLoudness = fabs(loudness / NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// our input loudness is 0, since we're muted
|
// our input loudness is 0, since we're muted
|
||||||
|
@ -626,11 +634,12 @@ void Audio::handleAudioInput() {
|
||||||
packetType = PacketTypeSilentAudioFrame;
|
packetType = PacketTypeSilentAudioFrame;
|
||||||
|
|
||||||
// we need to indicate how many silent samples this is to the audio mixer
|
// we need to indicate how many silent samples this is to the audio mixer
|
||||||
audioDataPacket[0] = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
|
audioDataPacket[0] = _isStereoInput
|
||||||
|
? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO
|
||||||
|
: NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
|
||||||
numAudioBytes = sizeof(int16_t);
|
numAudioBytes = sizeof(int16_t);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
numAudioBytes = NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL;
|
numAudioBytes = _isStereoInput ? NETWORK_BUFFER_LENGTH_BYTES_STEREO : NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL;
|
||||||
|
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::EchoServerAudio)) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::EchoServerAudio)) {
|
||||||
packetType = PacketTypeMicrophoneAudioWithEcho;
|
packetType = PacketTypeMicrophoneAudioWithEcho;
|
||||||
|
|
Loading…
Reference in a new issue