From 5bbf96d9467fcc008b24451cb2a95450b0ded98c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 5 Jun 2013 17:31:52 -0700 Subject: [PATCH] allow avatar agents to ask for audio loopback --- audio-mixer/src/AvatarAudioRingBuffer.cpp | 11 ++++++++++- audio-mixer/src/AvatarAudioRingBuffer.h | 4 ++++ audio-mixer/src/PositionalAudioRingBuffer.cpp | 1 - audio-mixer/src/PositionalAudioRingBuffer.h | 3 --- audio-mixer/src/main.cpp | 3 ++- interface/src/Audio.cpp | 4 +++- libraries/shared/src/PacketHeaders.h | 5 +++-- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/audio-mixer/src/AvatarAudioRingBuffer.cpp b/audio-mixer/src/AvatarAudioRingBuffer.cpp index 243e91033e..61d23f0fe6 100644 --- a/audio-mixer/src/AvatarAudioRingBuffer.cpp +++ b/audio-mixer/src/AvatarAudioRingBuffer.cpp @@ -6,9 +6,13 @@ // Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // +#include + #include "AvatarAudioRingBuffer.h" -AvatarAudioRingBuffer::AvatarAudioRingBuffer() : _freeVerbs() { +AvatarAudioRingBuffer::AvatarAudioRingBuffer() : + _freeVerbs(), + _shouldLoopbackForAgent(false) { } @@ -17,4 +21,9 @@ AvatarAudioRingBuffer::~AvatarAudioRingBuffer() { for (FreeVerbAgentMap::iterator verbIterator = _freeVerbs.begin(); verbIterator != _freeVerbs.end(); verbIterator++) { delete verbIterator->second; } +} + +int AvatarAudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) { + _shouldLoopbackForAgent = (sourceBuffer[0] == PACKET_HEADER_MICROPHONE_AUDIO_WITH_ECHO); + return PositionalAudioRingBuffer::parseData(sourceBuffer, numBytes); } \ No newline at end of file diff --git a/audio-mixer/src/AvatarAudioRingBuffer.h b/audio-mixer/src/AvatarAudioRingBuffer.h index 779f642f5a..1ca069b70c 100644 --- a/audio-mixer/src/AvatarAudioRingBuffer.h +++ b/audio-mixer/src/AvatarAudioRingBuffer.h @@ -21,13 +21,17 @@ public: AvatarAudioRingBuffer(); ~AvatarAudioRingBuffer(); + int parseData(unsigned char* sourceBuffer, int numBytes); + FreeVerbAgentMap& getFreeVerbs() { return _freeVerbs; } + bool shouldLoopbackForAgent() const { return _shouldLoopbackForAgent; } private: // disallow copying of AvatarAudioRingBuffer objects AvatarAudioRingBuffer(const AvatarAudioRingBuffer&); AvatarAudioRingBuffer& operator= (const AvatarAudioRingBuffer&); FreeVerbAgentMap _freeVerbs; + bool _shouldLoopbackForAgent; }; #endif /* defined(__hifi__AvatarAudioRingBuffer__) */ diff --git a/audio-mixer/src/PositionalAudioRingBuffer.cpp b/audio-mixer/src/PositionalAudioRingBuffer.cpp index 81911fc9df..03023634b4 100644 --- a/audio-mixer/src/PositionalAudioRingBuffer.cpp +++ b/audio-mixer/src/PositionalAudioRingBuffer.cpp @@ -14,7 +14,6 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer() : AudioRingBuffer(false), _position(0.0f, 0.0f, 0.0f), _orientation(0.0f, 0.0f, 0.0f, 0.0f), - _shouldLoopbackForAgent(false), _willBeAddedToMix(false) { diff --git a/audio-mixer/src/PositionalAudioRingBuffer.h b/audio-mixer/src/PositionalAudioRingBuffer.h index d1752fa0bf..41e775e74a 100644 --- a/audio-mixer/src/PositionalAudioRingBuffer.h +++ b/audio-mixer/src/PositionalAudioRingBuffer.h @@ -28,8 +28,6 @@ public: const glm::vec3& getPosition() const { return _position; } const glm::quat& getOrientation() const { return _orientation; } - bool shouldLoopbackForAgent() const { return _shouldLoopbackForAgent; } - protected: // disallow copying of PositionalAudioRingBuffer objects PositionalAudioRingBuffer(const PositionalAudioRingBuffer&); @@ -37,7 +35,6 @@ protected: glm::vec3 _position; glm::quat _orientation; - bool _shouldLoopbackForAgent; bool _willBeAddedToMix; }; diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 3fe11e2ee5..44151cee34 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -324,7 +324,8 @@ int main(int argc, const char* argv[]) { // pull any new audio data from agents off of the network stack while (agentList->getAgentSocket()->receive(agentAddress, packetData, &receivedBytes)) { - if (packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO) { + if (packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO_NO_ECHO || + packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO_WITH_ECHO) { Agent* avatarAgent = agentList->addOrUpdateAgent(agentAddress, agentAddress, AGENT_TYPE_AVATAR, diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 954d1df528..cba5139c05 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -135,7 +135,9 @@ int audioCallback (const void* inputBuffer, // + 12 for 3 floats for position + float for bearing + 1 attenuation byte unsigned char dataPacket[BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes]; - dataPacket[0] = PACKET_HEADER_MICROPHONE_AUDIO; + dataPacket[0] = (Application::getInstance()->shouldEchoAudio()) + ? PACKET_HEADER_MICROPHONE_AUDIO_WITH_ECHO + : PACKET_HEADER_MICROPHONE_AUDIO_NO_ECHO; unsigned char *currentPacketPtr = dataPacket + 1; // memcpy the three float positions diff --git a/libraries/shared/src/PacketHeaders.h b/libraries/shared/src/PacketHeaders.h index 3e6f2ba152..f40c8abea7 100644 --- a/libraries/shared/src/PacketHeaders.h +++ b/libraries/shared/src/PacketHeaders.h @@ -3,7 +3,7 @@ // hifi // // Created by Stephen Birarda on 4/8/13. -// +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // // The packet headers below refer to the first byte of a received UDP packet transmitted between // any two Hifi components. For example, a packet whose first byte is 'P' is always a ping packet. @@ -20,7 +20,8 @@ const PACKET_HEADER PACKET_HEADER_HEAD_DATA = 'H'; const PACKET_HEADER PACKET_HEADER_Z_COMMAND = 'Z'; const PACKET_HEADER PACKET_HEADER_INJECT_AUDIO = 'I'; const PACKET_HEADER PACKET_HEADER_MIXED_AUDIO = 'A'; -const PACKET_HEADER PACKET_HEADER_MICROPHONE_AUDIO = 'M'; +const PACKET_HEADER PACKET_HEADER_MICROPHONE_AUDIO_NO_ECHO = 'M'; +const PACKET_HEADER PACKET_HEADER_MICROPHONE_AUDIO_WITH_ECHO = 'm'; const PACKET_HEADER PACKET_HEADER_SET_VOXEL = 'S'; const PACKET_HEADER PACKET_HEADER_SET_VOXEL_DESTRUCTIVE = 'O'; const PACKET_HEADER PACKET_HEADER_ERASE_VOXEL = 'E';