Merge branch 'master' of github.com:/worklist/hifi into 19179

This commit is contained in:
Leonardo Murillo 2013-03-22 11:46:36 -06:00
commit f604b574c5
12 changed files with 177 additions and 87 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -44,7 +44,7 @@ const float MAX_FLANGE_SAMPLE_WEIGHT = 0.50;
const float MIN_FLANGE_INTENSITY = 0.25;
const int SAMPLE_RATE = 22050;
const float JITTER_BUFFER_LENGTH_MSECS = 4;
const float JITTER_BUFFER_LENGTH_MSECS = 12;
const short JITTER_BUFFER_SAMPLES = JITTER_BUFFER_LENGTH_MSECS *
NUM_AUDIO_CHANNELS * (SAMPLE_RATE / 1000.0);
@ -62,12 +62,18 @@ const int AUDIO_UDP_LISTEN_PORT = 55444;
int starve_counter = 0;
StDev stdev;
bool stopAudioReceiveThread = false;
int samplesLeftForFlange = 0;
int lastYawMeasuredMaximum = 0;
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;
@ -112,6 +118,26 @@ int audioCallback (const void *inputBuffer,
if (inputLeft != NULL) {
//
// Measure the loudness of the signal from the microphone and store in audio object
//
float loudness = 0;
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
loudness += abs(inputLeft[i]);
}
loudness /= BUFFER_LENGTH_SAMPLES;
data->lastInputLoudness = loudness;
data->averagedInputLoudness = 0.66*data->averagedInputLoudness + 0.33*loudness;
//
// If scope is turned on, copy input buffer to scope
//
if (scope->getState()) {
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
scope->addData((float)inputLeft[i]/32767.0, 1, i);
}
}
if (data->mixerAddress != 0) {
sockaddr_in audioMixerSocket;
audioMixerSocket.sin_family = AF_INET;
@ -147,32 +173,43 @@ int audioCallback (const void *inputBuffer,
memcpy(currentPacketPtr, &correctedYaw, sizeof(float));
currentPacketPtr += sizeof(float);
if (samplesLeftForWalk == 0) {
sampleWalkPointer = walkingSoundArray;
}
if (data->playWalkSound) {
// if this boolean is true and we aren't currently playing the walk sound
// set the number of samples left for walk
samplesLeftForWalk = walkingSoundSamples;
data->playWalkSound = false;
}
if (samplesLeftForWalk > 0) {
// we need to play part of the walking sound
// so add it in
int affectedSamples = std::min(samplesLeftForWalk, BUFFER_LENGTH_SAMPLES);
for (int i = 0; i < affectedSamples; i++) {
inputLeft[i] += *sampleWalkPointer;
inputLeft[i] = std::max(inputLeft[i], std::numeric_limits<int16_t>::min());
inputLeft[i] = std::min(inputLeft[i], std::numeric_limits<int16_t>::max());
sampleWalkPointer++;
samplesLeftForWalk--;
if (sampleWalkPointer - walkingSoundArray > walkingSoundSamples) {
sampleWalkPointer = walkingSoundArray;
};
}
}
// copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet
memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES);
data->audioSocket->send((sockaddr *)&audioMixerSocket, dataPacket, BUFFER_LENGTH_BYTES + leadingBytes);
}
//
// Measure the loudness of the signal from the microphone and store in audio object
//
float loudness = 0;
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
loudness += abs(inputLeft[i]);
}
loudness /= BUFFER_LENGTH_SAMPLES;
data->lastInputLoudness = loudness;
data->averagedInputLoudness = 0.66*data->averagedInputLoudness + 0.33*loudness;
//
// If scope is turned on, copy input buffer to scope
//
if (scope->getState()) {
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
scope->addData((float)inputLeft[i]/32767.0, 1, i);
}
}
}
int16_t *outputLeft = ((int16_t **) outputBuffer)[0];
@ -386,6 +423,10 @@ 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.
@ -395,6 +436,21 @@ Use Audio::getError() to retrieve the error code.
*/
Audio::Audio(Oscilloscope *s, Head *linkedHead)
{
// read the walking sound from the raw file and store it
// in the in memory array
switchToResourcesIfRequired();
FILE *soundFile = fopen("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);
paError = Pa_Initialize();
if (paError != paNoError) goto error;

View file

@ -30,6 +30,8 @@ public:
void getInputLoudness(float * lastLoudness, float * averageLoudness);
void updateMixerParams(in_addr_t mixerAddress, in_port_t mixerPort);
void setWalkingState(bool newWalkState);
// terminates audio I/O
bool terminate();
private:

View file

@ -40,6 +40,7 @@ class AudioData {
float averagedInputLoudness;
bool mixerLoopbackFlag;
bool playWalkSound;
};
#endif /* defined(__interface__AudioData__) */

View file

@ -8,30 +8,31 @@
#include <iostream>
#include <glm/glm.hpp>
#include "Head.h"
#include <vector>
#include <lodepng.h>
#include <fstream>
#include <sstream>
#include <SharedUtil.h>
#include "Head.h"
using namespace std;
float skinColor[] = {1.0f, 0.84f, 0.66f};
float browColor[] = {210.0f/255.0f, 105.0f/255.0f, 30.0f/255.0f};
float skinColor[] = {1.0, 0.84, 0.66};
float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0};
float mouthColor[] = {1, 0, 0};
float BrowRollAngle[5] = {0, 15, 30, -30, -15};
float BrowPitchAngle[3] = {-70, -60, -50};
float eyeColor[3] = {1,1,1};
float MouthWidthChoices[3] = {0.5f, 0.77f, 0.3f};
float MouthWidthChoices[3] = {0.5, 0.77, 0.3};
float browWidth = 0.8f;
float browThickness = 0.16f;
float browWidth = 0.8;
float browThickness = 0.16;
const float DECAY = 0.1f;
const float DECAY = 0.1;
char iris_texture_file[] = "interface.app/Contents/Resources/images/green_eye.png";
char iris_texture_file[] = "images/green_eye.png";
vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512;
@ -42,20 +43,20 @@ GLUquadric *sphere = gluNewQuadric();
Head::Head()
{
position.x = position.y = position.z = 0;
PupilSize = 0.10f;
interPupilDistance = 0.6f;
interBrowDistance = 0.75f;
NominalPupilSize = 0.10f;
Yaw = 0.0f;
PupilSize = 0.10;
interPupilDistance = 0.6;
interBrowDistance = 0.75;
NominalPupilSize = 0.10;
Yaw = 0.0;
EyebrowPitch[0] = EyebrowPitch[1] = -30;
EyebrowRoll[0] = 20;
EyebrowRoll[1] = -20;
MouthPitch = 0;
MouthYaw = 0;
MouthWidth = 1.0;
MouthHeight = 0.2f;
MouthHeight = 0.2;
EyeballPitch[0] = EyeballPitch[1] = 0;
EyeballScaleX = 1.2f; EyeballScaleY = 1.5f; EyeballScaleZ = 1.0f;
EyeballScaleX = 1.2; EyeballScaleY = 1.5; EyeballScaleZ = 1.0;
EyeballYaw[0] = EyeballYaw[1] = 0;
PitchTarget = YawTarget = 0;
NoiseEnvelope = 1.0;
@ -77,6 +78,7 @@ Head::Head()
hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
if (iris_texture.size() == 0) {
switchToResourcesIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
if (error != 0) {
std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl;
@ -150,13 +152,13 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea
const float PITCH_ACCEL_COUPLING = 0.5;
const float ROLL_ACCEL_COUPLING = -1.0;
float measured_pitch_rate = static_cast<float>(serialInterface->getRelativeValue(PITCH_RATE));
YawRate = static_cast<float>(serialInterface->getRelativeValue(YAW_RATE));
float measured_pitch_rate = serialInterface->getRelativeValue(PITCH_RATE);
YawRate = serialInterface->getRelativeValue(YAW_RATE);
float measured_lateral_accel = serialInterface->getRelativeValue(ACCEL_X) -
ROLL_ACCEL_COUPLING*serialInterface->getRelativeValue(ROLL_RATE);
float measured_fwd_accel = serialInterface->getRelativeValue(ACCEL_Z) -
PITCH_ACCEL_COUPLING*serialInterface->getRelativeValue(PITCH_RATE);
float measured_roll_rate = static_cast<float>(serialInterface->getRelativeValue(ROLL_RATE));
float measured_roll_rate = serialInterface->getRelativeValue(ROLL_RATE);
//std::cout << "Pitch Rate: " << serialInterface->getRelativeValue(PITCH_RATE) <<
// " fwd_accel: " << serialInterface->getRelativeValue(ACCEL_Z) << "\n";
@ -165,9 +167,9 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea
//std::cout << "Pitch: " << Pitch << "\n";
// Update avatar head position based on measured gyro rates
const float HEAD_ROTATION_SCALE = 0.70f;
const float HEAD_ROLL_SCALE = 0.40f;
const float HEAD_LEAN_SCALE = 0.01f;
const float HEAD_ROTATION_SCALE = 0.70;
const float HEAD_ROLL_SCALE = 0.40;
const float HEAD_LEAN_SCALE = 0.01;
const float MAX_PITCH = 45;
const float MIN_PITCH = -45;
const float MAX_YAW = 85;
@ -230,8 +232,8 @@ void Head::simulate(float deltaTime)
eyeContact = 1;
if (!eyeContact) {
// If we just stopped making eye contact,move the eyes markedly away
EyeballPitch[0] = EyeballPitch[1] = EyeballPitch[0] + 5.0f + (randFloat() - 0.5f)*10.0f;
EyeballYaw[0] = EyeballYaw[1] = EyeballYaw[0] + 5.0f + (randFloat()- 0.5f)*5.0f;
EyeballPitch[0] = EyeballPitch[1] = EyeballPitch[0] + 5.0 + (randFloat() - 0.5)*10;
EyeballYaw[0] = EyeballYaw[1] = EyeballYaw[0] + 5.0 + (randFloat()- 0.5)*5;
} else {
// If now making eye contact, turn head to look right at viewer
SetNewHeadTarget(0,0);
@ -256,15 +258,15 @@ void Head::simulate(float deltaTime)
if (noise)
{
Pitch += (randFloat() - 0.5f)*0.2f*NoiseEnvelope;
Yaw += (randFloat() - 0.5f)*0.3f*NoiseEnvelope;
Pitch += (randFloat() - 0.5)*0.2*NoiseEnvelope;
Yaw += (randFloat() - 0.5)*0.3*NoiseEnvelope;
//PupilSize += (randFloat() - 0.5)*0.001*NoiseEnvelope;
if (randFloat() < 0.005) MouthWidth = MouthWidthChoices[rand()%3];
if (!eyeContact) {
if (randFloat() < 0.01f) EyeballPitch[0] = EyeballPitch[1] = (randFloat() - 0.5f)*20.0f;
if (randFloat() < 0.01f) EyeballYaw[0] = EyeballYaw[1] = (randFloat()- 0.5f)*10.0f;
if (randFloat() < 0.01) EyeballPitch[0] = EyeballPitch[1] = (randFloat() - 0.5)*20;
if (randFloat() < 0.01) EyeballYaw[0] = EyeballYaw[1] = (randFloat()- 0.5)*10;
} else {
float eye_target_yaw_adjust = 0;
float eye_target_pitch_adjust = 0;
@ -280,17 +282,17 @@ void Head::simulate(float deltaTime)
if ((randFloat() < 0.005) && (fabs(PitchTarget - Pitch) < 1.0) && (fabs(YawTarget - Yaw) < 1.0))
{
SetNewHeadTarget((randFloat()-0.5f)*20.0f, (randFloat()-0.5f)*45.0f);
SetNewHeadTarget((randFloat()-0.5)*20.0, (randFloat()-0.5)*45.0);
}
if (0)
{
// Pick new target
PitchTarget = (randFloat() - 0.5f)*45.0f;
YawTarget = (randFloat() - 0.5f)*22.0f;
PitchTarget = (randFloat() - 0.5)*45;
YawTarget = (randFloat() - 0.5)*22;
}
if (randFloat() < 0.01f)
if (randFloat() < 0.01)
{
EyebrowPitch[0] = EyebrowPitch[1] = BrowPitchAngle[rand()%3];
EyebrowRoll[0] = EyebrowRoll[1] = BrowRollAngle[rand()%5];
@ -345,35 +347,35 @@ void Head::render(int faceToFace, int isMine, float * myLocation)
for(side = 0; side < 2; side++)
{
glPushMatrix();
glScalef(0.3f, 0.65f, .65f);
glutSolidSphere(0.5f, 30, 30);
glScalef(0.3, 0.65, .65);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
glTranslatef(-2.0f, 0, 0);
glTranslatef(-2.0, 0, 0);
}
glPopMatrix();
// Eyebrows
audioAttack = 0.9f*audioAttack + 0.1f*fabs(loudness - lastLoudness);
audioAttack = 0.9*audioAttack + 0.1*fabs(loudness - lastLoudness);
lastLoudness = loudness;
const float BROW_LIFT_THRESHOLD = 100;
if (audioAttack > BROW_LIFT_THRESHOLD)
browAudioLift += sqrt(audioAttack)/1000.0f;
browAudioLift += sqrt(audioAttack)/1000.0;
browAudioLift *= .90f;
browAudioLift *= .90;
glPushMatrix();
glTranslatef(-interBrowDistance/2.0f,0.4f,0.45f);
glTranslatef(-interBrowDistance/2.0,0.4,0.45);
for(side = 0; side < 2; side++)
{
glColor3fv(browColor);
glPushMatrix();
glTranslatef(0, 0.35f + browAudioLift, 0);
glRotatef(EyebrowPitch[side]/2.0f, 1, 0, 0);
glRotatef(EyebrowRoll[side]/2.0f, 0, 0, 1);
glTranslatef(0, 0.35 + browAudioLift, 0);
glRotatef(EyebrowPitch[side]/2.0, 1, 0, 0);
glRotatef(EyebrowRoll[side]/2.0, 0, 0, 1);
glScalef(browWidth, browThickness, 1);
glutSolidCube(0.5f);
glutSolidCube(0.5);
glPopMatrix();
glTranslatef(interBrowDistance, 0, 0);
}
@ -383,23 +385,23 @@ void Head::render(int faceToFace, int isMine, float * myLocation)
// Mouth
glPushMatrix();
glTranslatef(0,-0.35f,0.75f);
glTranslatef(0,-0.35,0.75);
glColor3f(0,0,0);
glRotatef(MouthPitch, 1, 0, 0);
glRotatef(MouthYaw, 0, 0, 1);
glScalef(MouthWidth*(.7f + sqrt(averageLoudness)/60.0f), MouthHeight*(1.0f + sqrt(averageLoudness)/30.0f), 1);
glutSolidCube(0.5f);
glScalef(MouthWidth*(.7 + sqrt(averageLoudness)/60.0), MouthHeight*(1.0 + sqrt(averageLoudness)/30.0), 1);
glutSolidCube(0.5);
glPopMatrix();
glTranslatef(0, 1.0, 0);
glTranslatef(-interPupilDistance/2.0f,-0.68f,0.7f);
glTranslatef(-interPupilDistance/2.0,-0.68,0.7);
// Right Eye
glRotatef(-10, 1, 0, 0);
glColor3fv(eyeColor);
glPushMatrix();
{
glTranslatef(interPupilDistance/10.0f, 0, 0.05f);
glTranslatef(interPupilDistance/10.0, 0, 0.05);
glRotatef(20, 0, 0, 1);
glScalef(EyeballScaleX, EyeballScaleY, EyeballScaleZ);
glutSolidSphere(0.25, 30, 30);
@ -420,9 +422,9 @@ void Head::render(int faceToFace, int isMine, float * myLocation)
{
glRotatef(EyeballPitch[1], 1, 0, 0);
glRotatef(EyeballYaw[1] + PupilConverge, 0, 1, 0);
glTranslatef(0,0,.35f);
glTranslatef(0,0,.35);
glRotatef(-75,1,0,0);
glScalef(1.0f, 0.4f, 1.0f);
glScalef(1.0, 0.4, 1.0);
glEnable(GL_TEXTURE_2D);
gluSphere(sphere, PupilSize, 15, 15);
@ -435,7 +437,7 @@ void Head::render(int faceToFace, int isMine, float * myLocation)
glTranslatef(interPupilDistance, 0, 0);
glPushMatrix();
{
glTranslatef(-interPupilDistance/10.0f, 0, .05f);
glTranslatef(-interPupilDistance/10.0, 0, .05);
glRotatef(-20, 0, 0, 1);
glScalef(EyeballScaleX, EyeballScaleY, EyeballScaleZ);
glutSolidSphere(0.25, 30, 30);
@ -446,9 +448,9 @@ void Head::render(int faceToFace, int isMine, float * myLocation)
{
glRotatef(EyeballPitch[0], 1, 0, 0);
glRotatef(EyeballYaw[0] - PupilConverge, 0, 1, 0);
glTranslatef(0, 0, .35f);
glTranslatef(0, 0, .35);
glRotatef(-75, 1, 0, 0);
glScalef(1.0f, 0.4f, 1.0f);
glScalef(1.0, 0.4, 1.0);
glEnable(GL_TEXTURE_2D);
gluSphere(sphere, PupilSize, 15, 15);

View file

@ -145,6 +145,8 @@ void VoxelSystem::init() {
}
void VoxelSystem::render() {
glPushMatrix();
if (voxelsToRender) {
glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID);
@ -180,6 +182,9 @@ void VoxelSystem::render() {
// bind with 0 to switch back to normal operation
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// scale back down to 1 so heads aren't massive
glPopMatrix();
}
void VoxelSystem::simulate(float deltaTime) {

View file

@ -197,8 +197,6 @@ unsigned int texture_height = 256;
float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles
float pointer_attenuation_quadratic[] = { 1.0f, 0.0f, 0.0f }; // for 2D view
#ifdef MARKER_CAPTURE
/*** Marker Capture ***/
@ -583,7 +581,7 @@ void display(void)
// Draw cloud of dots
glDisable( GL_POINT_SPRITE_ARB );
glDisable( GL_TEXTURE_2D );
if (!display_head) cloud.render();
// if (!display_head) cloud.render();
// Draw voxels
voxels.render();
@ -700,17 +698,20 @@ const float KEYBOARD_FLY_RATE = 0.08;
void specialkey(int k, int x, int y)
{
if (k == GLUT_KEY_UP) fwd_vel += KEYBOARD_FLY_RATE;
if (k == GLUT_KEY_DOWN) fwd_vel -= KEYBOARD_FLY_RATE;
if (k == GLUT_KEY_LEFT) {
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel -= KEYBOARD_STRAFE_RATE;
if (k == GLUT_KEY_UP || k == GLUT_KEY_DOWN || k == GLUT_KEY_LEFT || k == GLUT_KEY_RIGHT) {
if (k == GLUT_KEY_UP) fwd_vel += KEYBOARD_FLY_RATE;
if (k == GLUT_KEY_DOWN) fwd_vel -= KEYBOARD_FLY_RATE;
if (k == GLUT_KEY_LEFT) {
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel -= KEYBOARD_STRAFE_RATE;
else render_yaw_rate -= KEYBOARD_YAW_RATE;
}
if (k == GLUT_KEY_RIGHT) {
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel += KEYBOARD_STRAFE_RATE;
else render_yaw_rate += KEYBOARD_YAW_RATE;
}
}
if (k == GLUT_KEY_RIGHT) {
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) lateral_vel += KEYBOARD_STRAFE_RATE;
else render_yaw_rate += KEYBOARD_YAW_RATE;
}
audio.setWalkingState(true);
}
}
void key(unsigned char k, int x, int y)
{
@ -920,6 +921,7 @@ int main(int argc, char** argv)
}
}
#endif
// Lookup the IP address of things we have hostnames
if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo;

View file

@ -10,6 +10,10 @@
#include <cstdio>
#include "SharedUtil.h"
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#endif
double usecTimestamp(timeval *time) {
return (time->tv_sec * 1000000.0 + time->tv_usec);
}
@ -56,3 +60,19 @@ int numberOfOnes(unsigned char byte) {
bool oneAtBit(unsigned char byte, int bitIndex) {
return (byte >> (7 - bitIndex) & 1);
}
void switchToResourcesIfRequired() {
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) // Error: expected unqualified-id before 'if'
{
// error!
}
CFRelease(resourcesURL); // error: expected constructor, destructor or type conversion before '(' token
chdir(path); // error: expected constructor, destructor or type conversion before '(' token
std::cout << "Current Path: " << path << std::endl; // error: expected constructor, destructor or type conversion before '<<' token
#endif
}

View file

@ -29,4 +29,6 @@ void outputBits(unsigned char byte);
int numberOfOnes(unsigned char byte);
bool oneAtBit(unsigned char byte, int bitIndex);
void switchToResourcesIfRequired();
#endif /* defined(__hifi__SharedUtil__) */