send interface client position to audio mixer

This commit is contained in:
Stephen Birarda 2013-02-26 13:13:40 -08:00
parent df1186660b
commit 1783ee5f85
10 changed files with 52 additions and 21 deletions

View file

@ -32,8 +32,6 @@
#include "SharedUtil.h" #include "SharedUtil.h"
const int DOMAIN_LISTEN_PORT = 40102; const int DOMAIN_LISTEN_PORT = 40102;
const int MAX_PACKET_SIZE = 1500;
unsigned char packetData[MAX_PACKET_SIZE]; unsigned char packetData[MAX_PACKET_SIZE];
const int LOGOFF_CHECK_INTERVAL = 5000; const int LOGOFF_CHECK_INTERVAL = 5000;

View file

@ -84,7 +84,25 @@ int audioCallback (const void *inputBuffer,
audioMixerSocket.sin_family = AF_INET; audioMixerSocket.sin_family = AF_INET;
audioMixerSocket.sin_addr.s_addr = data->mixerAddress; audioMixerSocket.sin_addr.s_addr = data->mixerAddress;
audioMixerSocket.sin_port = data->mixerPort; audioMixerSocket.sin_port = data->mixerPort;
data->audioSocket->send((sockaddr *)&audioMixerSocket, (void *)inputLeft, BUFFER_LENGTH_BYTES);
int leadingBytes = 1 + (sizeof(float) * 3);
// we need the amount of bytes in the buffer + 1 for type + 12 for 3 floats for position
unsigned char *dataPacket = new unsigned char[BUFFER_LENGTH_BYTES + leadingBytes];
dataPacket[0] = 'I';
// memcpy the three float positions
for (int p = 0; p < 3; p++) {
memcpy(dataPacket + 1 + (p * sizeof(float)), &data->sourcePosition[p], sizeof(float));
}
// copy the audio data to the last 1024 bytes of the data packet
memcpy(dataPacket + leadingBytes, inputLeft, BUFFER_LENGTH_BYTES);
data->audioSocket->send((sockaddr *)&audioMixerSocket, dataPacket, BUFFER_LENGTH_BYTES + leadingBytes);
delete dataPacket;
} }
// //
@ -236,6 +254,10 @@ void *receiveAudioViaUDP(void *args) {
pthread_exit(0); pthread_exit(0);
} }
void Audio::setSourcePosition(glm::vec3 newPosition) {
audioData->sourcePosition = newPosition;
}
/** /**
* Initialize portaudio and start an audio stream. * Initialize portaudio and start an audio stream.
* Should be called at the beginning of program exection. * Should be called at the beginning of program exection.

View file

@ -25,11 +25,12 @@ public:
void getInputLoudness(float * lastLoudness, float * averageLoudness); void getInputLoudness(float * lastLoudness, float * averageLoudness);
void updateMixerParams(in_addr_t mixerAddress, in_port_t mixerPort); void updateMixerParams(in_addr_t mixerAddress, in_port_t mixerPort);
void setSourcePosition(glm::vec3 position);
// terminates audio I/O // terminates audio I/O
bool terminate(); bool terminate();
private: private:
bool initialized; bool initialized;
AudioData *audioData; AudioData *audioData;
// protects constructor so that public init method is used // protects constructor so that public init method is used

View file

@ -11,17 +11,22 @@
#include <iostream> #include <iostream>
#include <stdint.h> #include <stdint.h>
#include <glm/glm.hpp>
#include "AudioRingBuffer.h" #include "AudioRingBuffer.h"
#include "UDPSocket.h" #include "UDPSocket.h"
class AudioData { class AudioData {
public: public:
AudioData(int bufferLength);
~AudioData();
AudioRingBuffer *ringBuffer; AudioRingBuffer *ringBuffer;
UDPSocket *audioSocket; UDPSocket *audioSocket;
int16_t *samplesToQueue; int16_t *samplesToQueue;
glm::vec3 sourcePosition;
// store current mixer address and port // store current mixer address and port
in_addr_t mixerAddress; in_addr_t mixerAddress;
in_port_t mixerPort; in_port_t mixerPort;
@ -34,9 +39,6 @@ class AudioData {
float lastInputLoudness; float lastInputLoudness;
float averagedInputLoudness; float averagedInputLoudness;
AudioData(int bufferLength);
~AudioData();
}; };
#endif /* defined(__interface__AudioData__) */ #endif /* defined(__interface__AudioData__) */

View file

@ -53,7 +53,6 @@ int simulate_on = 1;
// Network Socket and network constants // Network Socket and network constants
// //
const int MAX_PACKET_SIZE = 1500;
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string
const int DOMAINSERVER_PORT = 40102; const int DOMAINSERVER_PORT = 40102;
@ -513,6 +512,7 @@ void simulateHead(float frametime)
myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate); myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate);
myHead.setRenderPitch(render_pitch); myHead.setRenderPitch(render_pitch);
myHead.setPos(glm::vec3(location[0], location[1], location[2])); myHead.setPos(glm::vec3(location[0], location[1], location[2]));
audio.setSourcePosition(glm::vec3(location[0], location[1], location[2]));
// Get audio loudness data from audio input device // Get audio loudness data from audio input device
float loudness, averageLoudness; float loudness, averageLoudness;

View file

@ -16,12 +16,8 @@
#include <AgentList.h> #include <AgentList.h>
#include <SharedUtil.h> #include <SharedUtil.h>
const int MAX_AGENTS = 1000;
const int LOGOFF_CHECK_INTERVAL = 1000;
const unsigned short MIXER_LISTEN_PORT = 55443; const unsigned short MIXER_LISTEN_PORT = 55443;
const float SAMPLE_RATE = 22050.0; const float SAMPLE_RATE = 22050.0;
const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES/SAMPLE_RATE) * 1000000; const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES/SAMPLE_RATE) * 1000000;
@ -35,7 +31,6 @@ char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102; const int DOMAINSERVER_PORT = 40102;
const int MAX_SOURCE_BUFFERS = 20;
AgentList agentList(MIXER_LISTEN_PORT); AgentList agentList(MIXER_LISTEN_PORT);
@ -182,7 +177,7 @@ int main(int argc, const char * argv[])
printf("Using static domainserver IP: %s\n", DOMAIN_IP); printf("Using static domainserver IP: %s\n", DOMAIN_IP);
} }
int16_t *packetData = new int16_t[BUFFER_LENGTH_SAMPLES]; unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
pthread_t sendBufferThread; pthread_t sendBufferThread;
pthread_create(&sendBufferThread, NULL, sendBuffer, NULL); pthread_create(&sendBufferThread, NULL, sendBuffer, NULL);
@ -191,9 +186,9 @@ int main(int argc, const char * argv[])
while (true) { while (true) {
if(agentList.getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if(agentList.getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) {
if (receivedBytes == BUFFER_LENGTH_BYTES) { if (receivedBytes > BUFFER_LENGTH_BYTES) {
// add or update the existing interface agent // add or update the existing interface agent
agentList.addOrUpdateAgent(agentAddress, agentAddress, 'I'); agentList.addOrUpdateAgent(agentAddress, agentAddress, packetData[0]);
agentList.updateAgentWithData(agentAddress, (void *)packetData, receivedBytes); agentList.updateAgentWithData(agentAddress, (void *)packetData, receivedBytes);
} }
} }

View file

@ -147,7 +147,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
// this is an audio mixer // this is an audio mixer
// for now that means we need to tell the audio class // for now that means we need to tell the audio class
// to use the local socket information the domain server gave us // to use the local socket information the domain server gave us
sockaddr_in *localSocketIn = (sockaddr_in *)localSocket; sockaddr_in *localSocketIn = (sockaddr_in *)publicSocket;
audioMixerSocketUpdate(localSocketIn->sin_addr.s_addr, localSocketIn->sin_port); audioMixerSocketUpdate(localSocketIn->sin_addr.s_addr, localSocketIn->sin_port);
} }

View file

@ -14,6 +14,7 @@
#include "Agent.h" #include "Agent.h"
#include "UDPSocket.h" #include "UDPSocket.h"
const int MAX_PACKET_SIZE = 1500;
const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103; const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103;
const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000; const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000;
extern const char *SOLO_AGENT_TYPES_STRING; extern const char *SOLO_AGENT_TYPES_STRING;

View file

@ -75,7 +75,19 @@ void AudioRingBuffer::setAddedToMix(bool added) {
} }
void AudioRingBuffer::parseData(void *data, int size) { void AudioRingBuffer::parseData(void *data, int size) {
int16_t *audioData = (int16_t *)data; int16_t *audioDataStart = (int16_t *) data;
if (size > BUFFER_LENGTH_BYTES) {
float position[3];
unsigned char *charData = (unsigned char *) data;
for (int p = 0; p < 3; p ++) {
memcpy(&position[p], charData + 1 + (sizeof(float) * p), sizeof(float));
}
audioDataStart = (int16_t *) charData + 1 + (sizeof(float) * 3);
}
if (endOfLastWrite == NULL) { if (endOfLastWrite == NULL) {
endOfLastWrite = buffer; endOfLastWrite = buffer;
@ -85,7 +97,7 @@ void AudioRingBuffer::parseData(void *data, int size) {
started = false; started = false;
} }
memcpy(endOfLastWrite, audioData, BUFFER_LENGTH_BYTES); memcpy(endOfLastWrite, audioDataStart, BUFFER_LENGTH_BYTES);
endOfLastWrite += BUFFER_LENGTH_SAMPLES; endOfLastWrite += BUFFER_LENGTH_SAMPLES;
if (endOfLastWrite >= buffer + RING_BUFFER_SAMPLES) { if (endOfLastWrite >= buffer + RING_BUFFER_SAMPLES) {

View file

@ -13,7 +13,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#define MAX_BUFFER_LENGTH_BYTES 1024 #define MAX_BUFFER_LENGTH_BYTES 1500
class UDPSocket { class UDPSocket {
public: public: