mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 12:15:30 +02:00
Added Procedural audio noise when moving, scaled to velocity
This commit is contained in:
parent
0ae700d746
commit
baf64c07dc
6 changed files with 39 additions and 6 deletions
|
@ -111,11 +111,8 @@ int audioCallback (const void *inputBuffer,
|
||||||
|
|
||||||
int16_t *inputLeft = ((int16_t **) inputBuffer)[0];
|
int16_t *inputLeft = ((int16_t **) inputBuffer)[0];
|
||||||
|
|
||||||
// Add some noise to the audio we got from the callback
|
// Add Procedural effects to input samples
|
||||||
|
data->addProceduralSounds(inputLeft, BUFFER_LENGTH_SAMPLES);
|
||||||
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
|
|
||||||
inputLeft[i] = (int16_t) (rand() % 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputLeft != NULL) {
|
if (inputLeft != NULL) {
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ public:
|
||||||
|
|
||||||
void setWalkingState(bool newWalkState);
|
void setWalkingState(bool newWalkState);
|
||||||
|
|
||||||
|
void setLastAcceleration(glm::vec3 a) { audioData->setLastAcceleration(a); };
|
||||||
|
void setLastVelocity(glm::vec3 v) { audioData->setLastVelocity(v); };
|
||||||
|
|
||||||
// terminates audio I/O
|
// terminates audio I/O
|
||||||
bool terminate();
|
bool terminate();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,4 +28,20 @@ AudioData::~AudioData() {
|
||||||
delete audioSocket;
|
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
|
#endif
|
||||||
|
|
|
@ -39,6 +39,17 @@ class AudioData {
|
||||||
|
|
||||||
bool mixerLoopbackFlag;
|
bool mixerLoopbackFlag;
|
||||||
bool playWalkSound;
|
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__) */
|
#endif /* defined(__interface__AudioData__) */
|
||||||
|
|
|
@ -105,6 +105,7 @@ public:
|
||||||
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; };
|
const glm::vec3& getJointPosition(AvatarJointID j) const { return _joint[j].position; };
|
||||||
const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); };
|
const glm::vec3& getBodyUpDirection() const { return _orientation.getUp(); };
|
||||||
float getSpeed() const { return _speed; };
|
float getSpeed() const { return _speed; };
|
||||||
|
const glm::vec3& getVelocity() const { return _velocity; };
|
||||||
float getGirth();
|
float getGirth();
|
||||||
float getHeight();
|
float getHeight();
|
||||||
|
|
||||||
|
|
|
@ -1671,6 +1671,7 @@ void idle(void) {
|
||||||
handControl.stop();
|
handControl.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read serial port interface devices
|
||||||
if (serialPort.active && USING_INVENSENSE_MPU9150) {
|
if (serialPort.active && USING_INVENSENSE_MPU9150) {
|
||||||
serialPort.readData();
|
serialPort.readData();
|
||||||
}
|
}
|
||||||
|
@ -1697,6 +1698,10 @@ void idle(void) {
|
||||||
myAvatar.setGravity(getGravity(myAvatar.getPosition()));
|
myAvatar.setGravity(getGravity(myAvatar.getPosition()));
|
||||||
myAvatar.simulate(deltaTime);
|
myAvatar.simulate(deltaTime);
|
||||||
|
|
||||||
|
// Update audio stats for procedural sounds
|
||||||
|
audio.setLastAcceleration(myAvatar.getThrust());
|
||||||
|
audio.setLastVelocity(myAvatar.getVelocity());
|
||||||
|
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
lastTimeIdle = check;
|
lastTimeIdle = check;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue