debugging new audio stream organization

This commit is contained in:
wangyix 2014-07-24 13:58:15 -07:00
parent 172cd91f27
commit 3d22a11e28
4 changed files with 41 additions and 53 deletions

View file

@ -98,15 +98,18 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
// if the frame to be mixed is silent, don't mix it // if the frame to be mixed is silent, don't mix it
if (bufferToAdd->getNextOutputTrailingLoudness() == 0.0f) { if (bufferToAdd->getNextOutputTrailingLoudness() == 0.0f) {
bufferToAdd->popFrames(1); bufferToAdd->popFrames(1);
printf("trailing loudness too soft: not mixing!\n");
return; return;
} }
// get pointer to frame to be mixed. If the stream cannot provide a frame (is starved), bail // get pointer to frame to be mixed. If the stream cannot provide a frame (is starved), bail
AudioRingBuffer::ConstIterator nextOutputStart; AudioRingBuffer::ConstIterator nextOutputStart;
if (!bufferToAdd->popFrames(&nextOutputStart, 1)) { if (!bufferToAdd->popFrames(&nextOutputStart, 1)) {
printf("stream is starved! not mixing!\n");
return; return;
} }
printf("mixing stream\n");
float bearingRelativeAngleToSource = 0.0f; float bearingRelativeAngleToSource = 0.0f;
float attenuationCoefficient = 1.0f; float attenuationCoefficient = 1.0f;
@ -312,7 +315,7 @@ void AudioMixer::prepareMixForListeningNode(Node* node) {
QHash<QUuid, PositionalAudioRingBuffer*>::ConstIterator i, end = otherNodeRingBuffers.constEnd(); QHash<QUuid, PositionalAudioRingBuffer*>::ConstIterator i, end = otherNodeRingBuffers.constEnd();
for (i = otherNodeRingBuffers.begin(); i != end; i++) { for (i = otherNodeRingBuffers.begin(); i != end; i++) {
PositionalAudioRingBuffer* otherNodeBuffer = i.value(); PositionalAudioRingBuffer* otherNodeBuffer = i.value();
if (*otherNode != *node || otherNodeBuffer->shouldLoopbackForNode()) { if (*otherNode != *node || otherNodeBuffer->shouldLoopbackForNode()) {
addBufferToMixForListeningNodeWithBuffer(otherNodeBuffer, nodeRingBuffer); addBufferToMixForListeningNodeWithBuffer(otherNodeBuffer, nodeRingBuffer);
} }

View file

@ -86,6 +86,7 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
} }
if (_isStarved && _ringBuffer.samplesAvailable() >= _desiredJitterBufferFrames * _ringBuffer.getNumFrameSamples()) { if (_isStarved && _ringBuffer.samplesAvailable() >= _desiredJitterBufferFrames * _ringBuffer.getNumFrameSamples()) {
printf("\nstream refilled from starve!\n");
_isStarved = false; _isStarved = false;
} }
@ -95,79 +96,60 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
} }
bool InboundAudioStream::popFrames(int numFrames, bool starveOnFail) { bool InboundAudioStream::popFrames(int numFrames, bool starveOnFail) {
if (_isStarved) { bool popped;
_consecutiveNotMixedCount++;
return false;
}
bool popped = false;
int numSamplesRequested = numFrames * _ringBuffer.getNumFrameSamples(); int numSamplesRequested = numFrames * _ringBuffer.getNumFrameSamples();
if (_ringBuffer.samplesAvailable() >= numSamplesRequested) { if (popped = shouldPop(numSamplesRequested, starveOnFail)) {
_ringBuffer.shiftReadPosition(numSamplesRequested); _ringBuffer.shiftReadPosition(numSamplesRequested);
_hasStarted = true;
popped = true;
} else {
if (starveOnFail) {
setToStarved();
_consecutiveNotMixedCount++;
}
} }
_framesAvailableStats.update(_ringBuffer.framesAvailable()); _framesAvailableStats.update(_ringBuffer.framesAvailable());
return popped; return popped;
} }
bool InboundAudioStream::popFrames(int16_t* dest, int numFrames, bool starveOnFail) { bool InboundAudioStream::popFrames(int16_t* dest, int numFrames, bool starveOnFail) {
if (_isStarved) { bool popped;
_consecutiveNotMixedCount++;
return false;
}
bool popped = false;
int numSamplesRequested = numFrames * _ringBuffer.getNumFrameSamples(); int numSamplesRequested = numFrames * _ringBuffer.getNumFrameSamples();
if (_ringBuffer.samplesAvailable() >= numSamplesRequested) { if (popped = shouldPop(numSamplesRequested, starveOnFail)) {
_ringBuffer.readSamples(dest, numSamplesRequested); _ringBuffer.readSamples(dest, numSamplesRequested);
_hasStarted = true;
popped = true;
} else {
if (starveOnFail) {
setToStarved();
_consecutiveNotMixedCount++;
}
} }
_framesAvailableStats.update(_ringBuffer.framesAvailable()); _framesAvailableStats.update(_ringBuffer.framesAvailable());
return popped; return popped;
} }
bool InboundAudioStream::popFrames(AudioRingBuffer::ConstIterator* nextOutput, int numFrames, bool starveOnFail) { bool InboundAudioStream::popFrames(AudioRingBuffer::ConstIterator* nextOutput, int numFrames, bool starveOnFail) {
bool popped;
int numSamplesRequested = numFrames * _ringBuffer.getNumFrameSamples();
if (popped = shouldPop(numSamplesRequested, starveOnFail)) {
*nextOutput = _ringBuffer.nextOutput();
_ringBuffer.shiftReadPosition(numSamplesRequested);
}
_framesAvailableStats.update(_ringBuffer.framesAvailable());
return popped;
}
bool InboundAudioStream::shouldPop(int numSamples, bool starveOnFail) {
printf("\nshouldPop()\n");
if (_isStarved) { if (_isStarved) {
printf("\t we're starved, not popping\n");
_consecutiveNotMixedCount++; _consecutiveNotMixedCount++;
return false; return false;
} }
bool popped = false; if (_ringBuffer.samplesAvailable() >= numSamples) {
printf("have requested samples and not starved, popping\n");
int numSamplesRequested = numFrames * _ringBuffer.getNumFrameSamples();
if (_ringBuffer.samplesAvailable() >= numSamplesRequested) {
*nextOutput = _ringBuffer.nextOutput();
_ringBuffer.shiftReadPosition(numSamplesRequested);
_hasStarted = true; _hasStarted = true;
popped = true; return true;
} else { } else {
if (starveOnFail) { if (starveOnFail) {
printf("don't have enough samples; starved!\n");
setToStarved(); setToStarved();
_consecutiveNotMixedCount++; _consecutiveNotMixedCount++;
} }
return false;
} }
_framesAvailableStats.update(_ringBuffer.framesAvailable());
return popped;
} }
void InboundAudioStream::setToStarved() { void InboundAudioStream::setToStarved() {

View file

@ -79,6 +79,9 @@ public:
int getSilentFramesDropped() const { return _silentFramesDropped; } int getSilentFramesDropped() const { return _silentFramesDropped; }
int getOverflowCount() const { return _ringBuffer.getOverflowCount(); } int getOverflowCount() const { return _ringBuffer.getOverflowCount(); }
private:
bool shouldPop(int numSamples, bool starveOnFail);
protected: protected:
// disallow copying of InboundAudioStream objects // disallow copying of InboundAudioStream objects
InboundAudioStream(const InboundAudioStream&); InboundAudioStream(const InboundAudioStream&);

View file

@ -22,15 +22,15 @@
#include <UUID.h> #include <UUID.h>
PositionalAudioRingBuffer::PositionalAudioRingBuffer(PositionalAudioRingBuffer::Type type, bool isStereo, bool dynamicJitterBuffers) : PositionalAudioRingBuffer::PositionalAudioRingBuffer(PositionalAudioRingBuffer::Type type, bool isStereo, bool dynamicJitterBuffers) :
InboundAudioStream(isStereo ? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO : NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL, InboundAudioStream(isStereo ? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO : NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL,
AUDIOMIXER_INBOUND_RING_BUFFER_FRAME_CAPACITY, dynamicJitterBuffers), AUDIOMIXER_INBOUND_RING_BUFFER_FRAME_CAPACITY, dynamicJitterBuffers),
_type(type), _type(type),
_position(0.0f, 0.0f, 0.0f), _position(0.0f, 0.0f, 0.0f),
_orientation(0.0f, 0.0f, 0.0f, 0.0f), _orientation(0.0f, 0.0f, 0.0f, 0.0f),
_shouldLoopbackForNode(false), _shouldLoopbackForNode(false),
_isStereo(isStereo), _isStereo(isStereo),
_nextOutputTrailingLoudness(0.0f), _nextOutputTrailingLoudness(0.0f),
_listenerUnattenuatedZone(NULL) _listenerUnattenuatedZone(NULL)
{ {
} }