mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Merge branch 'master' into seqNumberStats
This commit is contained in:
commit
97139b0bd0
3 changed files with 57 additions and 45 deletions
|
@ -286,7 +286,7 @@ void Stats::display(
|
|||
pingVoxel = totalPingVoxel/voxelServerCount;
|
||||
}
|
||||
|
||||
lines = _expanded ? 6 : 5;
|
||||
lines = _expanded ? 6 : 3;
|
||||
drawBackground(backgroundColor, horizontalOffset, 0, _pingStatsWidth, lines * STATS_PELS_PER_LINE + 10);
|
||||
horizontalOffset += 5;
|
||||
|
||||
|
@ -321,24 +321,24 @@ void Stats::display(
|
|||
|
||||
verticalOffset += STATS_PELS_PER_LINE;
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, voxelMaxPing, color);
|
||||
|
||||
|
||||
static const float MSECS_PER_FRAME = (float)NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL * (float)MSECS_PER_SECOND / (float)SAMPLE_RATE;
|
||||
|
||||
const AudioMixerJitterBuffersStats& audioMixerJitterBufferStats =
|
||||
Application::getInstance()->getAudio()->getAudioMixerJitterBuffersStats();
|
||||
|
||||
char* audioMixerJitterBuffersStatsLabel = "AudioMixer j-buffers msecs:";
|
||||
char audioMixerJitterBuffersStats[30];
|
||||
sprintf(audioMixerJitterBuffersStats, "mic/max/avg: %.1f / %.1f / %.1f", audioMixerJitterBufferStats._avatarJitterBufferFrames * MSECS_PER_FRAME,
|
||||
audioMixerJitterBufferStats._maxJitterBufferFrames * MSECS_PER_FRAME, audioMixerJitterBufferStats._avgJitterBufferFrames * MSECS_PER_FRAME);
|
||||
|
||||
verticalOffset += STATS_PELS_PER_LINE;
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, audioMixerJitterBuffersStatsLabel, color);
|
||||
verticalOffset += STATS_PELS_PER_LINE;
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, audioMixerJitterBuffersStats, color);
|
||||
}
|
||||
|
||||
static const float MSECS_PER_FRAME = (float)NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL * (float)MSECS_PER_SECOND / (float)SAMPLE_RATE;
|
||||
|
||||
const AudioMixerJitterBuffersStats& audioMixerJitterBufferStats =
|
||||
Application::getInstance()->getAudio()->getAudioMixerJitterBuffersStats();
|
||||
|
||||
char* audioMixerJitterBuffersStatsLabel = "AudioMixer j-buffers msecs:";
|
||||
char audioMixerJitterBuffersStats[30];
|
||||
sprintf(audioMixerJitterBuffersStats, "mic/max/avg: %.1f / %.1f / %.1f", audioMixerJitterBufferStats._avatarJitterBufferFrames * MSECS_PER_FRAME,
|
||||
audioMixerJitterBufferStats._maxJitterBufferFrames * MSECS_PER_FRAME, audioMixerJitterBufferStats._avgJitterBufferFrames * MSECS_PER_FRAME);
|
||||
|
||||
verticalOffset += STATS_PELS_PER_LINE;
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, audioMixerJitterBuffersStatsLabel, color);
|
||||
verticalOffset += STATS_PELS_PER_LINE;
|
||||
drawText(horizontalOffset, verticalOffset, scale, rotation, font, audioMixerJitterBuffersStats, color);
|
||||
|
||||
|
||||
verticalOffset = 0;
|
||||
horizontalOffset = _lastHorizontalOffset + _generalStatsWidth + _pingStatsWidth + 2;
|
||||
}
|
||||
|
|
|
@ -26,14 +26,13 @@ AudioRingBuffer::AudioRingBuffer(int numFrameSamples, bool randomAccessMode) :
|
|||
_numFrameSamples(numFrameSamples),
|
||||
_isStarved(true),
|
||||
_hasStarted(false),
|
||||
_randomAccessMode(randomAccessMode)
|
||||
_randomAccessMode(randomAccessMode),
|
||||
_isFull(false)
|
||||
{
|
||||
_arrayLength = _sampleCapacity + 1;
|
||||
|
||||
if (numFrameSamples) {
|
||||
_buffer = new int16_t[_arrayLength];
|
||||
_buffer = new int16_t[_sampleCapacity];
|
||||
if (_randomAccessMode) {
|
||||
memset(_buffer, 0, _arrayLength * sizeof(int16_t));
|
||||
memset(_buffer, 0, _sampleCapacity * sizeof(int16_t));
|
||||
}
|
||||
_nextOutput = _buffer;
|
||||
_endOfLastWrite = _buffer;
|
||||
|
@ -57,10 +56,10 @@ void AudioRingBuffer::reset() {
|
|||
void AudioRingBuffer::resizeForFrameSize(qint64 numFrameSamples) {
|
||||
delete[] _buffer;
|
||||
_sampleCapacity = numFrameSamples * RING_BUFFER_LENGTH_FRAMES;
|
||||
_arrayLength = _sampleCapacity + 1;
|
||||
_buffer = new int16_t[_arrayLength];
|
||||
_sampleCapacity = _sampleCapacity + 1;
|
||||
_buffer = new int16_t[_sampleCapacity];
|
||||
if (_randomAccessMode) {
|
||||
memset(_buffer, 0, _arrayLength * sizeof(int16_t));
|
||||
memset(_buffer, 0, _sampleCapacity * sizeof(int16_t));
|
||||
}
|
||||
_nextOutput = _buffer;
|
||||
_endOfLastWrite = _buffer;
|
||||
|
@ -87,11 +86,11 @@ qint64 AudioRingBuffer::readData(char *data, qint64 maxSize) {
|
|||
numReadSamples = _endOfLastWrite ? (maxSize / sizeof(int16_t)) : 0;
|
||||
}
|
||||
|
||||
if (_nextOutput + numReadSamples > _buffer + _arrayLength) {
|
||||
if (_nextOutput + numReadSamples > _buffer + _sampleCapacity) {
|
||||
// we're going to need to do two reads to get this data, it wraps around the edge
|
||||
|
||||
// read to the end of the buffer
|
||||
int numSamplesToEnd = (_buffer + _arrayLength) - _nextOutput;
|
||||
int numSamplesToEnd = (_buffer + _sampleCapacity) - _nextOutput;
|
||||
memcpy(data, _nextOutput, numSamplesToEnd * sizeof(int16_t));
|
||||
if (_randomAccessMode) {
|
||||
memset(_nextOutput, 0, numSamplesToEnd * sizeof(int16_t)); // clear it
|
||||
|
@ -112,6 +111,9 @@ qint64 AudioRingBuffer::readData(char *data, qint64 maxSize) {
|
|||
|
||||
// push the position of _nextOutput by the number of samples read
|
||||
_nextOutput = shiftedPositionAccomodatingWrap(_nextOutput, numReadSamples);
|
||||
if (numReadSamples > 0) {
|
||||
_isFull = false;
|
||||
}
|
||||
|
||||
return numReadSamples * sizeof(int16_t);
|
||||
}
|
||||
|
@ -134,16 +136,19 @@ qint64 AudioRingBuffer::writeData(const char* data, qint64 maxSize) {
|
|||
qDebug() << "Overflowed ring buffer! Overwriting old data";
|
||||
}
|
||||
|
||||
if (_endOfLastWrite + samplesToCopy <= _buffer + _arrayLength) {
|
||||
if (_endOfLastWrite + samplesToCopy <= _buffer + _sampleCapacity) {
|
||||
memcpy(_endOfLastWrite, data, samplesToCopy * sizeof(int16_t));
|
||||
} else {
|
||||
int numSamplesToEnd = (_buffer + _arrayLength) - _endOfLastWrite;
|
||||
int numSamplesToEnd = (_buffer + _sampleCapacity) - _endOfLastWrite;
|
||||
memcpy(_endOfLastWrite, data, numSamplesToEnd * sizeof(int16_t));
|
||||
memcpy(_buffer, data + (numSamplesToEnd * sizeof(int16_t)), (samplesToCopy - numSamplesToEnd) * sizeof(int16_t));
|
||||
}
|
||||
|
||||
_endOfLastWrite = shiftedPositionAccomodatingWrap(_endOfLastWrite, samplesToCopy);
|
||||
|
||||
if (samplesToCopy > 0 && _endOfLastWrite == _nextOutput) {
|
||||
_isFull = true;
|
||||
}
|
||||
|
||||
return samplesToCopy * sizeof(int16_t);
|
||||
}
|
||||
|
||||
|
@ -156,21 +161,25 @@ const int16_t& AudioRingBuffer::operator[] (const int index) const {
|
|||
}
|
||||
|
||||
void AudioRingBuffer::shiftReadPosition(unsigned int numSamples) {
|
||||
_nextOutput = shiftedPositionAccomodatingWrap(_nextOutput, numSamples);
|
||||
if (numSamples > 0) {
|
||||
_nextOutput = shiftedPositionAccomodatingWrap(_nextOutput, numSamples);
|
||||
_isFull = false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int AudioRingBuffer::samplesAvailable() const {
|
||||
if (!_endOfLastWrite) {
|
||||
return 0;
|
||||
} else {
|
||||
int sampleDifference = _endOfLastWrite - _nextOutput;
|
||||
|
||||
if (sampleDifference < 0) {
|
||||
sampleDifference += _arrayLength;
|
||||
}
|
||||
|
||||
return sampleDifference;
|
||||
}
|
||||
if (_isFull) {
|
||||
return _sampleCapacity;
|
||||
}
|
||||
|
||||
int sampleDifference = _endOfLastWrite - _nextOutput;
|
||||
if (sampleDifference < 0) {
|
||||
sampleDifference += _sampleCapacity;
|
||||
}
|
||||
return sampleDifference;
|
||||
}
|
||||
|
||||
int AudioRingBuffer::addSilentFrame(int numSilentSamples) {
|
||||
|
@ -184,14 +193,17 @@ int AudioRingBuffer::addSilentFrame(int numSilentSamples) {
|
|||
|
||||
// memset zeroes into the buffer, accomodate a wrap around the end
|
||||
// push the _endOfLastWrite to the correct spot
|
||||
if (_endOfLastWrite + numSilentSamples <= _buffer + _arrayLength) {
|
||||
if (_endOfLastWrite + numSilentSamples <= _buffer + _sampleCapacity) {
|
||||
memset(_endOfLastWrite, 0, numSilentSamples * sizeof(int16_t));
|
||||
} else {
|
||||
int numSamplesToEnd = (_buffer + _arrayLength) - _endOfLastWrite;
|
||||
int numSamplesToEnd = (_buffer + _sampleCapacity) - _endOfLastWrite;
|
||||
memset(_endOfLastWrite, 0, numSamplesToEnd * sizeof(int16_t));
|
||||
memset(_buffer, 0, (numSilentSamples - numSamplesToEnd) * sizeof(int16_t));
|
||||
}
|
||||
_endOfLastWrite = shiftedPositionAccomodatingWrap(_endOfLastWrite, numSilentSamples);
|
||||
if (numSilentSamples > 0 && _nextOutput == _endOfLastWrite) {
|
||||
_isFull = true;
|
||||
}
|
||||
|
||||
return numSilentSamples * sizeof(int16_t);
|
||||
}
|
||||
|
@ -206,12 +218,12 @@ bool AudioRingBuffer::isNotStarvedOrHasMinimumSamples(unsigned int numRequiredSa
|
|||
|
||||
int16_t* AudioRingBuffer::shiftedPositionAccomodatingWrap(int16_t* position, int numSamplesShift) const {
|
||||
|
||||
if (numSamplesShift > 0 && position + numSamplesShift >= _buffer + _arrayLength) {
|
||||
if (numSamplesShift > 0 && position + numSamplesShift >= _buffer + _sampleCapacity) {
|
||||
// this shift will wrap the position around to the beginning of the ring
|
||||
return position + numSamplesShift - _arrayLength;
|
||||
return position + numSamplesShift - _sampleCapacity;
|
||||
} else if (numSamplesShift < 0 && position + numSamplesShift < _buffer) {
|
||||
// this shift will go around to the end of the ring
|
||||
return position + numSamplesShift + _arrayLength;
|
||||
return position + numSamplesShift + _sampleCapacity;
|
||||
} else {
|
||||
return position + numSamplesShift;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ protected:
|
|||
int _resetCount; /// how many times has the ring buffer written past the end and done a reset
|
||||
|
||||
int _sampleCapacity;
|
||||
int _arrayLength;
|
||||
bool _isFull;
|
||||
int _numFrameSamples;
|
||||
int16_t* _nextOutput;
|
||||
int16_t* _endOfLastWrite;
|
||||
|
|
Loading…
Reference in a new issue