mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 02:19:58 +02:00
working on selected audio
This commit is contained in:
parent
c301b799c5
commit
c969570e8c
8 changed files with 233 additions and 145 deletions
|
@ -32,6 +32,32 @@ PositionalAudioRingBuffer::~PositionalAudioRingBuffer() {
|
|||
}
|
||||
}
|
||||
|
||||
bool PositionalAudioRingBuffer::isListeningToSource(PositionalAudioRingBuffer* other) {
|
||||
switch (_listenMode) {
|
||||
default:
|
||||
case AudioRingBuffer::NORMAL:
|
||||
return true;
|
||||
break;
|
||||
|
||||
case AudioRingBuffer::OMNI_DIRECTIONAL_POINT: {
|
||||
float distance = glm::distance(_position, other->_position);
|
||||
return distance <= _listenRadius;
|
||||
break;
|
||||
}
|
||||
case AudioRingBuffer::SELECTED_SOURCES:
|
||||
if (_listenSources) {
|
||||
for (int i = 0; i < _listenSourceCount; i++) {
|
||||
if (other->_sourceID == _listenSources[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int PositionalAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||
unsigned char* currentBuffer = sourceBuffer + numBytesForPacketHeader(sourceBuffer);
|
||||
currentBuffer += parseSourceData(currentBuffer, numBytes - (currentBuffer - sourceBuffer));
|
||||
|
@ -63,14 +89,12 @@ int PositionalAudioRingBuffer::parseListenModeData(unsigned char* sourceBuffer,
|
|||
} else if (_listenMode == AudioRingBuffer::SELECTED_SOURCES) {
|
||||
memcpy(&_listenSourceCount, currentBuffer, sizeof(_listenSourceCount));
|
||||
currentBuffer += sizeof(_listenSourceCount);
|
||||
|
||||
if (_listenSources) {
|
||||
delete[] _listenSources;
|
||||
}
|
||||
_listenSources = new int[_listenSourceCount];
|
||||
memcpy(_listenSources, currentBuffer, sizeof(int) * _listenSourceCount);
|
||||
currentBuffer += sizeof(int) * _listenSourceCount;
|
||||
|
||||
}
|
||||
|
||||
return currentBuffer - sourceBuffer;
|
||||
|
|
|
@ -31,6 +31,10 @@ public:
|
|||
const glm::vec3& getPosition() const { return _position; }
|
||||
const glm::quat& getOrientation() const { return _orientation; }
|
||||
|
||||
bool isListeningToSource(PositionalAudioRingBuffer* other);
|
||||
int getSourceID() const { return _sourceID; }
|
||||
int getListeningMode() const { return _listenMode; }
|
||||
|
||||
protected:
|
||||
// disallow copying of PositionalAudioRingBuffer objects
|
||||
PositionalAudioRingBuffer(const PositionalAudioRingBuffer&);
|
||||
|
|
|
@ -159,12 +159,16 @@ int main(int argc, const char* argv[]) {
|
|||
// zero out the client mix for this node
|
||||
memset(clientSamples, 0, sizeof(clientSamples));
|
||||
|
||||
// loop through all other nodes that have sufficient audio to mix
|
||||
for (NodeList::iterator otherNode = nodeList->begin(); otherNode != nodeList->end(); otherNode++) {
|
||||
|
||||
if (((PositionalAudioRingBuffer*) otherNode->getLinkedData())->willBeAddedToMix()
|
||||
&& (otherNode != node || (otherNode == node && nodeRingBuffer->shouldLoopbackForNode()))) {
|
||||
|
||||
PositionalAudioRingBuffer* otherNodeBuffer = (PositionalAudioRingBuffer*) otherNode->getLinkedData();
|
||||
|
||||
// based on our listen mode we will do this mixing...
|
||||
if (nodeRingBuffer->isListeningToSource(otherNodeBuffer)) {
|
||||
float bearingRelativeAngleToSource = 0.0f;
|
||||
float attenuationCoefficient = 1.0f;
|
||||
int numSamplesDelay = 0;
|
||||
|
@ -172,7 +176,8 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
stk::TwoPole* otherNodeTwoPole = NULL;
|
||||
|
||||
if (otherNode != node) {
|
||||
// only do axis/distance attenuation when in normal mode
|
||||
if (otherNode != node && nodeRingBuffer->getListeningMode() == AudioRingBuffer::NORMAL) {
|
||||
|
||||
glm::vec3 listenerPosition = nodeRingBuffer->getPosition();
|
||||
glm::vec3 relativePosition = otherNodeBuffer->getPosition() - nodeRingBuffer->getPosition();
|
||||
|
@ -325,6 +330,7 @@ int main(int argc, const char* argv[]) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(clientPacket + numBytesPacketHeader, clientSamples, sizeof(clientSamples));
|
||||
nodeList->getNodeSocket()->send(node->getPublicSocket(), clientPacket, sizeof(clientPacket));
|
||||
|
@ -340,7 +346,6 @@ int main(int argc, const char* argv[]) {
|
|||
if (nodeBuffer->getNextOutput() >= nodeBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES) {
|
||||
nodeBuffer->setNextOutput(nodeBuffer->getBuffer());
|
||||
}
|
||||
|
||||
nodeBuffer->setWillBeAddedToMix(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1835,6 +1835,11 @@ void Application::initMenu() {
|
|||
(_simulateLeapHand = debugMenu->addAction("Simulate Leap Hand"))->setCheckable(true);
|
||||
(_testRaveGlove = debugMenu->addAction("Test RaveGlove"))->setCheckable(true);
|
||||
|
||||
QMenu* audioDebugMenu = debugMenu->addMenu("Audio Debugging Tools");
|
||||
audioDebugMenu->addAction("Listen Mode Normal", this, SLOT(setListenModeNormal()), Qt::CTRL | Qt::Key_1);
|
||||
audioDebugMenu->addAction("Listen Mode Point/Radius", this, SLOT(setListenModePoint()), Qt::CTRL | Qt::Key_2);
|
||||
audioDebugMenu->addAction("Listen Mode Single Source", this, SLOT(setListenModeSingleSource()), Qt::CTRL | Qt::Key_3);
|
||||
|
||||
QMenu* settingsMenu = menuBar->addMenu("Settings");
|
||||
(_settingsAutosave = settingsMenu->addAction("Autosave"))->setCheckable(true);
|
||||
_settingsAutosave->setChecked(true);
|
||||
|
@ -1846,6 +1851,37 @@ void Application::initMenu() {
|
|||
_networkAccessManager = new QNetworkAccessManager(this);
|
||||
}
|
||||
|
||||
void Application::setListenModeNormal() {
|
||||
_audio.setListenMode(AudioRingBuffer::NORMAL);
|
||||
}
|
||||
|
||||
void Application::setListenModePoint() {
|
||||
_audio.setListenMode(AudioRingBuffer::OMNI_DIRECTIONAL_POINT);
|
||||
_audio.setListenRadius(1.0);
|
||||
}
|
||||
|
||||
void Application::setListenModeSingleSource() {
|
||||
_audio.setListenMode(AudioRingBuffer::SELECTED_SOURCES);
|
||||
_audio.clearListenSources();
|
||||
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||
if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
|
||||
Avatar* avatar = (Avatar *) node->getLinkedData();
|
||||
glm::vec3 headPosition = avatar->getHead().getPosition();
|
||||
glm::vec3 mouseRayOrigin = _myAvatar.getMouseRayOrigin();
|
||||
glm::vec3 mouseRayDirection = _myAvatar.getMouseRayDirection();
|
||||
const float HEAD_SPHERE_RADIUS = 0.07;
|
||||
|
||||
if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) {
|
||||
int sourceID = avatar->getOwningNode()->getNodeID();
|
||||
_audio.addListenSource(sourceID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Application::updateFrustumRenderModeAction() {
|
||||
switch (_frustumDrawingMode) {
|
||||
default:
|
||||
|
|
|
@ -170,6 +170,10 @@ private slots:
|
|||
void copyVoxels();
|
||||
void pasteVoxels();
|
||||
void runTests();
|
||||
void setListenModeNormal();
|
||||
void setListenModePoint();
|
||||
void setListenModeSingleSource();
|
||||
|
||||
|
||||
void renderCoverageMap();
|
||||
void renderCoverageMapsRecursively(CoverageMap* map);
|
||||
|
|
|
@ -112,7 +112,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
|
||||
// we need the amount of bytes in the buffer + 1 for type
|
||||
// + 12 for 3 floats for position + float for bearing + 1 attenuation byte
|
||||
unsigned char dataPacket[BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes];
|
||||
unsigned char dataPacket[MAX_PACKET_SIZE];
|
||||
|
||||
PACKET_TYPE packetType = (Application::getInstance()->shouldEchoAudio())
|
||||
? PACKET_TYPE_MICROPHONE_AUDIO_WITH_ECHO
|
||||
|
@ -123,21 +123,25 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
// pack Source Data
|
||||
memcpy(currentPacketPtr, &_sourceID, sizeof(_sourceID));
|
||||
currentPacketPtr += (sizeof(_sourceID));
|
||||
leadingBytes += (sizeof(_sourceID));
|
||||
|
||||
// pack Listen Mode Data
|
||||
memcpy(currentPacketPtr, &_listenMode, sizeof(_listenMode));
|
||||
currentPacketPtr += (sizeof(_listenMode));
|
||||
leadingBytes += (sizeof(_listenMode));
|
||||
|
||||
if (_listenMode == AudioRingBuffer::OMNI_DIRECTIONAL_POINT) {
|
||||
memcpy(currentPacketPtr, &_listenRadius, sizeof(_listenRadius));
|
||||
currentPacketPtr += (sizeof(_listenRadius));
|
||||
leadingBytes += (sizeof(_listenRadius));
|
||||
} else if (_listenMode == AudioRingBuffer::SELECTED_SOURCES) {
|
||||
memcpy(currentPacketPtr, &_listenSourceCount, sizeof(_listenSourceCount));
|
||||
currentPacketPtr += (sizeof(_listenSourceCount));
|
||||
|
||||
leadingBytes += (sizeof(_listenSourceCount));
|
||||
if (_listenSources) {
|
||||
memcpy(currentPacketPtr, &_listenSources, sizeof(int) * _listenSourceCount);
|
||||
memcpy(currentPacketPtr, _listenSources, sizeof(int) * _listenSourceCount);
|
||||
currentPacketPtr += (sizeof(int) * _listenSourceCount);
|
||||
leadingBytes += (sizeof(int) * _listenSourceCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,6 +360,12 @@ void Audio::addListenSource(int sourceID) {
|
|||
_listenSourceCount++;
|
||||
}
|
||||
|
||||
void Audio::clearListenSources() {
|
||||
delete[] _listenSources;
|
||||
_listenSources = NULL;
|
||||
_listenSourceCount = 0;
|
||||
}
|
||||
|
||||
void Audio::removeListenSource(int sourceID) {
|
||||
// If we don't yet have a list of listen sources, make one
|
||||
if (_listenSources) {
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void setListenRadius(float radius) { _listenRadius = radius; };
|
||||
void addListenSource(int sourceID);
|
||||
void removeListenSource(int sourceID);
|
||||
void clearListenSources();
|
||||
|
||||
private:
|
||||
PaStream* _stream;
|
||||
|
|
|
@ -164,6 +164,10 @@ public:
|
|||
glm::quat getOrientation () const;
|
||||
glm::quat getWorldAlignedOrientation() const;
|
||||
|
||||
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
|
||||
|
||||
glm::vec3 getGravity () const { return _gravity; }
|
||||
|
||||
glm::vec3 getUprightHeadPosition() const;
|
||||
|
|
Loading…
Reference in a new issue