mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-11 01:39:30 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into improved_undo
This commit is contained in:
commit
a24f092efe
34 changed files with 398 additions and 318 deletions
|
@ -21,12 +21,10 @@
|
|||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#include <math.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#endif //_WIN32
|
||||
|
||||
|
@ -389,9 +387,8 @@ void AudioMixer::run() {
|
|||
nodeList->linkedDataCreateCallback = attachNewBufferToNode;
|
||||
|
||||
int nextFrame = 0;
|
||||
timeval startTime;
|
||||
|
||||
gettimeofday(&startTime, NULL);
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
|
||||
char* clientMixBuffer = new char[NETWORK_BUFFER_LENGTH_BYTES_STEREO
|
||||
+ numBytesForPacketHeaderGivenPacketType(PacketTypeMixedAudio)];
|
||||
|
@ -490,7 +487,7 @@ void AudioMixer::run() {
|
|||
break;
|
||||
}
|
||||
|
||||
usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
|
||||
usecToSleep = (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - timer.nsecsElapsed() / 1000; // ns to us
|
||||
|
||||
if (usecToSleep > 0) {
|
||||
usleep(usecToSleep);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "AssignmentClientMonitor.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
initialiseUsecTimestampNow();
|
||||
|
||||
#ifndef WIN32
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <Logging.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "DomainServer.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
initialiseUsecTimestampNow();
|
||||
|
||||
#ifndef WIN32
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
|
|
@ -50,7 +50,7 @@ function maybePlaySound(deltaTime) {
|
|||
const CLAP_DISTANCE = 0.2;
|
||||
|
||||
if (!clapping[palm] && (distanceBetween < CLAP_DISTANCE) && (speed > CLAP_SPEED)) {
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = palm1Position;
|
||||
options.volume = speed / 2.0;
|
||||
if (options.volume > 1.0) options.volume = 1.0;
|
||||
|
|
|
@ -61,7 +61,7 @@ function checkSticks(deltaTime) {
|
|||
// Waiting for change in velocity direction or slowing to trigger drum sound
|
||||
if ((palmVelocity.y > 0.0) || (speed < STOP_SPEED)) {
|
||||
state[palm] = 0;
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = Controller.getSpatialControlPosition(palm * 2 + 1);
|
||||
if (strokeSpeed[palm] > 1.0) { strokeSpeed[palm] = 1.0; }
|
||||
options.volume = strokeSpeed[palm];
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
// First, load the clap sound from a URL
|
||||
var clap = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/bushtit_1.raw");
|
||||
var clap = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/bushtit_1.raw");
|
||||
|
||||
function maybePlaySound(deltaTime) {
|
||||
if (Math.random() < 0.01) {
|
||||
// Set the location and other info for the sound to play
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
var palmPosition = Controller.getSpatialControlPosition(0);
|
||||
options.position = palmPosition;
|
||||
options.volume = 0.5;
|
||||
|
|
|
@ -217,7 +217,7 @@ function update(deltaTime) {
|
|||
|
||||
if (invaderStepOfCycle % stepsPerSound == 0) {
|
||||
// play the move sound
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
if (soundInMyHead) {
|
||||
options.position = { x: MyAvatar.position.x + 0.0,
|
||||
y: MyAvatar.position.y + 0.1,
|
||||
|
@ -329,7 +329,7 @@ function fireMissile() {
|
|||
lifetime: 5
|
||||
});
|
||||
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
if (soundInMyHead) {
|
||||
options.position = { x: MyAvatar.position.x + 0.0,
|
||||
y: MyAvatar.position.y + 0.1,
|
||||
|
@ -379,7 +379,7 @@ function deleteIfInvader(possibleInvaderParticle) {
|
|||
Particles.deleteParticle(myMissile);
|
||||
|
||||
// play the hit sound
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
if (soundInMyHead) {
|
||||
options.position = { x: MyAvatar.position.x + 0.0,
|
||||
y: MyAvatar.position.y + 0.1,
|
||||
|
@ -417,4 +417,3 @@ initializeInvaders();
|
|||
|
||||
// shut down the game after 1 minute
|
||||
var gameTimer = Script.setTimeout(endGame, itemLifetimes * 1000);
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ function checkControllerSide(whichSide) {
|
|||
velocity : { x: 0, y: 0, z: 0}, inHand: true };
|
||||
Particles.editParticle(closestParticle, properties);
|
||||
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = ballPosition;
|
||||
options.volume = 1.0;
|
||||
Audio.playSound(catchSound, options);
|
||||
|
@ -152,7 +152,7 @@ function checkControllerSide(whichSide) {
|
|||
}
|
||||
|
||||
// Play a new ball sound
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = ballPosition;
|
||||
options.volume = 1.0;
|
||||
Audio.playSound(catchSound, options);
|
||||
|
@ -201,7 +201,7 @@ function checkControllerSide(whichSide) {
|
|||
rightHandParticle = false;
|
||||
}
|
||||
|
||||
var options = new AudioInjectionOptions();
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = ballPosition;
|
||||
options.volume = 1.0;
|
||||
Audio.playSound(throwSound, options);
|
||||
|
|
|
@ -64,7 +64,7 @@ collisionBubble[1] = Overlays.addOverlay("sphere",
|
|||
visible: false
|
||||
});
|
||||
|
||||
var audioOptions = new AudioInjectionOptions();
|
||||
var audioOptions = new AudioInjectionOptions();
|
||||
audioOptions.position = { x: MyAvatar.position.x, y: MyAvatar.position.y + 1, z: MyAvatar.position.z };
|
||||
audioOptions.volume = 1;
|
||||
|
||||
|
|
|
@ -9,10 +9,6 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -134,7 +130,7 @@ QString& Application::resourcesPath() {
|
|||
return staticResourcePath;
|
||||
}
|
||||
|
||||
Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||
Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||
QApplication(argc, argv),
|
||||
_window(new QMainWindow(desktop())),
|
||||
_glWidget(new GLCanvas()),
|
||||
|
@ -507,7 +503,7 @@ void Application::initializeGL() {
|
|||
_idleLoopStdev.reset();
|
||||
|
||||
if (_justStarted) {
|
||||
float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0;
|
||||
float startupTime = (float)_applicationStartupTime.elapsed() / 1000.0;
|
||||
_justStarted = false;
|
||||
qDebug("Startup time: %4.2f seconds.", startupTime);
|
||||
const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";
|
||||
|
@ -1222,7 +1218,6 @@ void Application::touchEndEvent(QTouchEvent* event) {
|
|||
if (_controllerScriptingInterface.isTouchCaptured()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// put any application specific touch behavior below here..
|
||||
_touchDragStartedAvgX = _touchAvgX;
|
||||
_touchDragStartedAvgY = _touchAvgY;
|
||||
|
@ -1276,21 +1271,21 @@ void Application::sendPingPackets() {
|
|||
|
||||
// Every second, check the frame rates and other stuff
|
||||
void Application::timer() {
|
||||
gettimeofday(&_timerEnd, NULL);
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) {
|
||||
sendPingPackets();
|
||||
}
|
||||
|
||||
float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f;
|
||||
|
||||
_fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
|
||||
_fps = (float)_frameCount / diffTime;
|
||||
|
||||
_packetsPerSecond = (float) _datagramProcessor.getPacketCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
|
||||
_bytesPerSecond = (float) _datagramProcessor.getByteCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
|
||||
_packetsPerSecond = (float) _datagramProcessor.getPacketCount() / diffTime;
|
||||
_bytesPerSecond = (float) _datagramProcessor.getByteCount() / diffTime;
|
||||
_frameCount = 0;
|
||||
|
||||
_datagramProcessor.resetCounters();
|
||||
|
||||
gettimeofday(&_timerStart, NULL);
|
||||
_timerStart.start();
|
||||
|
||||
// ask the node list to check in with the domain server
|
||||
NodeList::getInstance()->sendDomainServerCheckIn();
|
||||
|
@ -1303,13 +1298,11 @@ void Application::idle() {
|
|||
bool showWarnings = getLogger()->extraDebugging();
|
||||
PerformanceWarning warn(showWarnings, "Application::idle()");
|
||||
|
||||
timeval check;
|
||||
gettimeofday(&check, NULL);
|
||||
|
||||
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran
|
||||
|
||||
double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
|
||||
double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0;
|
||||
if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {
|
||||
_lastTimeUpdated.start();
|
||||
{
|
||||
PerformanceWarning warn(showWarnings, "Application::idle()... update()");
|
||||
const float BIGGEST_DELTA_TIME_SECS = 0.25f;
|
||||
|
@ -1321,7 +1314,6 @@ void Application::idle() {
|
|||
}
|
||||
{
|
||||
PerformanceWarning warn(showWarnings, "Application::idle()... rest of it");
|
||||
_lastTimeUpdated = check;
|
||||
_idleLoopStdev.addValue(timeSinceLastUpdate);
|
||||
|
||||
// Record standard deviation and reset counter if needed
|
||||
|
@ -1637,8 +1629,8 @@ void Application::init() {
|
|||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
gettimeofday(&_timerStart, NULL);
|
||||
gettimeofday(&_lastTimeUpdated, NULL);
|
||||
_timerStart.start();
|
||||
_lastTimeUpdated.start();
|
||||
|
||||
Menu::getInstance()->loadSettings();
|
||||
if (Menu::getInstance()->getAudioJitterBufferSamples() != 0) {
|
||||
|
@ -2651,6 +2643,8 @@ void Application::displayOverlay() {
|
|||
audioMeterY,
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::Mirror));
|
||||
|
||||
_audio.renderScope(_glWidget->width(), _glWidget->height());
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
if (isClipping) {
|
||||
glColor3f(1, 0, 0);
|
||||
|
|
|
@ -117,7 +117,7 @@ public:
|
|||
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
|
||||
static QString& resourcesPath();
|
||||
|
||||
Application(int& argc, char** argv, timeval &startup_time);
|
||||
Application(int& argc, char** argv, QElapsedTimer &startup_time);
|
||||
~Application();
|
||||
|
||||
void restoreSizeAndPosition();
|
||||
|
@ -392,9 +392,9 @@ private:
|
|||
|
||||
int _frameCount;
|
||||
float _fps;
|
||||
timeval _applicationStartupTime;
|
||||
timeval _timerStart, _timerEnd;
|
||||
timeval _lastTimeUpdated;
|
||||
QElapsedTimer _applicationStartupTime;
|
||||
QElapsedTimer _timerStart;
|
||||
QElapsedTimer _lastTimeUpdated;
|
||||
bool _justStarted;
|
||||
Stars _stars;
|
||||
|
||||
|
|
|
@ -92,7 +92,14 @@ Audio::Audio(int16_t initialJitterBufferSamples, QObject* parent) :
|
|||
_processSpatialAudio(false),
|
||||
_spatialAudioStart(0),
|
||||
_spatialAudioFinish(0),
|
||||
_spatialAudioRingBuffer(NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL, true) // random access mode
|
||||
_spatialAudioRingBuffer(NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL, true), // random access mode
|
||||
_scopeEnabled(false),
|
||||
_scopeEnabledPause(false),
|
||||
_scopeInputOffset(0),
|
||||
_scopeOutputOffset(0),
|
||||
_scopeInput(SAMPLES_PER_SCOPE_WIDTH * sizeof(int16_t), 0),
|
||||
_scopeOutputLeft(SAMPLES_PER_SCOPE_WIDTH * sizeof(int16_t), 0),
|
||||
_scopeOutputRight(SAMPLES_PER_SCOPE_WIDTH * sizeof(int16_t), 0)
|
||||
{
|
||||
// clear the array of locally injected samples
|
||||
memset(_localProceduralSamples, 0, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL);
|
||||
|
@ -575,6 +582,14 @@ void Audio::handleAudioInput() {
|
|||
processProceduralAudio(monoAudioSamples, NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||
}
|
||||
|
||||
if (_scopeEnabled && !_scopeEnabledPause) {
|
||||
unsigned int numMonoAudioChannels = 1;
|
||||
unsigned int monoAudioChannel = 0;
|
||||
addBufferToScope(_scopeInput, _scopeInputOffset, monoAudioSamples, monoAudioChannel, numMonoAudioChannels);
|
||||
_scopeInputOffset += NETWORK_SAMPLES_PER_FRAME;
|
||||
_scopeInputOffset %= SAMPLES_PER_SCOPE_WIDTH;
|
||||
}
|
||||
|
||||
NodeList* nodeList = NodeList::getInstance();
|
||||
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||
|
||||
|
@ -628,13 +643,12 @@ void Audio::handleAudioInput() {
|
|||
void Audio::addReceivedAudioToBuffer(const QByteArray& audioByteArray) {
|
||||
const int NUM_INITIAL_PACKETS_DISCARD = 3;
|
||||
const int STANDARD_DEVIATION_SAMPLE_COUNT = 500;
|
||||
|
||||
timeval currentReceiveTime;
|
||||
gettimeofday(¤tReceiveTime, NULL);
|
||||
|
||||
_timeSinceLastRecieved.start();
|
||||
_totalPacketsReceived++;
|
||||
|
||||
double timeDiff = diffclock(&_lastReceiveTime, ¤tReceiveTime);
|
||||
|
||||
|
||||
double timeDiff = (double)_timeSinceLastRecieved.nsecsElapsed() / 1000000.0; // ns to ms
|
||||
|
||||
// Discard first few received packets for computing jitter (often they pile up on start)
|
||||
if (_totalPacketsReceived > NUM_INITIAL_PACKETS_DISCARD) {
|
||||
_stdev.addValue(timeDiff);
|
||||
|
@ -658,8 +672,6 @@ void Audio::addReceivedAudioToBuffer(const QByteArray& audioByteArray) {
|
|||
}
|
||||
|
||||
Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AUDIO).updateValue(audioByteArray.size());
|
||||
|
||||
_lastReceiveTime = currentReceiveTime;
|
||||
}
|
||||
|
||||
// NOTE: numSamples is the total number of single channel samples, since callers will always call this with stereo
|
||||
|
@ -813,6 +825,30 @@ void Audio::processReceivedAudio(const QByteArray& audioByteArray) {
|
|||
if (_outputDevice) {
|
||||
_outputDevice->write(outputBuffer);
|
||||
}
|
||||
|
||||
if (_scopeEnabled && !_scopeEnabledPause) {
|
||||
unsigned int numAudioChannels = _desiredOutputFormat.channelCount();
|
||||
int16_t* samples = ringBufferSamples;
|
||||
for (int numSamples = numNetworkOutputSamples / numAudioChannels; numSamples > 0; numSamples -= NETWORK_SAMPLES_PER_FRAME) {
|
||||
|
||||
unsigned int audioChannel = 0;
|
||||
addBufferToScope(
|
||||
_scopeOutputLeft,
|
||||
_scopeOutputOffset,
|
||||
samples, audioChannel, numAudioChannels);
|
||||
|
||||
audioChannel = 1;
|
||||
addBufferToScope(
|
||||
_scopeOutputRight,
|
||||
_scopeOutputOffset,
|
||||
samples, audioChannel, numAudioChannels);
|
||||
|
||||
_scopeOutputOffset += NETWORK_SAMPLES_PER_FRAME;
|
||||
_scopeOutputOffset %= SAMPLES_PER_SCOPE_WIDTH;
|
||||
samples += NETWORK_SAMPLES_PER_FRAME * numAudioChannels;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] ringBufferSamples;
|
||||
}
|
||||
}
|
||||
|
@ -1019,6 +1055,140 @@ void Audio::renderToolBox(int x, int y, bool boxed) {
|
|||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void Audio::toggleScopePause() {
|
||||
_scopeEnabledPause = !_scopeEnabledPause;
|
||||
}
|
||||
|
||||
void Audio::toggleScope() {
|
||||
_scopeEnabled = !_scopeEnabled;
|
||||
if (_scopeEnabled) {
|
||||
static const int width = SAMPLES_PER_SCOPE_WIDTH;
|
||||
_scopeInputOffset = 0;
|
||||
_scopeOutputOffset = 0;
|
||||
memset(_scopeInput.data(), 0, width * sizeof(int16_t));
|
||||
memset(_scopeOutputLeft.data(), 0, width * sizeof(int16_t));
|
||||
memset(_scopeOutputRight.data(), 0, width * sizeof(int16_t));
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::addBufferToScope(
|
||||
QByteArray& byteArray, unsigned int frameOffset, const int16_t* source, unsigned int sourceChannel, unsigned int sourceNumberOfChannels) {
|
||||
|
||||
// Constant multiplier to map sample value to vertical size of scope
|
||||
float multiplier = (float)MULTIPLIER_SCOPE_HEIGHT / logf(2.0f);
|
||||
|
||||
// Temporary variable receives sample value
|
||||
float sample;
|
||||
|
||||
// Temporary variable receives mapping of sample value
|
||||
int16_t value;
|
||||
|
||||
// Short int pointer to mapped samples in byte array
|
||||
int16_t* destination = (int16_t*) byteArray.data();
|
||||
|
||||
for (int i = 0; i < NETWORK_SAMPLES_PER_FRAME; i++) {
|
||||
|
||||
sample = (float)source[i * sourceNumberOfChannels + sourceChannel];
|
||||
|
||||
if (sample > 0) {
|
||||
value = (int16_t)(multiplier * logf(sample));
|
||||
} else if (sample < 0) {
|
||||
value = (int16_t)(-multiplier * logf(-sample));
|
||||
} else {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
destination[i + frameOffset] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::renderScope(int width, int height) {
|
||||
|
||||
if (!_scopeEnabled)
|
||||
return;
|
||||
|
||||
static const float backgroundColor[4] = { 0.2f, 0.2f, 0.2f, 0.6f };
|
||||
static const float gridColor[4] = { 0.3f, 0.3f, 0.3f, 0.6f };
|
||||
static const float inputColor[4] = { 0.3f, .7f, 0.3f, 0.6f };
|
||||
static const float outputLeftColor[4] = { 0.7f, .3f, 0.3f, 0.6f };
|
||||
static const float outputRightColor[4] = { 0.3f, .3f, 0.7f, 0.6f };
|
||||
static const int gridRows = 2;
|
||||
static const int gridCols = 5;
|
||||
|
||||
int x = (width - SAMPLES_PER_SCOPE_WIDTH) / 2;
|
||||
int y = (height - SAMPLES_PER_SCOPE_HEIGHT) / 2;
|
||||
int w = SAMPLES_PER_SCOPE_WIDTH;
|
||||
int h = SAMPLES_PER_SCOPE_HEIGHT;
|
||||
|
||||
renderBackground(backgroundColor, x, y, w, h);
|
||||
renderGrid(gridColor, x, y, w, h, gridRows, gridCols);
|
||||
renderLineStrip(inputColor, x, y, w, _scopeInputOffset, _scopeInput);
|
||||
renderLineStrip(outputLeftColor, x, y, w, _scopeOutputOffset, _scopeOutputLeft);
|
||||
renderLineStrip(outputRightColor, x, y, w, _scopeOutputOffset, _scopeOutputRight);
|
||||
}
|
||||
|
||||
void Audio::renderBackground(const float* color, int x, int y, int width, int height) {
|
||||
|
||||
glColor4fv(color);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glVertex2i(x, y);
|
||||
glVertex2i(x + width, y);
|
||||
glVertex2i(x + width, y + height);
|
||||
glVertex2i(x , y + height);
|
||||
|
||||
glEnd();
|
||||
glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
void Audio::renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols) {
|
||||
|
||||
glColor4fv(color);
|
||||
glBegin(GL_LINES);
|
||||
|
||||
int dx = width / cols;
|
||||
int dy = height / rows;
|
||||
int tx = x;
|
||||
int ty = y;
|
||||
|
||||
// Draw horizontal grid lines
|
||||
for (int i = rows + 1; --i >= 0; ) {
|
||||
glVertex2i(x, ty);
|
||||
glVertex2i(x + width, ty);
|
||||
ty += dy;
|
||||
}
|
||||
// Draw vertical grid lines
|
||||
for (int i = cols + 1; --i >= 0; ) {
|
||||
glVertex2i(tx, y);
|
||||
glVertex2i(tx, y + height);
|
||||
tx += dx;
|
||||
}
|
||||
glEnd();
|
||||
glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, const QByteArray& byteArray) {
|
||||
|
||||
glColor4fv(color);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
|
||||
int16_t sample;
|
||||
int16_t* samples = ((int16_t*) byteArray.data()) + offset;
|
||||
y += SAMPLES_PER_SCOPE_HEIGHT / 2;
|
||||
for (int i = n - offset; --i >= 0; ) {
|
||||
sample = *samples++;
|
||||
glVertex2i(x++, y - sample);
|
||||
}
|
||||
samples = (int16_t*) byteArray.data();
|
||||
for (int i = offset; --i >= 0; ) {
|
||||
sample = *samples++;
|
||||
glVertex2i(x++, y - sample);
|
||||
}
|
||||
glEnd();
|
||||
glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
bool Audio::switchInputToAudioDevice(const QAudioDeviceInfo& inputDeviceInfo) {
|
||||
bool supportedFormat = false;
|
||||
|
||||
|
@ -1098,13 +1268,13 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
|
|||
// setup a procedural audio output device
|
||||
_proceduralAudioOutput = new QAudioOutput(outputDeviceInfo, _outputFormat, this);
|
||||
|
||||
gettimeofday(&_lastReceiveTime, NULL);
|
||||
_timeSinceLastRecieved.start();
|
||||
|
||||
// setup spatial audio ringbuffer
|
||||
int numFrameSamples = _outputFormat.sampleRate() * _desiredOutputFormat.channelCount();
|
||||
_spatialAudioRingBuffer.resizeForFrameSize(numFrameSamples);
|
||||
_spatialAudioStart = _spatialAudioFinish = 0;
|
||||
|
||||
|
||||
supportedFormat = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,6 @@
|
|||
#ifndef hifi_Audio_h
|
||||
#define hifi_Audio_h
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
|
@ -23,11 +19,13 @@
|
|||
|
||||
#include <QAudio>
|
||||
#include <QAudioInput>
|
||||
#include <QElapsedTimer>
|
||||
#include <QGLWidget>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtMultimedia/QAudioFormat>
|
||||
#include <QVector>
|
||||
#include <QByteArray>
|
||||
|
||||
#include <AbstractAudioInterface.h>
|
||||
#include <AudioRingBuffer.h>
|
||||
|
@ -67,6 +65,7 @@ public:
|
|||
bool mousePressEvent(int x, int y);
|
||||
|
||||
void renderToolBox(int x, int y, bool boxed);
|
||||
void renderScope(int width, int height);
|
||||
|
||||
int getNetworkSampleRate() { return SAMPLE_RATE; }
|
||||
int getNetworkBufferLengthSamplesPerChannel() { return NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; }
|
||||
|
@ -83,6 +82,8 @@ public slots:
|
|||
void toggleMute();
|
||||
void toggleAudioNoiseReduction();
|
||||
void toggleToneInjection();
|
||||
void toggleScope();
|
||||
void toggleScopePause();
|
||||
void toggleAudioSpatialProcessing();
|
||||
|
||||
virtual void handleAudioByteArray(const QByteArray& audioByteArray);
|
||||
|
@ -128,7 +129,7 @@ private:
|
|||
QString _outputAudioDeviceName;
|
||||
|
||||
StDev _stdev;
|
||||
timeval _lastReceiveTime;
|
||||
QElapsedTimer _timeSinceLastRecieved;
|
||||
float _averagedLatency;
|
||||
float _measuredJitter;
|
||||
int16_t _jitterBufferSamples;
|
||||
|
@ -196,6 +197,29 @@ private:
|
|||
int calculateNumberOfFrameSamples(int numBytes);
|
||||
float calculateDeviceToNetworkInputRatio(int numBytes);
|
||||
|
||||
// Audio scope methods for data acquisition
|
||||
void addBufferToScope(
|
||||
QByteArray& byteArray, unsigned int frameOffset, const int16_t* source, unsigned int sourceChannel, unsigned int sourceNumberOfChannels);
|
||||
|
||||
// Audio scope methods for rendering
|
||||
void renderBackground(const float* color, int x, int y, int width, int height);
|
||||
void renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols);
|
||||
void renderLineStrip(const float* color, int x, int y, int n, int offset, const QByteArray& byteArray);
|
||||
|
||||
// Audio scope data
|
||||
static const unsigned int NETWORK_SAMPLES_PER_FRAME = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
|
||||
static const unsigned int FRAMES_PER_SCOPE = 5;
|
||||
static const unsigned int SAMPLES_PER_SCOPE_WIDTH = FRAMES_PER_SCOPE * NETWORK_SAMPLES_PER_FRAME;
|
||||
static const unsigned int MULTIPLIER_SCOPE_HEIGHT = 20;
|
||||
static const unsigned int SAMPLES_PER_SCOPE_HEIGHT = 2 * 15 * MULTIPLIER_SCOPE_HEIGHT;
|
||||
bool _scopeEnabled;
|
||||
bool _scopeEnabledPause;
|
||||
int _scopeInputOffset;
|
||||
int _scopeOutputOffset;
|
||||
QByteArray _scopeInput;
|
||||
QByteArray _scopeOutputLeft;
|
||||
QByteArray _scopeOutputRight;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -260,6 +260,9 @@ Menu::Menu() :
|
|||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Bandwidth, 0, true);
|
||||
addActionToQMenuAndActionHash(viewMenu, MenuOption::BandwidthDetails, 0, this, SLOT(bandwidthDetails()));
|
||||
addActionToQMenuAndActionHash(viewMenu, MenuOption::OctreeStats, 0, this, SLOT(octreeStatsDetails()));
|
||||
addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::AudioScope, 0, false,
|
||||
appInstance->getAudio(),
|
||||
SLOT(toggleScope()));
|
||||
|
||||
QMenu* developerMenu = addMenu("Developer");
|
||||
|
||||
|
@ -386,6 +389,11 @@ Menu::Menu() :
|
|||
false,
|
||||
appInstance->getAudio(),
|
||||
SLOT(toggleToneInjection()));
|
||||
addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioScopePause,
|
||||
Qt::CTRL | Qt::Key_P,
|
||||
false,
|
||||
appInstance->getAudio(),
|
||||
SLOT(toggleScopePause()));
|
||||
|
||||
QMenu* spatialAudioMenu = audioDebugMenu->addMenu("Spatial Audio");
|
||||
|
||||
|
|
|
@ -259,8 +259,9 @@ namespace MenuOption {
|
|||
const QString AmbientOcclusion = "Ambient Occlusion";
|
||||
const QString Atmosphere = "Atmosphere";
|
||||
const QString AudioNoiseReduction = "Audio Noise Reduction";
|
||||
const QString AudioScope = "Audio Scope";
|
||||
const QString AudioScopePause = "Pause Audio Scope";
|
||||
const QString AudioToneInjection = "Inject Test Tone";
|
||||
|
||||
const QString AudioSpatialProcessing = "Audio Spatial Processing";
|
||||
const QString AudioSpatialProcessingHeadOriented = "Head Oriented";
|
||||
const QString AudioSpatialProcessingIncludeOriginal = "Includes Network Original";
|
||||
|
|
|
@ -172,14 +172,6 @@ void renderWorldBox() {
|
|||
|
||||
}
|
||||
|
||||
double diffclock(timeval *clock1,timeval *clock2)
|
||||
{
|
||||
double diffms = (clock2->tv_sec - clock1->tv_sec) * 1000.0;
|
||||
diffms += (clock2->tv_usec - clock1->tv_usec) / 1000.0; // us to ms
|
||||
|
||||
return diffms;
|
||||
}
|
||||
|
||||
// Return a random vector of average length 1
|
||||
const glm::vec3 randVector() {
|
||||
return glm::vec3(randFloat() - 0.5f, randFloat() - 0.5f, randFloat() - 0.5f) * 2.f;
|
||||
|
@ -411,69 +403,63 @@ void runTimingTests() {
|
|||
int iResults[numTests];
|
||||
float fTest = 1.0;
|
||||
float fResults[numTests];
|
||||
timeval startTime, endTime;
|
||||
float elapsedMsecs;
|
||||
gettimeofday(&startTime, NULL);
|
||||
for (int i = 1; i < numTests; i++) {
|
||||
gettimeofday(&endTime, NULL);
|
||||
}
|
||||
elapsedMsecs = diffclock(&startTime, &endTime);
|
||||
qDebug("gettimeofday() usecs: %f", 1000.0f * elapsedMsecs / (float) numTests);
|
||||
QElapsedTimer startTime;
|
||||
startTime.start();
|
||||
float elapsedUsecs;
|
||||
|
||||
float NSEC_TO_USEC = 1.0f / 1000.0f;
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("QElapsedTimer::nsecElapsed() usecs: %f", elapsedUsecs / (float) numTests);
|
||||
|
||||
// Random number generation
|
||||
gettimeofday(&startTime, NULL);
|
||||
startTime.start();
|
||||
for (int i = 1; i < numTests; i++) {
|
||||
iResults[i] = rand();
|
||||
}
|
||||
gettimeofday(&endTime, NULL);
|
||||
elapsedMsecs = diffclock(&startTime, &endTime);
|
||||
qDebug("rand() stored in array usecs: %f, first result:%d", 1000.0f * elapsedMsecs / (float) numTests, iResults[0]);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("rand() stored in array usecs: %f, first result:%d", elapsedUsecs / (float) numTests, iResults[0]);
|
||||
|
||||
// Random number generation using randFloat()
|
||||
gettimeofday(&startTime, NULL);
|
||||
startTime.start();
|
||||
for (int i = 1; i < numTests; i++) {
|
||||
fResults[i] = randFloat();
|
||||
}
|
||||
gettimeofday(&endTime, NULL);
|
||||
elapsedMsecs = diffclock(&startTime, &endTime);
|
||||
qDebug("randFloat() stored in array usecs: %f, first result: %f", 1000.0f * elapsedMsecs / (float) numTests, fResults[0]);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("randFloat() stored in array usecs: %f, first result: %f", elapsedUsecs / (float) numTests, fResults[0]);
|
||||
|
||||
// PowF function
|
||||
fTest = 1145323.2342f;
|
||||
gettimeofday(&startTime, NULL);
|
||||
startTime.start();
|
||||
for (int i = 1; i < numTests; i++) {
|
||||
fTest = powf(fTest, 0.5f);
|
||||
}
|
||||
gettimeofday(&endTime, NULL);
|
||||
elapsedMsecs = diffclock(&startTime, &endTime);
|
||||
qDebug("powf(f, 0.5) usecs: %f", 1000.0f * elapsedMsecs / (float) numTests);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("powf(f, 0.5) usecs: %f", elapsedUsecs / (float) numTests);
|
||||
|
||||
// Vector Math
|
||||
float distance;
|
||||
glm::vec3 pointA(randVector()), pointB(randVector());
|
||||
gettimeofday(&startTime, NULL);
|
||||
startTime.start();
|
||||
for (int i = 1; i < numTests; i++) {
|
||||
//glm::vec3 temp = pointA - pointB;
|
||||
//float distanceSquared = glm::dot(temp, temp);
|
||||
distance = glm::distance(pointA, pointB);
|
||||
}
|
||||
gettimeofday(&endTime, NULL);
|
||||
elapsedMsecs = diffclock(&startTime, &endTime);
|
||||
qDebug("vector math usecs: %f [%f msecs total for %d tests], last result:%f",
|
||||
1000.0f * elapsedMsecs / (float) numTests, elapsedMsecs, numTests, distance);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("vector math usecs: %f [%f usecs total for %d tests], last result:%f",
|
||||
elapsedUsecs / (float) numTests, elapsedUsecs, numTests, distance);
|
||||
|
||||
// Vec3 test
|
||||
glm::vec3 vecA(randVector()), vecB(randVector());
|
||||
float result;
|
||||
|
||||
gettimeofday(&startTime, NULL);
|
||||
|
||||
startTime.start();
|
||||
for (int i = 1; i < numTests; i++) {
|
||||
glm::vec3 temp = vecA-vecB;
|
||||
result = glm::dot(temp,temp);
|
||||
}
|
||||
gettimeofday(&endTime, NULL);
|
||||
elapsedMsecs = diffclock(&startTime, &endTime);
|
||||
qDebug("vec3 assign and dot() usecs: %f, last result:%f", 1000.0f * elapsedMsecs / (float) numTests, result);
|
||||
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
|
||||
qDebug("vec3 assign and dot() usecs: %f, last result:%f", elapsedUsecs / (float) numTests, result);
|
||||
}
|
||||
|
||||
float loadSetting(QSettings* settings, const char* name, float defaultValue) {
|
||||
|
|
|
@ -12,12 +12,6 @@
|
|||
#ifndef hifi_Util_h
|
||||
#define hifi_Util_h
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <QSettings>
|
||||
|
@ -44,8 +38,6 @@ void drawVector(glm::vec3* vector);
|
|||
|
||||
void printVector(glm::vec3 vec);
|
||||
|
||||
double diffclock(timeval *clock1,timeval *clock2);
|
||||
|
||||
void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0);
|
||||
|
||||
void renderOrientationDirections( glm::vec3 position, const glm::quat& orientation, float size );
|
||||
|
|
|
@ -11,10 +11,6 @@
|
|||
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
|
||||
#include <QOpenGLFramebufferObject>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#include "TV3DManager.h"
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
#include <SharedUtil.h>
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
timeval startup_time;
|
||||
gettimeofday(&startup_time, NULL);
|
||||
initialiseUsecTimestampNow();
|
||||
QElapsedTimer startupTime;
|
||||
startupTime.start();
|
||||
|
||||
// Debug option to demonstrate that the client's local time does not
|
||||
// need to be in sync with any other network node. This forces clock
|
||||
|
@ -33,7 +34,7 @@ int main(int argc, const char * argv[]) {
|
|||
int exitCode;
|
||||
{
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
Application app(argc, const_cast<char**>(argv), startup_time);
|
||||
Application app(argc, const_cast<char**>(argv), startupTime);
|
||||
|
||||
QTranslator translator;
|
||||
translator.load("interface_en");
|
||||
|
|
|
@ -9,24 +9,23 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "starfield/Controller.h"
|
||||
|
||||
using namespace starfield;
|
||||
|
||||
bool Controller::computeStars(unsigned numStars, unsigned seed) {
|
||||
timeval startTime;
|
||||
gettimeofday(&startTime, NULL);
|
||||
QElapsedTimer startTime;
|
||||
startTime.start();
|
||||
|
||||
Generator::computeStarPositions(_inputSequence, numStars, seed);
|
||||
|
||||
this->retile(numStars, _tileResolution);
|
||||
|
||||
qDebug() << "Total time to retile and generate stars: "
|
||||
<< ((usecTimestampNow() - usecTimestamp(&startTime)) / 1000) << "msec";
|
||||
double NSEC_TO_MSEC = 1.0 / 1000000.0;
|
||||
double timeDiff = (double)startTime.nsecsElapsed() * NSEC_TO_MSEC;
|
||||
qDebug() << "Total time to retile and generate stars: " << timeDiff << "msec";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "starfield/Generator.h"
|
||||
|
||||
|
@ -24,8 +22,8 @@ void Generator::computeStarPositions(InputVertices& destination, unsigned limit,
|
|||
InputVertices* vertices = & destination;
|
||||
//_limit = limit;
|
||||
|
||||
timeval startTime;
|
||||
gettimeofday(&startTime, NULL);
|
||||
QElapsedTimer startTime;
|
||||
startTime.start();
|
||||
|
||||
srand(seed);
|
||||
|
||||
|
@ -70,7 +68,8 @@ void Generator::computeStarPositions(InputVertices& destination, unsigned limit,
|
|||
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
|
||||
}
|
||||
|
||||
qDebug() << "Total time to generate stars: " << ((usecTimestampNow() - usecTimestamp(&startTime)) / 1000) << " msec";
|
||||
double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms
|
||||
qDebug() << "Total time to generate stars: " << timeDiff << " msec";
|
||||
}
|
||||
|
||||
// computeStarColor
|
||||
|
|
|
@ -62,26 +62,21 @@ BandwidthMeter::~BandwidthMeter() {
|
|||
free(_channels);
|
||||
}
|
||||
|
||||
BandwidthMeter::Stream::Stream(float msToAverage) :
|
||||
_value(0.0f),
|
||||
_msToAverage(msToAverage) {
|
||||
|
||||
gettimeofday(& _prevTime, NULL);
|
||||
BandwidthMeter::Stream::Stream(float msToAverage) : _value(0.0f), _msToAverage(msToAverage) {
|
||||
_prevTime.start();
|
||||
}
|
||||
|
||||
void BandwidthMeter::Stream::updateValue(double amount) {
|
||||
|
||||
// Determine elapsed time
|
||||
timeval now;
|
||||
gettimeofday(& now, NULL);
|
||||
double dt = diffclock(& _prevTime, & now);
|
||||
double dt = (double)_prevTime.nsecsElapsed() / 1000000.0; // ns to ms
|
||||
|
||||
// Ignore this value when timer imprecision yields dt = 0
|
||||
if (dt == 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(& _prevTime, & now, sizeof(timeval));
|
||||
_prevTime.start();
|
||||
|
||||
// Compute approximate average
|
||||
_value = glm::mix(_value, amount / dt,
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
#ifndef hifi_BandwidthMeter_h
|
||||
#define hifi_BandwidthMeter_h
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Systime.h>
|
||||
#endif
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
|
@ -59,7 +57,7 @@ public:
|
|||
private:
|
||||
double _value; // Current value.
|
||||
double _msToAverage; // Milliseconds to average.
|
||||
timeval _prevTime; // Time of last feed.
|
||||
QElapsedTimer _prevTime; // Time of last feed.
|
||||
};
|
||||
|
||||
// Data model accessors
|
||||
|
|
|
@ -106,7 +106,7 @@ private:
|
|||
/// Copy constructor prohibited.
|
||||
///
|
||||
Primitive(
|
||||
const Primitive& prim
|
||||
const Primitive& copy
|
||||
);
|
||||
|
||||
// SPI methods are defined here
|
||||
|
@ -153,14 +153,14 @@ public:
|
|||
/// Configuration dependency injection constructor.
|
||||
///
|
||||
Cube(
|
||||
float x,
|
||||
float y,
|
||||
float z,
|
||||
float s,
|
||||
unsigned char r,
|
||||
unsigned char g,
|
||||
unsigned char b,
|
||||
unsigned char faces
|
||||
float x, ///< Cube location on X-axis
|
||||
float y, ///< Cube location on Y-axis
|
||||
float z, ///< Cube location on Z-axis
|
||||
float s, ///< Cube size
|
||||
unsigned char r, ///< Cube red color component
|
||||
unsigned char g, ///< Cube green color component
|
||||
unsigned char b, ///< Cube blue color component
|
||||
unsigned char faces ///< Bitmask of faces of cube excluded from construction
|
||||
);
|
||||
|
||||
~Cube();
|
||||
|
@ -172,36 +172,48 @@ private:
|
|||
const Cube& cube
|
||||
);
|
||||
|
||||
/// Cube initialization
|
||||
///
|
||||
void init(
|
||||
float x,
|
||||
float y,
|
||||
float z,
|
||||
float s,
|
||||
unsigned char r,
|
||||
unsigned char g,
|
||||
unsigned char b,
|
||||
unsigned char faceExclusions
|
||||
float x, ///< Cube location on X-axis
|
||||
float y, ///< Cube location on Y-axis
|
||||
float z, ///< Cube location on Z-axis
|
||||
float s, ///< Cube size
|
||||
unsigned char r, ///< Cube red color component
|
||||
unsigned char g, ///< Cube green color component
|
||||
unsigned char b, ///< Cube blue color component
|
||||
unsigned char faceExclusions ///< Bitmask of faces of cube excluded from construction
|
||||
);
|
||||
|
||||
/// Cube termination
|
||||
///
|
||||
void terminate();
|
||||
|
||||
/// Initialize cube's vertex list
|
||||
///
|
||||
void initializeVertices(
|
||||
float x,
|
||||
float y,
|
||||
float z,
|
||||
float s,
|
||||
unsigned char r,
|
||||
unsigned char g,
|
||||
unsigned char b,
|
||||
unsigned char faceExclusions
|
||||
float x, ///< Cube location on X-axis
|
||||
float y, ///< Cube location on Y-axis
|
||||
float z, ///< Cube location on Z-axis
|
||||
float s, ///< Cube size
|
||||
unsigned char r, ///< Cube red color component
|
||||
unsigned char g, ///< Cube green color component
|
||||
unsigned char b, ///< Cube blue color component
|
||||
unsigned char faceExclusions ///< Bitmask of faces of cube excluded from construction
|
||||
);
|
||||
|
||||
/// Terminate cube's vertex list
|
||||
///
|
||||
void terminateVertices();
|
||||
|
||||
/// Initialize cube's triangle list
|
||||
///
|
||||
void initializeTris(
|
||||
unsigned char faceExclusions
|
||||
);
|
||||
|
||||
/// Terminate cube's triangle list
|
||||
///
|
||||
void terminateTris();
|
||||
|
||||
// SPI virtual override methods go here
|
||||
|
@ -219,11 +231,11 @@ private:
|
|||
|
||||
unsigned long _cpuMemoryUsage; ///< Memory allocation of object
|
||||
|
||||
static const int _sNumFacesPerCube = 6;
|
||||
static const int _sNumVerticesPerCube = 24;
|
||||
static unsigned char _sFaceIndexToHalfSpaceMask[6];
|
||||
static float _sVertexIndexToConstructionVector[24][3];
|
||||
static float _sVertexIndexToNormalVector[6][3];
|
||||
static const int _sNumFacesPerCube = 6; ///< Number of faces per cube
|
||||
static const int _sNumVerticesPerCube = 24; ///< Number of vertices per cube
|
||||
static unsigned char _sFaceIndexToHalfSpaceMask[6]; ///< index to bitmask map
|
||||
static float _sVertexIndexToConstructionVector[24][3]; ///< Vertex index to construction vector map
|
||||
static float _sVertexIndexToNormalVector[6][3]; ///< Vertex index to normal vector map
|
||||
|
||||
};
|
||||
|
||||
|
@ -242,13 +254,13 @@ public:
|
|||
/// Add primitive to renderer database.
|
||||
///
|
||||
int add(
|
||||
Primitive* primitive ///< Pointer to primitive
|
||||
Primitive* primitive ///< Primitive instance to be added
|
||||
);
|
||||
|
||||
/// Remove primitive from renderer database.
|
||||
///
|
||||
void remove(
|
||||
int id ///< Primitive id
|
||||
int id ///< Primitive id to be removed
|
||||
);
|
||||
|
||||
/// Clear all primitives from renderer database
|
||||
|
@ -278,7 +290,7 @@ private:
|
|||
/// Copy constructor prohibited.
|
||||
///
|
||||
Renderer(
|
||||
const Renderer& primitive
|
||||
const Renderer& copy
|
||||
);
|
||||
|
||||
// SPI methods are defined here
|
||||
|
@ -286,10 +298,10 @@ private:
|
|||
/// Add primitive to renderer database.
|
||||
/// Service implementer to provide private override for this method
|
||||
/// in derived class
|
||||
/// @return primitive id
|
||||
/// @return Primitive id
|
||||
///
|
||||
virtual int vAdd(
|
||||
Primitive* primitive ///< Pointer to primitive
|
||||
Primitive* primitive ///< Primitive instance to be added
|
||||
) = 0;
|
||||
|
||||
/// Remove primitive from renderer database.
|
||||
|
@ -297,7 +309,7 @@ private:
|
|||
/// in derived class
|
||||
///
|
||||
virtual void vRemove(
|
||||
int id ///< Primitive id
|
||||
int id ///< Primitive id
|
||||
) = 0;
|
||||
|
||||
/// Clear all primitives from renderer database
|
||||
|
@ -332,7 +344,7 @@ public:
|
|||
/// Configuration dependency injection constructor.
|
||||
///
|
||||
PrimitiveRenderer(
|
||||
int maxCount
|
||||
int maxCount ///< Max count
|
||||
);
|
||||
|
||||
~PrimitiveRenderer();
|
||||
|
@ -365,39 +377,39 @@ private:
|
|||
/// Construct the elements of the faces of the primitive.
|
||||
///
|
||||
void constructElements(
|
||||
Primitive* primitive
|
||||
Primitive* primitive ///< Primitive instance
|
||||
);
|
||||
|
||||
/// Deconstruct the elements of the faces of the primitive.
|
||||
///
|
||||
void deconstructElements(
|
||||
Primitive* primitive
|
||||
Primitive* primitive ///< Primitive instance
|
||||
);
|
||||
|
||||
/// Deconstruct the triangle element from the GL buffer.
|
||||
///
|
||||
void deconstructTriElement(
|
||||
int idx
|
||||
int idx ///< Triangle element index
|
||||
);
|
||||
|
||||
/// Deconstruct the vertex element from the GL buffer.
|
||||
///
|
||||
void deconstructVertexElement(
|
||||
int idx
|
||||
int idx ///< Vertex element index
|
||||
);
|
||||
|
||||
/// Transfer the vertex element to the GL buffer.
|
||||
///
|
||||
void transferVertexElement(
|
||||
int idx,
|
||||
VertexElement *vertex
|
||||
int idx, ///< Vertex element index
|
||||
VertexElement *vertex ///< Vertex element instance
|
||||
);
|
||||
|
||||
/// Transfer the triangle element to the GL buffer.
|
||||
///
|
||||
void transferTriElement(
|
||||
int idx,
|
||||
int tri[3]
|
||||
int idx, ///< Triangle element index
|
||||
int tri[3] ///< Triangle element data
|
||||
);
|
||||
|
||||
/// Get available primitive index.
|
||||
|
@ -424,13 +436,13 @@ private:
|
|||
/// Add primitive to renderer database.
|
||||
///
|
||||
int vAdd(
|
||||
Primitive* primitive
|
||||
Primitive* primitive ///< Primitive instance to be added
|
||||
);
|
||||
|
||||
/// Remove primitive from renderer database.
|
||||
///
|
||||
void vRemove(
|
||||
int id
|
||||
int id ///< Primitive id to be removed
|
||||
);
|
||||
|
||||
/// Clear all primitives from renderer database
|
||||
|
@ -451,7 +463,7 @@ private:
|
|||
|
||||
private:
|
||||
|
||||
int _maxCount;
|
||||
int _maxCount; ///< Maximum count of tris
|
||||
|
||||
// GL related parameters
|
||||
|
||||
|
@ -479,8 +491,8 @@ private:
|
|||
|
||||
// Statistics parameters, not necessary for proper operation
|
||||
|
||||
unsigned long _gpuMemoryUsage;
|
||||
unsigned long _cpuMemoryUsage;
|
||||
unsigned long _gpuMemoryUsage; ///< GPU memory used by this instance
|
||||
unsigned long _cpuMemoryUsage; ///< CPU memory used by this instance
|
||||
|
||||
|
||||
static const int _sIndicesPerTri = 3;
|
||||
|
|
|
@ -1695,11 +1695,12 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element,
|
|||
|
||||
//qDebug("Completely occupied voxel at %f %f %f size: %f", v.x, v.y, v.z, s);
|
||||
|
||||
// TODO: All of the exterior faces of this voxel element are
|
||||
// occluders, which means that this element is completely
|
||||
// occupied. Hence, the subtree from this node could be
|
||||
// pruned and replaced by a leaf voxel, if the visible
|
||||
// properties of the children are the same
|
||||
// All of the exterior faces of this voxel element are
|
||||
// occluders, which means that this element is completely
|
||||
// occupied. Hence, the subtree from this node could be
|
||||
// pruned and replaced by a leaf voxel, if the visible
|
||||
// properties of the children are the same
|
||||
|
||||
} else if (exteriorOcclusions != OctreeElement::HalfSpace::None) {
|
||||
//const glm::vec3& v = voxel->getCorner();
|
||||
//float s = voxel->getScale();
|
||||
|
|
|
@ -71,8 +71,8 @@ void AudioInjector::injectAudio() {
|
|||
quint8 volume = MAX_INJECTOR_VOLUME * _options.getVolume();
|
||||
packetStream << volume;
|
||||
|
||||
timeval startTime = {};
|
||||
gettimeofday(&startTime, NULL);
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
int nextFrame = 0;
|
||||
|
||||
int currentSendPosition = 0;
|
||||
|
@ -104,7 +104,7 @@ void AudioInjector::injectAudio() {
|
|||
if (currentSendPosition != bytesToCopy && currentSendPosition < soundByteArray.size()) {
|
||||
// not the first packet and not done
|
||||
// sleep for the appropriate time
|
||||
int usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
|
||||
int usecToSleep = (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - timer.nsecsElapsed() / 1000;
|
||||
|
||||
if (usecToSleep > 0) {
|
||||
usleep(usecToSleep);
|
||||
|
|
|
@ -12,12 +12,6 @@
|
|||
#ifndef hifi_Assignment_h
|
||||
#define hifi_Assignment_h
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
#include "NodeList.h"
|
||||
|
|
|
@ -286,8 +286,8 @@ void ScriptEngine::run() {
|
|||
emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString());
|
||||
}
|
||||
|
||||
timeval startTime;
|
||||
gettimeofday(&startTime, NULL);
|
||||
QElapsedTimer startTime;
|
||||
startTime.start();
|
||||
|
||||
int thisFrame = 0;
|
||||
|
||||
|
@ -296,7 +296,7 @@ void ScriptEngine::run() {
|
|||
qint64 lastUpdate = usecTimestampNow();
|
||||
|
||||
while (!_isFinished) {
|
||||
int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - usecTimestampNow();
|
||||
int usecToSleep = (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - startTime.nsecsElapsed() / 1000; // nsec to usec
|
||||
if (usecToSleep > 0) {
|
||||
usleep(usecToSleep);
|
||||
}
|
||||
|
@ -561,4 +561,4 @@ void ScriptEngine::include(const QString& includeFile) {
|
|||
qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString();
|
||||
emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,6 @@
|
|||
#include <stdint.h>
|
||||
#include "SharedUtil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
|
|
@ -15,28 +15,44 @@
|
|||
#include <cctype>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QDateTime>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "OctalCode.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
quint64 usecTimestamp(const timeval *time) {
|
||||
return (time->tv_sec * 1000000 + time->tv_usec);
|
||||
|
||||
static qint64 TIME_REFERENCE = 0; // in usec
|
||||
static QElapsedTimer timestampTimer;
|
||||
static int usecTimestampNowAdjust = 0; // in usec
|
||||
|
||||
void initialiseUsecTimestampNow() {
|
||||
static bool initialised = false;
|
||||
if (initialised) {
|
||||
qDebug() << "[WARNING] Double initialisation of usecTimestampNow().";
|
||||
return;
|
||||
}
|
||||
|
||||
TIME_REFERENCE = QDateTime::currentMSecsSinceEpoch() * 1000; // ms to usec
|
||||
initialised = true;
|
||||
}
|
||||
|
||||
int usecTimestampNowAdjust = 0;
|
||||
void usecTimestampNowForceClockSkew(int clockSkew) {
|
||||
::usecTimestampNowAdjust = clockSkew;
|
||||
}
|
||||
|
||||
quint64 usecTimestampNow() {
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
return (now.tv_sec * 1000000 + now.tv_usec) + ::usecTimestampNowAdjust;
|
||||
// usec nsec to usec usec
|
||||
return TIME_REFERENCE + timestampTimer.nsecsElapsed() / 1000 + ::usecTimestampNowAdjust;
|
||||
}
|
||||
|
||||
float randFloat() {
|
||||
|
|
|
@ -24,12 +24,6 @@
|
|||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Systime.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
const int BYTES_PER_COLOR = 3;
|
||||
const int BYTES_PER_FLAGS = 1;
|
||||
typedef unsigned char rgbColor[BYTES_PER_COLOR];
|
||||
|
@ -66,7 +60,7 @@ static const quint64 USECS_PER_SECOND = USECS_PER_MSEC * MSECS_PER_SECOND;
|
|||
|
||||
const int BITS_IN_BYTE = 8;
|
||||
|
||||
quint64 usecTimestamp(const timeval *time);
|
||||
void initialiseUsecTimestampNow();
|
||||
quint64 usecTimestampNow();
|
||||
void usecTimestampNowForceClockSkew(int clockSkew);
|
||||
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
//
|
||||
// Systime.cpp
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "Systime.h"
|
||||
|
||||
/**
|
||||
* gettimeofday
|
||||
* Implementation according to:
|
||||
* The Open Group Base Specifications Issue 6
|
||||
* IEEE Std 1003.1, 2004 Edition
|
||||
*/
|
||||
|
||||
/**
|
||||
* THIS SOFTWARE IS NOT COPYRIGHTED
|
||||
*
|
||||
* This source code is offered for use in the public domain. You may
|
||||
* use, modify or distribute it freely.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful but
|
||||
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
||||
* DISCLAIMED. This includes but is not limited to warranties of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Contributed by:
|
||||
* Danny Smith <dannysmith@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
/** Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
|
||||
#define _W32_FT_OFFSET (116444736000000000ULL)
|
||||
|
||||
int gettimeofday(timeval* p_tv, timezone* p_tz) {
|
||||
|
||||
union {
|
||||
unsigned long long ns100; /**time since 1 Jan 1601 in 100ns units */
|
||||
FILETIME ft;
|
||||
} _now;
|
||||
|
||||
if (p_tv) {
|
||||
GetSystemTimeAsFileTime (&_now.ft);
|
||||
p_tv->tv_usec=(long)((_now.ns100 / 10ULL) % 1000000ULL );
|
||||
p_tv->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000ULL);
|
||||
}
|
||||
|
||||
/** Always return 0 as per Open Group Base Specifications Issue 6.
|
||||
Do not set errno on error. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,27 +0,0 @@
|
|||
//
|
||||
// Systime.h
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Systime_h
|
||||
#define hifi_Systime_h
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <winsock2.h>
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval* p_tv, struct timezone* p_tz);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // hifi_Systime_h
|
Loading…
Reference in a new issue