Added Procedural audio noise when moving, scaled to velocity

This commit is contained in:
Philip Rosedale 2013-05-08 09:04:38 -07:00
parent 0ae700d746
commit baf64c07dc
6 changed files with 39 additions and 6 deletions

View file

@ -111,11 +111,8 @@ int audioCallback (const void *inputBuffer,
int16_t *inputLeft = ((int16_t **) inputBuffer)[0];
// Add some noise to the audio we got from the callback
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
inputLeft[i] = (int16_t) (rand() % 65536);
}
// Add Procedural effects to input samples
data->addProceduralSounds(inputLeft, BUFFER_LENGTH_SAMPLES);
if (inputLeft != NULL) {

View file

@ -30,6 +30,9 @@ public:
void setWalkingState(bool newWalkState);
void setLastAcceleration(glm::vec3 a) { audioData->setLastAcceleration(a); };
void setLastVelocity(glm::vec3 v) { audioData->setLastVelocity(v); };
// terminates audio I/O
bool terminate();
private:

View file

@ -28,4 +28,20 @@ AudioData::~AudioData() {
delete audioSocket;
}
// Take a pointer to the acquired microphone input samples and add procedural sounds
void AudioData::addProceduralSounds(int16_t* inputBuffer, int numSamples) {
const float MAX_AUDIBLE_VELOCITY = 3.0;
const float MIN_AUDIBLE_VELOCITY = 0.1;
const float VOLUME = 200;
float speed = glm::length(_lastVelocity);
if ((speed > MIN_AUDIBLE_VELOCITY) && (speed < MAX_AUDIBLE_VELOCITY)) {
for (int i = 0; i < numSamples; i++) {
inputBuffer[i] += (int16_t) ((randFloat() - 0.5f) * VOLUME * speed) ;
}
}
return;
}
#endif

View file

@ -39,6 +39,17 @@ class AudioData {
bool mixerLoopbackFlag;
bool playWalkSound;
// Added avatar acceleration and velocity for procedural effects sounds from client
void setLastVelocity(glm::vec3 v) { _lastVelocity = v; };
void setLastAcceleration(glm::vec3 a) { _lastAcceleration = a; };
void addProceduralSounds(int16_t* inputBuffer, int numSamples);
private:
glm::vec3 _lastVelocity;
glm::vec3 _lastAcceleration;
};
#endif /* defined(__interface__AudioData__) */

View file

@ -105,6 +105,7 @@ public:
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; };
const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); };
float getSpeed() const { return _speed; };
const glm::vec3& getVelocity() const { return _velocity; };
float getGirth();
float getHeight();

View file

@ -1671,6 +1671,7 @@ void idle(void) {
handControl.stop();
}
// Read serial port interface devices
if (serialPort.active && USING_INVENSENSE_MPU9150) {
serialPort.readData();
}
@ -1696,7 +1697,11 @@ void idle(void) {
myAvatar.setGravity(getGravity(myAvatar.getPosition()));
myAvatar.simulate(deltaTime);
// Update audio stats for procedural sounds
audio.setLastAcceleration(myAvatar.getThrust());
audio.setLastVelocity(myAvatar.getVelocity());
glutPostRedisplay();
lastTimeIdle = check;
}