mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-09 12:37:02 +02:00
remove dependency on Stk library and TwoPole effect
This commit is contained in:
parent
00446076b5
commit
73a42fbfde
3 changed files with 7 additions and 70 deletions
|
@ -77,10 +77,6 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
|
||||||
|
|
||||||
const int PHASE_DELAY_AT_90 = 20;
|
const int PHASE_DELAY_AT_90 = 20;
|
||||||
|
|
||||||
static stk::StkFrames stkFrameBuffer(BUFFER_LENGTH_SAMPLES_PER_CHANNEL, 1);
|
|
||||||
|
|
||||||
stk::TwoPole* otherNodeTwoPole = NULL;
|
|
||||||
|
|
||||||
if (bufferToAdd != listeningNodeBuffer) {
|
if (bufferToAdd != listeningNodeBuffer) {
|
||||||
// if the two buffer pointers do not match then these are different buffers
|
// if the two buffer pointers do not match then these are different buffers
|
||||||
|
|
||||||
|
@ -156,26 +152,6 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
|
||||||
float sinRatio = fabsf(sinf(glm::radians(bearingRelativeAngleToSource)));
|
float sinRatio = fabsf(sinf(glm::radians(bearingRelativeAngleToSource)));
|
||||||
numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
|
numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
|
||||||
weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
|
weakChannelAmplitudeRatio = 1 - (PHASE_AMPLITUDE_RATIO_AT_90 * sinRatio);
|
||||||
|
|
||||||
// grab the TwoPole object for this source, add it if it doesn't exist
|
|
||||||
TwoPoleNodeMap& nodeTwoPoles = listeningNodeBuffer->getTwoPoles();
|
|
||||||
TwoPoleNodeMap::iterator twoPoleIterator = nodeTwoPoles.find(bufferToAdd);
|
|
||||||
|
|
||||||
if (twoPoleIterator == nodeTwoPoles.end()) {
|
|
||||||
// setup the freeVerb effect for this source for this client
|
|
||||||
otherNodeTwoPole = nodeTwoPoles[bufferToAdd] = new stk::TwoPole;
|
|
||||||
} else {
|
|
||||||
otherNodeTwoPole = twoPoleIterator->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate the reasonance for this TwoPole based on angle to source
|
|
||||||
float TWO_POLE_CUT_OFF_FREQUENCY = 800.0f;
|
|
||||||
float TWO_POLE_MAX_FILTER_STRENGTH = 0.4f;
|
|
||||||
|
|
||||||
otherNodeTwoPole->setResonance(TWO_POLE_CUT_OFF_FREQUENCY,
|
|
||||||
TWO_POLE_MAX_FILTER_STRENGTH
|
|
||||||
* fabsf(bearingRelativeAngleToSource) / 180.0f,
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,44 +168,22 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
|
||||||
? bufferToAdd->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay
|
? bufferToAdd->getBuffer() + RING_BUFFER_LENGTH_SAMPLES - numSamplesDelay
|
||||||
: bufferToAdd->getNextOutput() - numSamplesDelay;
|
: bufferToAdd->getNextOutput() - numSamplesDelay;
|
||||||
|
|
||||||
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
|
||||||
// load up the stkFrameBuffer with this source's samples
|
|
||||||
stkFrameBuffer[s] = (stk::StkFloat) sourceBuffer[s];
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform the TwoPole effect on the stkFrameBuffer
|
|
||||||
if (otherNodeTwoPole) {
|
|
||||||
otherNodeTwoPole->tick(stkFrameBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) {
|
||||||
if (s < numSamplesDelay) {
|
if (s < numSamplesDelay) {
|
||||||
// pull the earlier sample for the delayed channel
|
// pull the earlier sample for the delayed channel
|
||||||
int earlierSample = delaySamplePointer[s] * attenuationCoefficient * weakChannelAmplitudeRatio;
|
int earlierSample = delaySamplePointer[s] * attenuationCoefficient * weakChannelAmplitudeRatio;
|
||||||
|
|
||||||
delayedChannel[s] = glm::clamp(delayedChannel[s] + earlierSample,
|
delayedChannel[s] = glm::clamp(delayedChannel[s] + earlierSample, MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
||||||
MIN_SAMPLE_VALUE,
|
|
||||||
MAX_SAMPLE_VALUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t currentSample = stkFrameBuffer[s] * attenuationCoefficient;
|
// pull the current sample for the good channel
|
||||||
|
int16_t currentSample = sourceBuffer[s] * attenuationCoefficient;
|
||||||
goodChannel[s] = glm::clamp(goodChannel[s] + currentSample,
|
goodChannel[s] = glm::clamp(goodChannel[s] + currentSample, MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
||||||
MIN_SAMPLE_VALUE,
|
|
||||||
MAX_SAMPLE_VALUE);
|
|
||||||
|
|
||||||
if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
||||||
int sumSample = delayedChannel[s + numSamplesDelay]
|
// place the curernt sample at the right spot in the delayed channel
|
||||||
+ (currentSample * weakChannelAmplitudeRatio);
|
int sumSample = delayedChannel[s + numSamplesDelay] + (currentSample * weakChannelAmplitudeRatio);
|
||||||
delayedChannel[s + numSamplesDelay] = glm::clamp(sumSample,
|
delayedChannel[s + numSamplesDelay] = glm::clamp(sumSample, MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
|
||||||
MIN_SAMPLE_VALUE,
|
|
||||||
MAX_SAMPLE_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s >= BUFFER_LENGTH_SAMPLES_PER_CHANNEL - PHASE_DELAY_AT_90) {
|
|
||||||
// this could be a delayed sample on the next pass
|
|
||||||
// so store the affected back in the ARB
|
|
||||||
bufferToAdd->getNextOutput()[s] = (int16_t) stkFrameBuffer[s];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,18 +12,10 @@
|
||||||
|
|
||||||
AvatarAudioRingBuffer::AvatarAudioRingBuffer() :
|
AvatarAudioRingBuffer::AvatarAudioRingBuffer() :
|
||||||
PositionalAudioRingBuffer(PositionalAudioRingBuffer::Microphone),
|
PositionalAudioRingBuffer(PositionalAudioRingBuffer::Microphone),
|
||||||
_twoPoles(),
|
|
||||||
_shouldLoopbackForNode(false) {
|
_shouldLoopbackForNode(false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AvatarAudioRingBuffer::~AvatarAudioRingBuffer() {
|
|
||||||
// enumerate the freeVerbs map and delete the FreeVerb objects
|
|
||||||
for (TwoPoleNodeMap::iterator poleIterator = _twoPoles.begin(); poleIterator != _twoPoles.end(); poleIterator++) {
|
|
||||||
delete poleIterator->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int AvatarAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
int AvatarAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
_shouldLoopbackForNode = (sourceBuffer[0] == PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO);
|
_shouldLoopbackForNode = (sourceBuffer[0] == PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO);
|
||||||
return PositionalAudioRingBuffer::parseData(sourceBuffer, numBytes);
|
return PositionalAudioRingBuffer::parseData(sourceBuffer, numBytes);
|
||||||
|
|
|
@ -9,31 +9,22 @@
|
||||||
#ifndef __hifi__AvatarAudioRingBuffer__
|
#ifndef __hifi__AvatarAudioRingBuffer__
|
||||||
#define __hifi__AvatarAudioRingBuffer__
|
#define __hifi__AvatarAudioRingBuffer__
|
||||||
|
|
||||||
#include <Stk.h>
|
|
||||||
#include <TwoPole.h>
|
|
||||||
|
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
|
|
||||||
#include "PositionalAudioRingBuffer.h"
|
#include "PositionalAudioRingBuffer.h"
|
||||||
|
|
||||||
typedef std::map<PositionalAudioRingBuffer*, stk::TwoPole*> TwoPoleNodeMap;
|
|
||||||
|
|
||||||
class AvatarAudioRingBuffer : public PositionalAudioRingBuffer {
|
class AvatarAudioRingBuffer : public PositionalAudioRingBuffer {
|
||||||
public:
|
public:
|
||||||
AvatarAudioRingBuffer();
|
AvatarAudioRingBuffer();
|
||||||
~AvatarAudioRingBuffer();
|
|
||||||
|
|
||||||
int parseData(unsigned char* sourceBuffer, int numBytes);
|
int parseData(unsigned char* sourceBuffer, int numBytes);
|
||||||
|
|
||||||
TwoPoleNodeMap& getTwoPoles() { return _twoPoles; }
|
|
||||||
|
|
||||||
bool shouldLoopbackForNode() const { return _shouldLoopbackForNode; }
|
bool shouldLoopbackForNode() const { return _shouldLoopbackForNode; }
|
||||||
private:
|
private:
|
||||||
// disallow copying of AvatarAudioRingBuffer objects
|
// disallow copying of AvatarAudioRingBuffer objects
|
||||||
AvatarAudioRingBuffer(const AvatarAudioRingBuffer&);
|
AvatarAudioRingBuffer(const AvatarAudioRingBuffer&);
|
||||||
AvatarAudioRingBuffer& operator= (const AvatarAudioRingBuffer&);
|
AvatarAudioRingBuffer& operator= (const AvatarAudioRingBuffer&);
|
||||||
|
|
||||||
TwoPoleNodeMap _twoPoles;
|
|
||||||
bool _shouldLoopbackForNode;
|
bool _shouldLoopbackForNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue