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

View file

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

View file

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

View file

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