mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-05 11:09:52 +02:00
Replace inline audio mixing with functions that do gain interpolation
This commit is contained in:
parent
181a4e9bdc
commit
85368e6836
2 changed files with 12 additions and 29 deletions
|
@ -549,38 +549,28 @@ void AudioMixerSlave::addStream(AudioMixerClientData::MixableStream& mixableStre
|
||||||
// grab the stream from the ring buffer
|
// grab the stream from the ring buffer
|
||||||
AudioRingBuffer::ConstIterator streamPopOutput = streamToAdd->getLastPopOutput();
|
AudioRingBuffer::ConstIterator streamPopOutput = streamToAdd->getLastPopOutput();
|
||||||
|
|
||||||
// stereo sources are not passed through HRTF
|
|
||||||
if (streamToAdd->isStereo()) {
|
if (streamToAdd->isStereo()) {
|
||||||
|
|
||||||
// apply the avatar gain adjustment
|
streamPopOutput.readSamples(_bufferSamples, AudioConstants::NETWORK_FRAME_SAMPLES_STEREO);
|
||||||
gain *= mixableStream.hrtf->getGainAdjustment();
|
|
||||||
|
|
||||||
const float scale = 1 / 32768.0f; // int16_t to float
|
// stereo sources are not passed through HRTF
|
||||||
|
mixableStream.hrtf->mixStereo(_bufferSamples, _mixSamples, gain, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL; i++) {
|
|
||||||
_mixSamples[2*i+0] += (float)streamPopOutput[2*i+0] * gain * scale;
|
|
||||||
_mixSamples[2*i+1] += (float)streamPopOutput[2*i+1] * gain * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
++stats.manualStereoMixes;
|
++stats.manualStereoMixes;
|
||||||
} else if (isEcho) {
|
} else if (isEcho) {
|
||||||
|
|
||||||
|
streamPopOutput.readSamples(_bufferSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
// echo sources are not passed through HRTF
|
// echo sources are not passed through HRTF
|
||||||
|
mixableStream.hrtf->mixMono(_bufferSamples, _mixSamples, gain, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
const float scale = 1/32768.0f; // int16_t to float
|
|
||||||
|
|
||||||
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL; i++) {
|
|
||||||
float sample = (float)streamPopOutput[i] * gain * scale;
|
|
||||||
_mixSamples[2*i+0] += sample;
|
|
||||||
_mixSamples[2*i+1] += sample;
|
|
||||||
}
|
|
||||||
|
|
||||||
++stats.manualEchoMixes;
|
++stats.manualEchoMixes;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
streamPopOutput.readSamples(_bufferSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
streamPopOutput.readSamples(_bufferSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
mixableStream.hrtf->render(_bufferSamples, _mixSamples, HRTF_DATASET_INDEX, azimuth, distance, gain,
|
mixableStream.hrtf->render(_bufferSamples, _mixSamples, HRTF_DATASET_INDEX, azimuth, distance, gain,
|
||||||
AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
++stats.hrtfRenders;
|
++stats.hrtfRenders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1397,7 +1397,6 @@ bool AudioClient::mixLocalAudioInjectors(float* mixBuffer) {
|
||||||
// spatialize into mixBuffer
|
// spatialize into mixBuffer
|
||||||
injector->getLocalFOA().render(_localScratchBuffer, mixBuffer, HRTF_DATASET_INDEX,
|
injector->getLocalFOA().render(_localScratchBuffer, mixBuffer, HRTF_DATASET_INDEX,
|
||||||
qw, qx, qy, qz, gain, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
qw, qx, qy, qz, gain, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
} else if (options.stereo) {
|
} else if (options.stereo) {
|
||||||
|
|
||||||
if (options.positionSet) {
|
if (options.positionSet) {
|
||||||
|
@ -1409,11 +1408,8 @@ bool AudioClient::mixLocalAudioInjectors(float* mixBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// direct mix into mixBuffer
|
// direct mix into mixBuffer
|
||||||
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL; i++) {
|
injector->getLocalHRTF().mixStereo(_localScratchBuffer, mixBuffer, gain,
|
||||||
mixBuffer[2*i+0] += convertToFloat(_localScratchBuffer[2*i+0]) * gain;
|
AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
mixBuffer[2*i+1] += convertToFloat(_localScratchBuffer[2*i+1]) * gain;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else { // injector is mono
|
} else { // injector is mono
|
||||||
|
|
||||||
if (options.positionSet) {
|
if (options.positionSet) {
|
||||||
|
@ -1431,11 +1427,8 @@ bool AudioClient::mixLocalAudioInjectors(float* mixBuffer) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// direct mix into mixBuffer
|
// direct mix into mixBuffer
|
||||||
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL; i++) {
|
injector->getLocalHRTF().mixMono(_localScratchBuffer, mixBuffer, gain,
|
||||||
float sample = convertToFloat(_localScratchBuffer[i]) * gain;
|
AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
|
||||||
mixBuffer[2*i+0] += sample;
|
|
||||||
mixBuffer[2*i+1] += sample;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue