Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jeffrey Ventrella 2013-05-10 21:58:52 -07:00
commit 1e4305d277
7 changed files with 36 additions and 62 deletions

View file

@ -31,6 +31,8 @@ const int HAND_TIMER_SLEEP_ITERATIONS = 50;
const float EVE_PELVIS_HEIGHT = 0.565925f;
const float AUDIO_INJECT_PROXIMITY = 0.4f;
bool stopReceiveAgentDataThread;
bool injectAudioThreadRunning = false;
@ -43,20 +45,14 @@ void *receiveAgentData(void *args) {
unsigned char incomingPacket[MAX_PACKET_SIZE];
AgentList* agentList = AgentList::getInstance();
Agent* avatarMixer = NULL;
while (!::stopReceiveAgentDataThread) {
if (agentList->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) {
switch (incomingPacket[0]) {
case PACKET_HEADER_BULK_AVATAR_DATA:
// this is the positional data for other agents
// eve doesn't care about this for now, so let's just update the receive time for the
// avatar mixer - this makes sure it won't be killed during silent agent removal
avatarMixer = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
if (avatarMixer) {
avatarMixer->setLastHeardMicrostamp(usecTimestampNow());
}
// pass that off to the agentList processBulkAgentData method
agentList->processBulkAgentData(&senderAddress, incomingPacket, bytesReceived);
break;
default:
@ -94,6 +90,12 @@ void *injectAudio(void *args) {
return NULL;
}
void createAvatarDataForAgent(Agent* agent) {
if (!agent->getLinkedData()) {
agent->setLinkedData(new AvatarData());
}
}
int main(int argc, const char* argv[]) {
// new seed for random audio sleep times
srand(time(0));
@ -133,13 +135,18 @@ int main(int argc, const char* argv[]) {
// read eve's audio data
AudioInjector eveAudioInjector("/etc/highfidelity/eve/resources/eve.raw");
// lower Eve's volume by setting the attentuation modifier (this is a value out of 255)
eveAudioInjector.setAttenuationModifier(190);
// register the callback for agent data creation
agentList->linkedDataCreateCallback = createAvatarDataForAgent;
unsigned char broadcastPacket[MAX_PACKET_SIZE];
broadcastPacket[0] = PACKET_HEADER_HEAD_DATA;
timeval thisSend;
double numMicrosecondsSleep = 0;
int numIterationsLeftBeforeAudioSend = 0;
pthread_t injectAudioThread;
int handStateTimer = 0;
@ -163,21 +170,20 @@ int main(int argc, const char* argv[]) {
agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, packetPosition - broadcastPacket);
}
// temporarily disable Eve's audio sending until the file is actually available on EC2 box
if (numIterationsLeftBeforeAudioSend == 0) {
if (!::injectAudioThreadRunning) {
// enumerate the other agents to decide if one is close enough that eve should talk
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
AvatarData* avatarData = (AvatarData*) agent->getLinkedData();
if (avatarData) {
glm::vec3 tempVector = eve.getPosition() - avatarData->getPosition();
float squareDistance = glm::dot(tempVector, tempVector);
if (squareDistance <= AUDIO_INJECT_PROXIMITY) {
pthread_create(&injectAudioThread, NULL, injectAudio, (void*) &eveAudioInjector);
numIterationsLeftBeforeAudioSend = randIntInRange(MIN_ITERATIONS_BETWEEN_AUDIO_SENDS,
MAX_ITERATIONS_BETWEEN_AUDIO_SENDS);
}
} else {
numIterationsLeftBeforeAudioSend--;
}
// sleep for the correct amount of time to have data send be consistently timed
if ((numMicrosecondsSleep = (DATA_SEND_INTERVAL_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
usleep(numMicrosecondsSleep);
}
}
// simulate the effect of pressing and un-pressing the mouse button/pad
@ -190,6 +196,11 @@ int main(int argc, const char* argv[]) {
} else if (handStateTimer >= ITERATIONS_BEFORE_HAND_GRAB + HAND_GRAB_DURATION_ITERATIONS + HAND_TIMER_SLEEP_ITERATIONS) {
handStateTimer = 0;
}
// sleep for the correct amount of time to have data send be consistently timed
if ((numMicrosecondsSleep = (DATA_SEND_INTERVAL_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
usleep(numMicrosecondsSleep);
}
}
// stop the receive agent data thread

View file

@ -71,11 +71,6 @@ float flangeIntensity = 0;
float flangeRate = 0;
float flangeWeight = 0;
int16_t *walkingSoundArray;
int walkingSoundSamples;
int samplesLeftForWalk = 0;
int16_t *sampleWalkPointer;
timeval firstPlaybackTimer;
int packetsReceivedThisPlayback = 0;
float usecsAtStartup = 0;
@ -357,10 +352,6 @@ bool Audio::getMixerLoopbackFlag() {
return audioData->mixerLoopbackFlag;
}
void Audio::setWalkingState(bool newWalkState) {
audioData->playWalkSound = newWalkState;
}
/**
* Initialize portaudio and start an audio stream.
* Should be called at the beginning of program exection.
@ -368,23 +359,7 @@ void Audio::setWalkingState(bool newWalkState) {
* @return Returns true if successful or false if an error occurred.
Use Audio::getError() to retrieve the error code.
*/
Audio::Audio(Oscilloscope *s, Avatar *linkedAvatar)
{
// read the walking sound from the raw file and store it
// in the in memory array
switchToResourcesParentIfRequired();
FILE *soundFile = fopen("resources/audio/walking.raw", "r");
// get length of file:
std::fseek(soundFile, 0, SEEK_END);
walkingSoundSamples = std::ftell(soundFile) / sizeof(int16_t);
walkingSoundArray = new int16_t[walkingSoundSamples];
std::rewind(soundFile);
std::fread(walkingSoundArray, sizeof(int16_t), walkingSoundSamples, soundFile);
std::fclose(soundFile);
Audio::Audio(Oscilloscope* s, Avatar* linkedAvatar) {
paError = Pa_Initialize();
if (paError != paNoError) goto error;

View file

@ -28,8 +28,6 @@ public:
float getInputLoudness() const;
void updateMixerParams(in_addr_t mixerAddress, in_port_t mixerPort);
void setWalkingState(bool newWalkState);
void setLastAcceleration(glm::vec3 a) { audioData->setLastAcceleration(a); };
void setLastVelocity(glm::vec3 v) { audioData->setLastVelocity(v); };

View file

@ -38,7 +38,6 @@ class AudioData {
float lastInputLoudness;
bool mixerLoopbackFlag;
bool playWalkSound;
// Added avatar acceleration and velocity for procedural effects sounds from client
void setLastVelocity(glm::vec3 v) { _lastVelocity = v; };

View file

@ -214,7 +214,6 @@ double elapsedTime;
timeval applicationStartupTime;
bool justStarted = true;
// Every second, check the frame rates and other stuff
void Timer(int extra) {
gettimeofday(&timerEnd, NULL);
@ -378,9 +377,7 @@ void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) {
}
}
//
// Using gyro data, update both view frustum and avatar head position
//
void updateAvatar(float deltaTime) {
// Update my avatar's head position from gyros
@ -1234,8 +1231,6 @@ int setRenderAvatars(int state) {
return setValue(state, &::renderAvatarsOn);
}
int setOculus(int state) {
bool wasOn = ::oculusOn;
int value = setValue(state, &::oculusOn);
@ -1562,9 +1557,6 @@ void specialkey(int k, int x, int y) {
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) myAvatar.setDriveKeys(RIGHT, 1);
else myAvatar.setDriveKeys(ROT_RIGHT, 1);
}
#ifndef _WIN32
audio.setWalkingState(true);
#endif
}
}
@ -1860,7 +1852,6 @@ void idle(void) {
glutPostRedisplay();
lastTimeIdle = check;
}
}
void reshape(int width, int height) {