mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:29:42 +02:00
improve collision sounds, difference between ground and voxels
This commit is contained in:
parent
d05108e26d
commit
edf031b985
4 changed files with 46 additions and 12 deletions
|
@ -333,6 +333,9 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
||||||
_flangeRate(0.0f),
|
_flangeRate(0.0f),
|
||||||
_flangeWeight(0.0f),
|
_flangeWeight(0.0f),
|
||||||
_collisionSoundMagnitude(0.0f),
|
_collisionSoundMagnitude(0.0f),
|
||||||
|
_collisionSoundFrequency(0.0f),
|
||||||
|
_collisionSoundNoise(0.0f),
|
||||||
|
_collisionSoundDuration(0.0f),
|
||||||
_proceduralEffectSample(0),
|
_proceduralEffectSample(0),
|
||||||
_heartbeatMagnitude(0.0f)
|
_heartbeatMagnitude(0.0f)
|
||||||
{
|
{
|
||||||
|
@ -621,17 +624,16 @@ void Audio::addProceduralSounds(int16_t* inputBuffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const float COLLISION_SOUND_CUTOFF_LEVEL = 5.0f;
|
const float COLLISION_SOUND_CUTOFF_LEVEL = 5.0f;
|
||||||
const float COLLISION_SOUND_PITCH_1 = 2.0f;
|
|
||||||
const float COLLISION_SOUND_DECAY = 1.f/1024.f;
|
|
||||||
const float COLLISION_VOLUME_BASELINE = 10.f;
|
|
||||||
int sample;
|
int sample;
|
||||||
if (_collisionSoundMagnitude > COLLISION_SOUND_CUTOFF_LEVEL) {
|
if (_collisionSoundMagnitude > COLLISION_SOUND_CUTOFF_LEVEL) {
|
||||||
for (int i = 0; i < numSamples; i++) {
|
for (int i = 0; i < numSamples; i++) {
|
||||||
sample = (int16_t) ((sinf((float) (_proceduralEffectSample + i) / COLLISION_SOUND_PITCH_1) * COLLISION_VOLUME_BASELINE * _collisionSoundMagnitude));
|
sample = (int16_t) (((sinf(((float)_proceduralEffectSample + (float)i) * _collisionSoundFrequency) * (1.f - _collisionSoundNoise)
|
||||||
|
+ ((randFloat() * 2.f - 1.0f) * _collisionSoundNoise))
|
||||||
|
* _collisionSoundMagnitude));
|
||||||
inputBuffer[i] += sample;
|
inputBuffer[i] += sample;
|
||||||
outputLeft[i] += sample;
|
outputLeft[i] += sample;
|
||||||
outputRight[i] += sample;
|
outputRight[i] += sample;
|
||||||
_collisionSoundMagnitude *= (1.f - COLLISION_SOUND_DECAY);
|
_collisionSoundMagnitude *= _collisionSoundDuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,6 +643,12 @@ void Audio::addProceduralSounds(int16_t* inputBuffer,
|
||||||
_proceduralEffectSample += numSamples;
|
_proceduralEffectSample += numSamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio::startCollisionSound(float magnitude, float frequency, float noise, float duration) {
|
||||||
|
_collisionSoundMagnitude = magnitude;
|
||||||
|
_collisionSoundFrequency = frequency;
|
||||||
|
_collisionSoundNoise = noise;
|
||||||
|
_collisionSoundDuration = duration;
|
||||||
|
}
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// Accoustic ping (audio system round trip time determination)
|
// Accoustic ping (audio system round trip time determination)
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
|
@ -46,6 +46,8 @@ public:
|
||||||
|
|
||||||
void setCollisionSoundMagnitude(float collisionSoundMagnitude) { _collisionSoundMagnitude = collisionSoundMagnitude; }
|
void setCollisionSoundMagnitude(float collisionSoundMagnitude) { _collisionSoundMagnitude = collisionSoundMagnitude; }
|
||||||
|
|
||||||
|
void startCollisionSound(float magnitude, float frequency, float noise, float duration);
|
||||||
|
|
||||||
void ping();
|
void ping();
|
||||||
|
|
||||||
// Call periodically to eventually perform round trip time analysis,
|
// Call periodically to eventually perform round trip time analysis,
|
||||||
|
@ -84,6 +86,9 @@ private:
|
||||||
float _flangeRate;
|
float _flangeRate;
|
||||||
float _flangeWeight;
|
float _flangeWeight;
|
||||||
float _collisionSoundMagnitude;
|
float _collisionSoundMagnitude;
|
||||||
|
float _collisionSoundFrequency;
|
||||||
|
float _collisionSoundNoise;
|
||||||
|
float _collisionSoundDuration;
|
||||||
int _proceduralEffectSample;
|
int _proceduralEffectSample;
|
||||||
float _heartbeatMagnitude;
|
float _heartbeatMagnitude;
|
||||||
|
|
||||||
|
|
|
@ -873,12 +873,15 @@ void Avatar::updateCollisionWithEnvironment() {
|
||||||
float radius = _height * 0.125f;
|
float radius = _height * 0.125f;
|
||||||
const float ENVIRONMENT_SURFACE_ELASTICITY = 1.0f;
|
const float ENVIRONMENT_SURFACE_ELASTICITY = 1.0f;
|
||||||
const float ENVIRONMENT_SURFACE_DAMPING = 0.01;
|
const float ENVIRONMENT_SURFACE_DAMPING = 0.01;
|
||||||
|
const float ENVIRONMENT_COLLISION_FREQUENCY = 0.05f;
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
if (Application::getInstance()->getEnvironment()->findCapsulePenetration(
|
if (Application::getInstance()->getEnvironment()->findCapsulePenetration(
|
||||||
_position - up * (_pelvisFloatingHeight - radius),
|
_position - up * (_pelvisFloatingHeight - radius),
|
||||||
_position + up * (_height - _pelvisFloatingHeight - radius), radius, penetration)) {
|
_position + up * (_height - _pelvisFloatingHeight - radius), radius, penetration)) {
|
||||||
|
createCollisionSound(penetration, ENVIRONMENT_COLLISION_FREQUENCY);
|
||||||
applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING);
|
applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,10 +890,12 @@ void Avatar::updateCollisionWithVoxels() {
|
||||||
float radius = _height * 0.125f;
|
float radius = _height * 0.125f;
|
||||||
const float VOXEL_ELASTICITY = 1.4f;
|
const float VOXEL_ELASTICITY = 1.4f;
|
||||||
const float VOXEL_DAMPING = 0.0;
|
const float VOXEL_DAMPING = 0.0;
|
||||||
|
const float VOXEL_COLLISION_FREQUENCY = 0.5f;
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
if (Application::getInstance()->getVoxels()->findCapsulePenetration(
|
if (Application::getInstance()->getVoxels()->findCapsulePenetration(
|
||||||
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
|
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
|
||||||
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight - radius, 0.0f), radius, penetration)) {
|
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight - radius, 0.0f), radius, penetration)) {
|
||||||
|
createCollisionSound(penetration, VOXEL_COLLISION_FREQUENCY);
|
||||||
applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING);
|
applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -916,16 +921,31 @@ void Avatar::applyHardCollision(const glm::vec3& penetration, float elasticity,
|
||||||
// If moving really slowly after a collision, and not applying forces, stop altogether
|
// If moving really slowly after a collision, and not applying forces, stop altogether
|
||||||
_velocity *= 0.f;
|
_velocity *= 0.f;
|
||||||
}
|
}
|
||||||
// Push the collision into the audio system for procedural effects
|
|
||||||
const float AUDIBLE_COLLISION_THRESHOLD = 200.f;
|
|
||||||
const float COLLISION_VOLUME = 10000.f;
|
|
||||||
float collisionSoundLevel = penetrationLength * COLLISION_VOLUME;
|
|
||||||
if (collisionSoundLevel > AUDIBLE_COLLISION_THRESHOLD) {
|
|
||||||
Application::getInstance()->getAudio()->setCollisionSoundMagnitude(collisionSoundLevel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Avatar::createCollisionSound(const glm::vec3 &penetration, float frequency) {
|
||||||
|
// Push the collision into the audio system for procedural effects
|
||||||
|
const float AUDIBLE_COLLISION_THRESHOLD = 0.2f;
|
||||||
|
const float COLLISION_VOLUME = 1000.f;
|
||||||
|
const float MAX_COLLISION_VOLUME = 15000.f;
|
||||||
|
const float DURATION_SCALING = 0.004f;
|
||||||
|
float velocityTowardCollision = glm::dot(_velocity, glm::normalize(penetration));
|
||||||
|
float velocityTangentToCollision = glm::length(_velocity) - velocityTowardCollision;
|
||||||
|
if (velocityTowardCollision > AUDIBLE_COLLISION_THRESHOLD) {
|
||||||
|
Application::getInstance()->getAudio()->startCollisionSound(
|
||||||
|
fmax(COLLISION_VOLUME * velocityTowardCollision, MAX_COLLISION_VOLUME),
|
||||||
|
frequency,
|
||||||
|
fmin(velocityTangentToCollision / velocityTowardCollision, 1.f),
|
||||||
|
1.f - DURATION_SCALING * powf(frequency, 0.5f) / velocityTowardCollision);
|
||||||
|
|
||||||
|
}
|
||||||
|
//float collisionSoundLevel = penetrationLength * COLLISION_VOLUME;
|
||||||
|
//if (collisionSoundLevel > AUDIBLE_COLLISION_THRESHOLD) {
|
||||||
|
// Application::getInstance()->getAudio()->setCollisionSoundMagnitude(collisionSoundLevel);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
void Avatar::updateAvatarCollisions(float deltaTime) {
|
void Avatar::updateAvatarCollisions(float deltaTime) {
|
||||||
|
|
||||||
// Reset detector for nearest avatar
|
// Reset detector for nearest avatar
|
||||||
|
|
|
@ -262,6 +262,7 @@ private:
|
||||||
void updateCollisionWithEnvironment();
|
void updateCollisionWithEnvironment();
|
||||||
void updateCollisionWithVoxels();
|
void updateCollisionWithVoxels();
|
||||||
void applyHardCollision(const glm::vec3& penetration, float elasticity, float damping);
|
void applyHardCollision(const glm::vec3& penetration, float elasticity, float damping);
|
||||||
|
void createCollisionSound(const glm::vec3& penetration, float frequency);
|
||||||
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
||||||
void checkForMouseRayTouching();
|
void checkForMouseRayTouching();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue