mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into red
This commit is contained in:
commit
4ef7fc61f0
8 changed files with 84 additions and 89 deletions
|
@ -154,9 +154,12 @@ MyAvatar::MyAvatar(RigPointer rig) :
|
|||
if (recordingInterface->getPlayFromCurrentLocation()) {
|
||||
setRecordingBasis();
|
||||
}
|
||||
_wasCharacterControllerEnabled = _characterController.isEnabled();
|
||||
_characterController.setEnabled(false);
|
||||
} else {
|
||||
clearRecordingBasis();
|
||||
useFullAvatarURL(_fullAvatarURLFromPreferences, _fullAvatarModelName);
|
||||
_characterController.setEnabled(_wasCharacterControllerEnabled);
|
||||
}
|
||||
|
||||
auto audioIO = DependencyManager::get<AudioClient>();
|
||||
|
|
|
@ -411,6 +411,7 @@ private:
|
|||
SharedSoundPointer _collisionSound;
|
||||
|
||||
MyCharacterController _characterController;
|
||||
bool _wasCharacterControllerEnabled { true };
|
||||
|
||||
AvatarWeakPointer _lookAtTargetAvatar;
|
||||
glm::vec3 _targetAvatarPosition;
|
||||
|
|
|
@ -45,13 +45,13 @@
|
|||
#include <AudioReverb.h>
|
||||
#include <AudioLimiter.h>
|
||||
#include <AudioConstants.h>
|
||||
#include <AudioNoiseGate.h>
|
||||
|
||||
#include <shared/RateCounter.h>
|
||||
|
||||
#include <plugins/CodecPlugin.h>
|
||||
|
||||
#include "AudioIOStats.h"
|
||||
#include "AudioNoiseGate.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning( push )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// AudioNoiseGate.cpp
|
||||
// interface/src/audio
|
||||
// libraries/audio
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-12-16.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
|
@ -9,29 +9,23 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "AudioNoiseGate.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string.h>
|
||||
|
||||
#include <AudioConstants.h>
|
||||
|
||||
#include "AudioNoiseGate.h"
|
||||
#include "AudioConstants.h"
|
||||
|
||||
const float AudioNoiseGate::CLIPPING_THRESHOLD = 0.90f;
|
||||
|
||||
AudioNoiseGate::AudioNoiseGate() :
|
||||
_inputBlockCounter(0),
|
||||
_lastLoudness(0.0f),
|
||||
_quietestBlock(std::numeric_limits<float>::max()),
|
||||
_loudestBlock(0.0f),
|
||||
_didClipInLastBlock(false),
|
||||
_dcOffset(0.0f),
|
||||
_measuredFloor(0.0f),
|
||||
_sampleCounter(0),
|
||||
_isOpen(false),
|
||||
_blocksToClose(0)
|
||||
{
|
||||
|
||||
}
|
||||
_blocksToClose(0) {}
|
||||
|
||||
void AudioNoiseGate::removeDCOffset(int16_t* samples, int numSamples) {
|
||||
//
|
||||
|
@ -80,7 +74,7 @@ void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
|||
float loudness = 0;
|
||||
int thisSample = 0;
|
||||
int samplesOverNoiseGate = 0;
|
||||
|
||||
|
||||
const float NOISE_GATE_HEIGHT = 7.0f;
|
||||
const int NOISE_GATE_WIDTH = 5;
|
||||
const int NOISE_GATE_CLOSE_BLOCK_DELAY = 5;
|
||||
|
@ -88,36 +82,22 @@ void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
|||
|
||||
// Check clipping, and check if should open noise gate
|
||||
_didClipInLastBlock = false;
|
||||
|
||||
|
||||
for (int i = 0; i < numSamples; i++) {
|
||||
thisSample = std::abs(samples[i]);
|
||||
if (thisSample >= ((float) AudioConstants::MAX_SAMPLE_VALUE * CLIPPING_THRESHOLD)) {
|
||||
_didClipInLastBlock = true;
|
||||
}
|
||||
|
||||
|
||||
loudness += thisSample;
|
||||
// Noise Reduction: Count peaks above the average loudness
|
||||
if (thisSample > (_measuredFloor * NOISE_GATE_HEIGHT)) {
|
||||
samplesOverNoiseGate++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_lastLoudness = fabs(loudness / numSamples);
|
||||
|
||||
if (_quietestBlock > _lastLoudness) {
|
||||
_quietestBlock = _lastLoudness;
|
||||
}
|
||||
if (_loudestBlock < _lastLoudness) {
|
||||
_loudestBlock = _lastLoudness;
|
||||
}
|
||||
|
||||
const int FRAMES_FOR_NOISE_DETECTION = 400;
|
||||
if (_inputBlockCounter++ > FRAMES_FOR_NOISE_DETECTION) {
|
||||
_quietestBlock = std::numeric_limits<float>::max();
|
||||
_loudestBlock = 0.0f;
|
||||
_inputBlockCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
// If Noise Gate is enabled, check and turn the gate on and off
|
||||
float averageOfAllSampleBlocks = 0.0f;
|
||||
_sampleBlocks[_sampleCounter++] = _lastLoudness;
|
||||
|
@ -130,7 +110,7 @@ void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
|||
averageOfAllSampleBlocks += _sampleBlocks[j];
|
||||
}
|
||||
thisAverage /= NOISE_GATE_BLOCKS_TO_AVERAGE;
|
||||
|
||||
|
||||
if (thisAverage < smallestSample) {
|
||||
smallestSample = thisAverage;
|
||||
}
|
||||
|
@ -138,7 +118,7 @@ void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
|||
averageOfAllSampleBlocks /= NUMBER_OF_NOISE_SAMPLE_BLOCKS;
|
||||
_measuredFloor = smallestSample;
|
||||
_sampleCounter = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
_closedInLastBlock = false;
|
||||
|
@ -156,7 +136,7 @@ void AudioNoiseGate::gateSamples(int16_t* samples, int numSamples) {
|
|||
}
|
||||
if (!_isOpen) {
|
||||
// First block after being closed gets faded to silence, we fade across
|
||||
// the entire block on fading out. All subsequent blocks are muted by being slammed
|
||||
// the entire block on fading out. All subsequent blocks are muted by being slammed
|
||||
// to zeros
|
||||
if (_closedInLastBlock) {
|
||||
float fadeSlope = (1.0f / numSamples);
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// AudioNoiseGate.h
|
||||
// interface/src/audio
|
||||
// libraries/audio
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-12-16.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
|
@ -19,24 +19,21 @@ const int NUMBER_OF_NOISE_SAMPLE_BLOCKS = 300;
|
|||
class AudioNoiseGate {
|
||||
public:
|
||||
AudioNoiseGate();
|
||||
|
||||
|
||||
void gateSamples(int16_t* samples, int numSamples);
|
||||
void removeDCOffset(int16_t* samples, int numSamples);
|
||||
|
||||
|
||||
bool clippedInLastBlock() const { return _didClipInLastBlock; }
|
||||
bool closedInLastBlock() const { return _closedInLastBlock; }
|
||||
bool openedInLastBlock() const { return _openedInLastBlock; }
|
||||
bool isOpen() const { return _isOpen; }
|
||||
float getMeasuredFloor() const { return _measuredFloor; }
|
||||
float getLastLoudness() const { return _lastLoudness; }
|
||||
|
||||
|
||||
static const float CLIPPING_THRESHOLD;
|
||||
|
||||
|
||||
private:
|
||||
int _inputBlockCounter;
|
||||
float _lastLoudness;
|
||||
float _quietestBlock;
|
||||
float _loudestBlock;
|
||||
bool _didClipInLastBlock;
|
||||
float _dcOffset;
|
||||
float _measuredFloor;
|
||||
|
@ -48,4 +45,4 @@ private:
|
|||
int _blocksToClose;
|
||||
};
|
||||
|
||||
#endif // hifi_AudioNoiseGate_h
|
||||
#endif // hifi_AudioNoiseGate_h
|
|
@ -33,6 +33,7 @@ void Deck::queueClip(ClipPointer clip, float timeOffset) {
|
|||
|
||||
// FIXME disabling multiple clips for now
|
||||
_clips.clear();
|
||||
_length = 0.0f;
|
||||
|
||||
// if the time offset is not zero, wrap in an OffsetClip
|
||||
if (timeOffset != 0.0f) {
|
||||
|
@ -153,8 +154,8 @@ void Deck::processFrames() {
|
|||
// if doing relative movement
|
||||
emit looped();
|
||||
} else {
|
||||
// otherwise pause playback
|
||||
pause();
|
||||
// otherwise stop playback
|
||||
stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
/* globals HIFI_PUBLIC_BUCKET:true, Tool, ToolBar */
|
||||
|
||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
Script.include("/~/system/libraries/toolBars.js");
|
||||
|
||||
var recordingFile = "recording.hfr";
|
||||
|
||||
function setPlayerOptions() {
|
||||
function setDefaultPlayerOptions() {
|
||||
Recording.setPlayFromCurrentLocation(true);
|
||||
Recording.setPlayerUseDisplayName(false);
|
||||
Recording.setPlayerUseAttachments(false);
|
||||
|
@ -38,16 +40,16 @@ var saveIcon;
|
|||
var loadIcon;
|
||||
var spacing;
|
||||
var timerOffset;
|
||||
setupToolBar();
|
||||
|
||||
var timer = null;
|
||||
var slider = null;
|
||||
|
||||
setupToolBar();
|
||||
setupTimer();
|
||||
|
||||
var watchStop = false;
|
||||
|
||||
function setupToolBar() {
|
||||
if (toolBar != null) {
|
||||
if (toolBar !== null) {
|
||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||
return;
|
||||
}
|
||||
|
@ -56,6 +58,8 @@ function setupToolBar() {
|
|||
|
||||
toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
|
||||
|
||||
toolBar.onMove = onToolbarMove;
|
||||
|
||||
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
||||
|
||||
recordIcon = toolBar.addTool({
|
||||
|
@ -86,7 +90,7 @@ function setupToolBar() {
|
|||
visible: true
|
||||
}, false);
|
||||
|
||||
timerOffset = toolBar.width;
|
||||
timerOffset = toolBar.width + ToolBar.SPACING;
|
||||
spacing = toolBar.addSpacing(0);
|
||||
|
||||
saveIcon = toolBar.addTool({
|
||||
|
@ -112,15 +116,15 @@ function setupTimer() {
|
|||
text: (0.00).toFixed(3),
|
||||
backgroundColor: COLOR_OFF,
|
||||
x: 0, y: 0,
|
||||
width: 0, height: 0,
|
||||
leftMargin: 10, topMargin: 10,
|
||||
width: 200, height: 25,
|
||||
leftMargin: 5, topMargin: 3,
|
||||
alpha: 1.0, backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
|
||||
slider = { x: 0, y: 0,
|
||||
w: 200, h: 20,
|
||||
pos: 0.0, // 0.0 <= pos <= 1.0
|
||||
pos: 0.0 // 0.0 <= pos <= 1.0
|
||||
};
|
||||
slider.background = Overlays.addOverlay("text", {
|
||||
text: "",
|
||||
|
@ -144,20 +148,40 @@ function setupTimer() {
|
|||
});
|
||||
}
|
||||
|
||||
function onToolbarMove(newX, newY, deltaX, deltaY) {
|
||||
Overlays.editOverlay(timer, {
|
||||
x: newX + timerOffset - ToolBar.SPACING,
|
||||
y: newY
|
||||
});
|
||||
|
||||
slider.x = newX - ToolBar.SPACING;
|
||||
slider.y = newY - slider.h - ToolBar.SPACING;
|
||||
|
||||
Overlays.editOverlay(slider.background, {
|
||||
x: slider.x,
|
||||
y: slider.y
|
||||
});
|
||||
Overlays.editOverlay(slider.foreground, {
|
||||
x: slider.x,
|
||||
y: slider.y
|
||||
});
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
var text = "";
|
||||
if (Recording.isRecording()) {
|
||||
text = formatTime(Recording.recorderElapsed());
|
||||
|
||||
} else {
|
||||
text = formatTime(Recording.playerElapsed()) + " / " +
|
||||
formatTime(Recording.playerLength());
|
||||
text = formatTime(Recording.playerElapsed()) + " / " + formatTime(Recording.playerLength());
|
||||
}
|
||||
|
||||
var timerWidth = text.length * 8 + ((Recording.isRecording()) ? 15 : 0);
|
||||
|
||||
Overlays.editOverlay(timer, {
|
||||
text: text
|
||||
})
|
||||
toolBar.changeSpacing(text.length * 8 + ((Recording.isRecording()) ? 15 : 0), spacing);
|
||||
text: text,
|
||||
width: timerWidth
|
||||
});
|
||||
toolBar.changeSpacing(timerWidth + ToolBar.SPACING, spacing);
|
||||
|
||||
if (Recording.isRecording()) {
|
||||
slider.pos = 1.0;
|
||||
|
@ -173,7 +197,7 @@ function updateTimer() {
|
|||
function formatTime(time) {
|
||||
var MIN_PER_HOUR = 60;
|
||||
var SEC_PER_MIN = 60;
|
||||
var MSEC_PER_SEC = 1000;
|
||||
var MSEC_DIGITS = 3;
|
||||
|
||||
var hours = Math.floor(time / (SEC_PER_MIN * MIN_PER_HOUR));
|
||||
time -= hours * (SEC_PER_MIN * MIN_PER_HOUR);
|
||||
|
@ -184,37 +208,19 @@ function formatTime(time) {
|
|||
var seconds = time;
|
||||
|
||||
var text = "";
|
||||
text += (hours > 0) ? hours + ":" :
|
||||
"";
|
||||
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
||||
"";
|
||||
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
||||
text += (hours > 0) ? hours + ":" : "";
|
||||
text += (minutes > 0) ? ((minutes < 10 && text !== "") ? "0" : "") + minutes + ":" : "";
|
||||
text += ((seconds < 10 && text !== "") ? "0" : "") + seconds.toFixed(MSEC_DIGITS);
|
||||
return text;
|
||||
}
|
||||
|
||||
function moveUI() {
|
||||
var relative = { x: 70, y: 40 };
|
||||
toolBar.move(relative.x, windowDimensions.y - relative.y);
|
||||
Overlays.editOverlay(timer, {
|
||||
x: relative.x + timerOffset - ToolBar.SPACING,
|
||||
y: windowDimensions.y - relative.y - ToolBar.SPACING
|
||||
});
|
||||
|
||||
slider.x = relative.x - ToolBar.SPACING;
|
||||
slider.y = windowDimensions.y - relative.y - slider.h - ToolBar.SPACING;
|
||||
|
||||
Overlays.editOverlay(slider.background, {
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
Overlays.editOverlay(slider.foreground, {
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
|
||||
if (recordIcon === toolBar.clicked(clickedOverlay, false) && !Recording.isPlaying()) {
|
||||
if (!Recording.isRecording()) {
|
||||
|
@ -226,7 +232,11 @@ function mousePressEvent(event) {
|
|||
toolBar.setAlpha(ALPHA_OFF, loadIcon);
|
||||
} else {
|
||||
Recording.stopRecording();
|
||||
toolBar.selectTool(recordIcon, true );
|
||||
toolBar.selectTool(recordIcon, true);
|
||||
setDefaultPlayerOptions();
|
||||
// Plays the recording at the same spot as you recorded it
|
||||
Recording.setPlayFromCurrentLocation(false);
|
||||
Recording.setPlayerTime(0);
|
||||
Recording.loadLastRecording();
|
||||
toolBar.setAlpha(ALPHA_ON, playIcon);
|
||||
toolBar.setAlpha(ALPHA_ON, playLoopIcon);
|
||||
|
@ -240,7 +250,6 @@ function mousePressEvent(event) {
|
|||
toolBar.setAlpha(ALPHA_ON, saveIcon);
|
||||
toolBar.setAlpha(ALPHA_ON, loadIcon);
|
||||
} else if (Recording.playerLength() > 0) {
|
||||
setPlayerOptions();
|
||||
Recording.setPlayerLoop(false);
|
||||
Recording.startPlaying();
|
||||
toolBar.setAlpha(ALPHA_OFF, recordIcon);
|
||||
|
@ -255,7 +264,6 @@ function mousePressEvent(event) {
|
|||
toolBar.setAlpha(ALPHA_ON, saveIcon);
|
||||
toolBar.setAlpha(ALPHA_ON, loadIcon);
|
||||
} else if (Recording.playerLength() > 0) {
|
||||
setPlayerOptions();
|
||||
Recording.setPlayerLoop(true);
|
||||
Recording.startPlaying();
|
||||
toolBar.setAlpha(ALPHA_OFF, recordIcon);
|
||||
|
@ -263,7 +271,7 @@ function mousePressEvent(event) {
|
|||
toolBar.setAlpha(ALPHA_OFF, loadIcon);
|
||||
}
|
||||
} else if (saveIcon === toolBar.clicked(clickedOverlay)) {
|
||||
if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() != 0) {
|
||||
if (!Recording.isRecording() && !Recording.isPlaying() && Recording.playerLength() !== 0) {
|
||||
recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
|
||||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||
Recording.saveRecording(recordingFile);
|
||||
|
@ -274,6 +282,7 @@ function mousePressEvent(event) {
|
|||
recordingFile = Window.browse("Load recording from file", ".", "Recordings (*.hfr *.rec *.HFR *.REC)");
|
||||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||
Recording.loadRecording(recordingFile);
|
||||
setDefaultPlayerOptions();
|
||||
}
|
||||
if (Recording.playerLength() > 0) {
|
||||
toolBar.setAlpha(ALPHA_ON, playIcon);
|
||||
|
@ -282,8 +291,8 @@ function mousePressEvent(event) {
|
|||
}
|
||||
}
|
||||
} else if (Recording.playerLength() > 0 &&
|
||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||
isSliding = true;
|
||||
slider.pos = (event.x - slider.x) / slider.w;
|
||||
Recording.setPlayerTime(slider.pos * Recording.playerLength());
|
||||
|
@ -308,7 +317,7 @@ function mouseReleaseEvent(event) {
|
|||
|
||||
function update() {
|
||||
var newDimensions = Controller.getViewportDimensions();
|
||||
if (windowDimensions.x != newDimensions.x || windowDimensions.y != newDimensions.y) {
|
||||
if (windowDimensions.x !== newDimensions.x || windowDimensions.y !== newDimensions.y) {
|
||||
windowDimensions = newDimensions;
|
||||
moveUI();
|
||||
}
|
||||
|
|
|
@ -160,6 +160,7 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
|
|||
visible: false
|
||||
});
|
||||
this.spacing = [];
|
||||
this.onMove = null;
|
||||
|
||||
this.addTool = function(properties, selectable, selected) {
|
||||
if (direction == ToolBar.HORIZONTAL) {
|
||||
|
@ -254,6 +255,9 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
|
|||
y: y - ToolBar.SPACING
|
||||
});
|
||||
}
|
||||
if (this.onMove !== null) {
|
||||
this.onMove(x, y, dx, dy);
|
||||
};
|
||||
}
|
||||
|
||||
this.setAlpha = function(alpha, tool) {
|
||||
|
|
Loading…
Reference in a new issue