mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
added InterframeTimeGapHistory and frameReceived() calls
This commit is contained in:
parent
761a154a93
commit
aa3602f0fb
4 changed files with 89 additions and 0 deletions
|
@ -19,6 +19,8 @@ AvatarAudioRingBuffer::AvatarAudioRingBuffer(bool isStereo) :
|
||||||
}
|
}
|
||||||
|
|
||||||
int AvatarAudioRingBuffer::parseData(const QByteArray& packet) {
|
int AvatarAudioRingBuffer::parseData(const QByteArray& packet) {
|
||||||
|
_timeGapHistory.frameReceived();
|
||||||
|
|
||||||
_shouldLoopbackForNode = (packetTypeForPacket(packet) == PacketTypeMicrophoneAudioWithEcho);
|
_shouldLoopbackForNode = (packetTypeForPacket(packet) == PacketTypeMicrophoneAudioWithEcho);
|
||||||
return PositionalAudioRingBuffer::parseData(packet);
|
return PositionalAudioRingBuffer::parseData(packet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
|
@ -19,6 +20,62 @@
|
||||||
|
|
||||||
#include "AudioRingBuffer.h"
|
#include "AudioRingBuffer.h"
|
||||||
|
|
||||||
|
InterframeTimeGapHistory::InterframeTimeGapHistory()
|
||||||
|
: _lastFrameReceivedTime(0),
|
||||||
|
_numSamplesInCurrentInterval(0),
|
||||||
|
_currentIntervalMaxGap(0),
|
||||||
|
_newestIntervalMaxGapAt(0),
|
||||||
|
_windowMaxGap(0),
|
||||||
|
_newWindowMaxGapAvailable(false)
|
||||||
|
{
|
||||||
|
memset(_intervalMaxGaps, 0, TIME_GAP_NUM_INTERVALS_IN_WINDOW*sizeof(quint64));
|
||||||
|
}
|
||||||
|
|
||||||
|
void InterframeTimeGapHistory::frameReceived() {
|
||||||
|
quint64 now = usecTimestampNow();
|
||||||
|
|
||||||
|
// make sure this isn't the first time frameReceived() is called, meaning there's actually a gap to calculate.
|
||||||
|
if (_lastFrameReceivedTime != 0) {
|
||||||
|
quint64 gap = now - _lastFrameReceivedTime;
|
||||||
|
|
||||||
|
// update the current interval max
|
||||||
|
if (gap > _currentIntervalMaxGap) {
|
||||||
|
_currentIntervalMaxGap = gap;
|
||||||
|
}
|
||||||
|
_numSamplesInCurrentInterval++;
|
||||||
|
|
||||||
|
// if the current interval of samples is now full, record it in our interval maxes
|
||||||
|
if (_numSamplesInCurrentInterval == TIME_GAP_NUM_SAMPLES_IN_INTERVAL) {
|
||||||
|
|
||||||
|
// find location to insert this interval's max (increment index cyclically)
|
||||||
|
_newestIntervalMaxGapAt = _newestIntervalMaxGapAt == TIME_GAP_NUM_INTERVALS_IN_WINDOW - 1 ? 0 : _newestIntervalMaxGapAt + 1;
|
||||||
|
|
||||||
|
// record the current interval's max gap as the newest
|
||||||
|
_intervalMaxGaps[_newestIntervalMaxGapAt] = _currentIntervalMaxGap;
|
||||||
|
|
||||||
|
// update the window max gap, which is the max out of all the past intervals' max gaps
|
||||||
|
_windowMaxGap = 0;
|
||||||
|
for (int i = 0; i < TIME_GAP_NUM_INTERVALS_IN_WINDOW; i++) {
|
||||||
|
if (_intervalMaxGaps[i] > _windowMaxGap) {
|
||||||
|
_windowMaxGap = _intervalMaxGaps[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_newWindowMaxGapAvailable = true;
|
||||||
|
|
||||||
|
// reset the current interval
|
||||||
|
_numSamplesInCurrentInterval = 0;
|
||||||
|
_currentIntervalMaxGap = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_lastFrameReceivedTime = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint64 InterframeTimeGapHistory::getPastWindowMaxGap() {
|
||||||
|
_newWindowMaxGapAvailable = false;
|
||||||
|
return _windowMaxGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
AudioRingBuffer::AudioRingBuffer(int numFrameSamples, bool randomAccessMode) :
|
AudioRingBuffer::AudioRingBuffer(int numFrameSamples, bool randomAccessMode) :
|
||||||
NodeData(),
|
NodeData(),
|
||||||
_sampleCapacity(numFrameSamples * RING_BUFFER_LENGTH_FRAMES),
|
_sampleCapacity(numFrameSamples * RING_BUFFER_LENGTH_FRAMES),
|
||||||
|
|
|
@ -21,6 +21,30 @@
|
||||||
|
|
||||||
#include "NodeData.h"
|
#include "NodeData.h"
|
||||||
|
|
||||||
|
// this means that every 500 samples, the max for the past 10*500 samples will be calculated
|
||||||
|
const int TIME_GAP_NUM_SAMPLES_IN_INTERVAL = 500;
|
||||||
|
const int TIME_GAP_NUM_INTERVALS_IN_WINDOW = 10;
|
||||||
|
|
||||||
|
class InterframeTimeGapHistory {
|
||||||
|
public:
|
||||||
|
InterframeTimeGapHistory();
|
||||||
|
|
||||||
|
void frameReceived();
|
||||||
|
bool isNewWindowMaxGapAvailable() const { return _newWindowMaxGapAvailable; }
|
||||||
|
quint64 getPastWindowMaxGap();
|
||||||
|
|
||||||
|
private:
|
||||||
|
quint64 _lastFrameReceivedTime;
|
||||||
|
|
||||||
|
int _numSamplesInCurrentInterval;
|
||||||
|
quint64 _currentIntervalMaxGap;
|
||||||
|
quint64 _intervalMaxGaps[TIME_GAP_NUM_INTERVALS_IN_WINDOW];
|
||||||
|
int _newestIntervalMaxGapAt;
|
||||||
|
quint64 _windowMaxGap;
|
||||||
|
bool _newWindowMaxGapAvailable;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const int SAMPLE_RATE = 24000;
|
const int SAMPLE_RATE = 24000;
|
||||||
|
|
||||||
const int NETWORK_BUFFER_LENGTH_BYTES_STEREO = 1024;
|
const int NETWORK_BUFFER_LENGTH_BYTES_STEREO = 1024;
|
||||||
|
@ -74,6 +98,8 @@ public:
|
||||||
bool hasStarted() const { return _hasStarted; }
|
bool hasStarted() const { return _hasStarted; }
|
||||||
|
|
||||||
void addSilentFrame(int numSilentSamples);
|
void addSilentFrame(int numSilentSamples);
|
||||||
|
|
||||||
|
InterframeTimeGapHistory& getInterframeTimeGapHistory() { return _timeGapHistory; }
|
||||||
protected:
|
protected:
|
||||||
// disallow copying of AudioRingBuffer objects
|
// disallow copying of AudioRingBuffer objects
|
||||||
AudioRingBuffer(const AudioRingBuffer&);
|
AudioRingBuffer(const AudioRingBuffer&);
|
||||||
|
@ -89,6 +115,8 @@ protected:
|
||||||
bool _isStarved;
|
bool _isStarved;
|
||||||
bool _hasStarted;
|
bool _hasStarted;
|
||||||
bool _randomAccessMode; /// will this ringbuffer be used for random access? if so, do some special processing
|
bool _randomAccessMode; /// will this ringbuffer be used for random access? if so, do some special processing
|
||||||
|
|
||||||
|
InterframeTimeGapHistory _timeGapHistory;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AudioRingBuffer_h
|
#endif // hifi_AudioRingBuffer_h
|
||||||
|
|
|
@ -31,6 +31,8 @@ InjectedAudioRingBuffer::InjectedAudioRingBuffer(const QUuid& streamIdentifier)
|
||||||
const uchar MAX_INJECTOR_VOLUME = 255;
|
const uchar MAX_INJECTOR_VOLUME = 255;
|
||||||
|
|
||||||
int InjectedAudioRingBuffer::parseData(const QByteArray& packet) {
|
int InjectedAudioRingBuffer::parseData(const QByteArray& packet) {
|
||||||
|
_timeGapHistory.frameReceived();
|
||||||
|
|
||||||
// setup a data stream to read from this packet
|
// setup a data stream to read from this packet
|
||||||
QDataStream packetStream(packet);
|
QDataStream packetStream(packet);
|
||||||
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
||||||
|
|
Loading…
Reference in a new issue