mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Better drums
This commit is contained in:
parent
2dfbaf605e
commit
0c32f94116
3 changed files with 56 additions and 11 deletions
|
@ -361,7 +361,10 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
|||
_collisionSoundNoise(0.0f),
|
||||
_collisionSoundDuration(0.0f),
|
||||
_proceduralEffectSample(0),
|
||||
_heartbeatMagnitude(0.0f),
|
||||
_drumSoundVolume(0),
|
||||
_drumSoundFrequency(0),
|
||||
_drumSoundDuration(0),
|
||||
_drumSoundSample(0),
|
||||
_muted(false),
|
||||
_localEcho(false)
|
||||
{
|
||||
|
@ -651,6 +654,7 @@ void Audio::addProceduralSounds(int16_t* inputBuffer,
|
|||
inputBuffer[i] += (int16_t)(sinf((float) (_proceduralEffectSample + i) / SOUND_PITCH ) * volume * (1.f + randFloat() * 0.25f) * speed);
|
||||
}
|
||||
}
|
||||
// Add a collision sound when voxels are run into
|
||||
const float COLLISION_SOUND_CUTOFF_LEVEL = 0.01f;
|
||||
const float COLLISION_SOUND_MAX_VOLUME = 1000.f;
|
||||
const float UP_MAJOR_FIFTH = powf(1.5f, 4.0f);
|
||||
|
@ -674,6 +678,30 @@ void Audio::addProceduralSounds(int16_t* inputBuffer,
|
|||
}
|
||||
}
|
||||
_proceduralEffectSample += numSamples;
|
||||
|
||||
// Add a drum sound
|
||||
const float MAX_VOLUME = 32000.f;
|
||||
const float MAX_DURATION = 2.f;
|
||||
const float MIN_AUDIBLE_VOLUME = 0.001f;
|
||||
const float NOISE_MAGNITUDE = 0.02f;
|
||||
float frequency = (_drumSoundFrequency / SAMPLE_RATE) * PI_TIMES_TWO;
|
||||
if (_drumSoundVolume > 0.f) {
|
||||
for (int i = 0; i < numSamples; i++) {
|
||||
t = (float) _drumSoundSample + (float) i;
|
||||
sample = sinf(t * frequency);
|
||||
sample += ((randFloat() - 0.5f) * NOISE_MAGNITUDE);
|
||||
sample *= _drumSoundVolume * MAX_VOLUME;
|
||||
inputBuffer[i] += (int) sample;
|
||||
outputLeft[i] += (int) sample;
|
||||
outputRight[i] += (int) sample;
|
||||
_drumSoundVolume *= (1.f - _drumSoundDecay);
|
||||
}
|
||||
_drumSoundSample += numSamples;
|
||||
_drumSoundDuration = glm::clamp(_drumSoundDuration - (AUDIO_CALLBACK_MSECS / 1000.f), 0.f, MAX_DURATION);
|
||||
if (_drumSoundDuration == 0.f || (_drumSoundVolume < MIN_AUDIBLE_VOLUME)) {
|
||||
_drumSoundVolume = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -686,6 +714,18 @@ void Audio::startCollisionSound(float magnitude, float frequency, float noise, f
|
|||
_collisionSoundDuration = duration;
|
||||
_collisionFlashesScreen = flashScreen;
|
||||
}
|
||||
|
||||
//
|
||||
// Starts a collision sound. magnitude is 0-1, with 1 the loudest possible sound.
|
||||
//
|
||||
void Audio::startDrumSound(float volume, float frequency, float duration, float decay) {
|
||||
_drumSoundVolume = volume;
|
||||
_drumSoundFrequency = frequency;
|
||||
_drumSoundDuration = duration;
|
||||
_drumSoundDecay = decay;
|
||||
_drumSoundSample = 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Accoustic ping (audio system round trip time determination)
|
||||
// -----------------------------------------------------------
|
||||
|
|
|
@ -56,7 +56,9 @@ public:
|
|||
void lowPassFilter(int16_t* inputBuffer);
|
||||
|
||||
void startCollisionSound(float magnitude, float frequency, float noise, float duration, bool flashScreen);
|
||||
|
||||
|
||||
void startDrumSound(float volume, float frequency, float duration, float decay);
|
||||
|
||||
float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; }
|
||||
|
||||
bool getCollisionFlashesScreen() { return _collisionFlashesScreen; }
|
||||
|
@ -101,13 +103,21 @@ private:
|
|||
float _flangeIntensity;
|
||||
float _flangeRate;
|
||||
float _flangeWeight;
|
||||
|
||||
// Collision sound generator
|
||||
float _collisionSoundMagnitude;
|
||||
float _collisionSoundFrequency;
|
||||
float _collisionSoundNoise;
|
||||
float _collisionSoundDuration;
|
||||
bool _collisionFlashesScreen;
|
||||
int _proceduralEffectSample;
|
||||
float _heartbeatMagnitude;
|
||||
|
||||
// Drum sound generator
|
||||
float _drumSoundVolume;
|
||||
float _drumSoundFrequency;
|
||||
float _drumSoundDuration;
|
||||
float _drumSoundDecay;
|
||||
int _drumSoundSample;
|
||||
|
||||
bool _muted;
|
||||
bool _localEcho;
|
||||
|
|
|
@ -128,20 +128,15 @@ void Hand::handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPositi
|
|||
//
|
||||
// Collision between finger and a voxel plays sound
|
||||
//
|
||||
float volume = glm::length(palm->getVelocity());
|
||||
float volume = 0.1f + glm::clamp(glm::length(palm->getVelocity()), 0.f, 0.9f);
|
||||
float duration = volume;
|
||||
_collisionCenter = fingerTipPosition;
|
||||
_collisionAge = deltaTime;
|
||||
_collisionDuration = duration;
|
||||
int voxelBrightness = voxel->getColor()[0] + voxel->getColor()[1] + voxel->getColor()[2];
|
||||
float frequency = 100.f + (voxelBrightness * 2.f); // Hz
|
||||
float frequency = 100.f + (voxelBrightness * 3.f); // Hz
|
||||
// Play a sound
|
||||
Application::getInstance()->getAudio()->startCollisionSound(volume,
|
||||
frequency,
|
||||
0.25,
|
||||
0.995f,
|
||||
false);
|
||||
|
||||
Application::getInstance()->getAudio()->startDrumSound(volume, frequency, 2.0f, 0.0005f);
|
||||
}
|
||||
|
||||
void Hand::calculateGeometry() {
|
||||
|
|
Loading…
Reference in a new issue