mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 02:56:55 +02:00
constantize the number of packets to discard for stats
This commit is contained in:
parent
b186dd0f65
commit
274c810dec
1 changed files with 7 additions and 4 deletions
|
@ -286,8 +286,8 @@ Audio::Audio(Oscilloscope* scope) :
|
||||||
_lastAcceleration(0),
|
_lastAcceleration(0),
|
||||||
_totalPacketsReceived(0),
|
_totalPacketsReceived(0),
|
||||||
_firstPlaybackTime(),
|
_firstPlaybackTime(),
|
||||||
_packetsReceivedThisPlayback(0) {
|
_packetsReceivedThisPlayback(0)
|
||||||
|
{
|
||||||
outputPortAudioError(Pa_Initialize());
|
outputPortAudioError(Pa_Initialize());
|
||||||
outputPortAudioError(Pa_OpenDefaultStream(&_stream,
|
outputPortAudioError(Pa_OpenDefaultStream(&_stream,
|
||||||
2,
|
2,
|
||||||
|
@ -315,18 +315,21 @@ Audio::~Audio() {
|
||||||
void Audio::addProceduralSounds(int16_t* inputBuffer, int numSamples) {
|
void Audio::addProceduralSounds(int16_t* inputBuffer, int numSamples) {
|
||||||
const float MAX_AUDIBLE_VELOCITY = 6.0;
|
const float MAX_AUDIBLE_VELOCITY = 6.0;
|
||||||
const float MIN_AUDIBLE_VELOCITY = 0.1;
|
const float MIN_AUDIBLE_VELOCITY = 0.1;
|
||||||
|
|
||||||
float speed = glm::length(_lastVelocity);
|
float speed = glm::length(_lastVelocity);
|
||||||
float volume = 400 * (1.f - speed / MAX_AUDIBLE_VELOCITY);
|
float volume = 400 * (1.f - speed / MAX_AUDIBLE_VELOCITY);
|
||||||
|
|
||||||
// Add a noise-modulated sinewave with volume that tapers off with speed increasing
|
// Add a noise-modulated sinewave with volume that tapers off with speed increasing
|
||||||
if ((speed > MIN_AUDIBLE_VELOCITY) && (speed < MAX_AUDIBLE_VELOCITY)) {
|
if ((speed > MIN_AUDIBLE_VELOCITY) && (speed < MAX_AUDIBLE_VELOCITY)) {
|
||||||
for (int i = 0; i < numSamples; i++) {
|
for (int i = 0; i < numSamples; i++) {
|
||||||
inputBuffer[i] += (int16_t) ((cosf((float)i / 8.f * speed) * randFloat()) * volume * speed) ;
|
inputBuffer[i] += (int16_t)((cosf((float) i / 8.f * speed) * randFloat()) * volume * speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes) {
|
void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes) {
|
||||||
|
const int NUM_INITIAL_PACKETS_DISCARD = 3;
|
||||||
|
|
||||||
timeval currentReceiveTime;
|
timeval currentReceiveTime;
|
||||||
gettimeofday(¤tReceiveTime, NULL);
|
gettimeofday(¤tReceiveTime, NULL);
|
||||||
_totalPacketsReceived++;
|
_totalPacketsReceived++;
|
||||||
|
@ -334,7 +337,7 @@ void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBy
|
||||||
double timeDiff = diffclock(&_lastReceiveTime, ¤tReceiveTime);
|
double timeDiff = diffclock(&_lastReceiveTime, ¤tReceiveTime);
|
||||||
|
|
||||||
// Discard first few received packets for computing jitter (often they pile up on start)
|
// Discard first few received packets for computing jitter (often they pile up on start)
|
||||||
if (_totalPacketsReceived > 3) {
|
if (_totalPacketsReceived > NUM_INITIAL_PACKETS_DISCARD) {
|
||||||
::stdev.addValue(timeDiff);
|
::stdev.addValue(timeDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue