mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 20:03:30 +02:00
Merge pull request #1310 from PhilipRosedale/master
Improved drumming, (maybe) lower latency hands
This commit is contained in:
commit
46804f4002
4 changed files with 73 additions and 15 deletions
|
@ -360,7 +360,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)
|
||||
{
|
||||
|
@ -650,6 +653,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);
|
||||
|
@ -673,6 +677,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -685,6 +713,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;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "Util.h"
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
Hand::Hand(Avatar* owningAvatar) :
|
||||
|
@ -126,23 +127,23 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
|||
}
|
||||
|
||||
void Hand::handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime) {
|
||||
//
|
||||
// Collision between finger and a voxel plays sound
|
||||
//
|
||||
float volume = glm::length(palm->getVelocity());
|
||||
const float LOWEST_FREQUENCY = 100.f;
|
||||
const float HERTZ_PER_RGB = 3.f;
|
||||
const float DECAY_PER_SAMPLE = 0.0005f;
|
||||
const float DURATION_MAX = 2.0f;
|
||||
const float MIN_VOLUME = 0.1f;
|
||||
float volume = MIN_VOLUME + glm::clamp(glm::length(palm->getVelocity()), 0.f, (1.f - MIN_VOLUME));
|
||||
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
|
||||
// Play a sound
|
||||
Application::getInstance()->getAudio()->startCollisionSound(volume,
|
||||
frequency,
|
||||
0.25,
|
||||
0.995f,
|
||||
false);
|
||||
|
||||
float frequency = LOWEST_FREQUENCY + (voxelBrightness * HERTZ_PER_RGB);
|
||||
Application::getInstance()->getAudio()->startDrumSound(volume,
|
||||
frequency,
|
||||
DURATION_MAX,
|
||||
DECAY_PER_SAMPLE);
|
||||
}
|
||||
|
||||
void Hand::calculateGeometry() {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
SixenseManager::SixenseManager() {
|
||||
#ifdef HAVE_SIXENSE
|
||||
sixenseInit();
|
||||
sixenseSetFilterEnabled(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -24,7 +25,7 @@ SixenseManager::~SixenseManager() {
|
|||
sixenseExit();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void SixenseManager::update(float deltaTime) {
|
||||
#ifdef HAVE_SIXENSE
|
||||
if (sixenseGetNumActiveControllers() == 0) {
|
||||
|
@ -68,6 +69,12 @@ void SixenseManager::update(float deltaTime) {
|
|||
palm->setControllerButtons(data.buttons);
|
||||
palm->setTrigger(data.trigger);
|
||||
palm->setJoystick(data.joystick_x, data.joystick_y);
|
||||
|
||||
// Vibrate if needed
|
||||
if (palm->getIsCollidingWithVoxel()) {
|
||||
//printf("vibrate!\n");
|
||||
//vibrate(data.controller_index, 100, 1);
|
||||
}
|
||||
|
||||
glm::vec3 position(data.pos[0], data.pos[1], data.pos[2]);
|
||||
// Adjust for distance between acquisition 'orb' and the user's torso
|
||||
|
|
Loading…
Reference in a new issue