fixed audio scope; added parseSilentPacketStreamProperties()

This commit is contained in:
wangyix 2014-08-08 14:55:38 -07:00
parent bf8188c6ff
commit a2d66b9a8f
5 changed files with 36 additions and 13 deletions

View file

@ -1481,17 +1481,17 @@ void Audio::renderScope(int width, int height) {
return; return;
static const float backgroundColor[4] = { 0.4f, 0.4f, 0.4f, 0.6f }; static const float backgroundColor[4] = { 0.4f, 0.4f, 0.4f, 0.6f };
static const float gridColor[4] = { 0.3f, 0.3f, 0.3f, 0.6f }; static const float gridColor[4] = { 0.7f, 0.7f, 0.7f, 1.0f };
static const float inputColor[4] = { 0.3f, 1.0f, 0.3f, 1.0f }; static const float inputColor[4] = { 0.3f, 1.0f, 0.3f, 1.0f };
static const float outputLeftColor[4] = { 1.0f, 0.3f, 0.3f, 1.0f }; static const float outputLeftColor[4] = { 1.0f, 0.3f, 0.3f, 1.0f };
static const float outputRightColor[4] = { 0.3f, 0.3f, 1.0f, 1.0f }; static const float outputRightColor[4] = { 0.3f, 0.3f, 1.0f, 1.0f };
static const int gridRows = 2; static const int gridRows = 2;
int gridCols = _framesPerScope; int gridCols = _framesPerScope;
int x = (width - SCOPE_WIDTH) / 2; int x = (width - (int)SCOPE_WIDTH) / 2;
int y = (height - SCOPE_HEIGHT) / 2; int y = (height - (int)SCOPE_HEIGHT) / 2;
int w = SCOPE_WIDTH; int w = (int)SCOPE_WIDTH;
int h = SCOPE_HEIGHT; int h = (int)SCOPE_HEIGHT;
renderBackground(backgroundColor, x, y, w, h); renderBackground(backgroundColor, x, y, w, h);
renderGrid(gridColor, x, y, w, h, gridRows, gridCols); renderGrid(gridColor, x, y, w, h, gridRows, gridCols);

View file

@ -107,12 +107,7 @@ int InboundAudioStream::parseData(const QByteArray& packet) {
int numAudioSamples; int numAudioSamples;
if (packetType == PacketTypeSilentAudioFrame) { if (packetType == PacketTypeSilentAudioFrame) {
// this is a general silent packet; parse the number of silent samples readBytes += parseSilentPacketStreamProperties(packet.mid(readBytes), numAudioSamples);
quint16 numSilentSamples = *(reinterpret_cast<const quint16*>(dataAt));
dataAt += sizeof(quint16);
readBytes += sizeof(quint16);
numAudioSamples = numSilentSamples;
} else { } else {
// parse the info after the seq number and before the audio data (the stream properties) // parse the info after the seq number and before the audio data (the stream properties)
readBytes += parseStreamProperties(packetType, packet.mid(readBytes), numAudioSamples); readBytes += parseStreamProperties(packetType, packet.mid(readBytes), numAudioSamples);
@ -171,6 +166,12 @@ int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packet
return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t)); return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t));
} }
int InboundAudioStream::parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
// this is a general silent packet; parse the number of silent samples
quint16 numSilentSamples = *(reinterpret_cast<const quint16*>(packetAfterSeqNum.data()));
numAudioSamples = numSilentSamples;
return sizeof(quint16);
}
int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped) { int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing, bool starveIfNoSamplesPopped) {
int samplesPopped = 0; int samplesPopped = 0;

View file

@ -172,6 +172,10 @@ protected:
/// parses the info between the seq num and the audio data in the network packet and calculates /// parses the info between the seq num and the audio data in the network packet and calculates
/// how many audio samples this packet contains (used when filling in samples for dropped packets). /// how many audio samples this packet contains (used when filling in samples for dropped packets).
virtual int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) = 0; virtual int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) = 0;
/// parses a silent packet after the seq. default implementation assumes the number of silent samples
/// is the only thing in packetAfterSeqNum and should work in most cases
virtual int parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples);
/// parses the audio data in the network packet. /// parses the audio data in the network packet.
/// default implementation assumes packet contains raw audio samples after stream properties /// default implementation assumes packet contains raw audio samples after stream properties

View file

@ -28,12 +28,22 @@ int MixedProcessedAudioStream::parseStreamProperties(PacketType type, const QByt
// since numAudioSamples is used to know how many samples to add for each dropped packet before this one, // since numAudioSamples is used to know how many samples to add for each dropped packet before this one,
// we want to set it to the number of device audio samples since this stream contains device audio samples, not network samples. // we want to set it to the number of device audio samples since this stream contains device audio samples, not network samples.
const int STEREO_DIVIDER = 2; numAudioSamples = networkToDeviceSamples(numNetworkSamples);
numAudioSamples = numNetworkSamples * _outputFormatChannelsTimesSampleRate / (STEREO_DIVIDER * SAMPLE_RATE);
return 0; return 0;
} }
int MixedProcessedAudioStream::parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples) {
int numNetworkSamples;
int bytesRead = InboundAudioStream::parseSilentPacketStreamProperties(packetAfterSeqNum, numNetworkSamples);
// since numAudioSamples is used to know how many samples to add for each dropped packet before this one,
// we want to set it to the number of device audio samples since this stream contains device audio samples, not network samples.
numAudioSamples = networkToDeviceSamples(numNetworkSamples);
return bytesRead;
}
int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) { int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
QByteArray outputBuffer; QByteArray outputBuffer;
@ -43,3 +53,8 @@ int MixedProcessedAudioStream::parseAudioData(PacketType type, const QByteArray&
return packetAfterStreamProperties.size(); return packetAfterStreamProperties.size();
} }
int MixedProcessedAudioStream::networkToDeviceSamples(int networkSamples) {
const int STEREO_DIVIDER = 2;
return networkSamples * _outputFormatChannelsTimesSampleRate / (STEREO_DIVIDER * SAMPLE_RATE);
}

View file

@ -28,8 +28,11 @@ public:
protected: protected:
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples); int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
int parseSilentPacketStreamProperties(const QByteArray& packetAfterSeqNum, int& numAudioSamples);
int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples); int parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples);
private:
int networkToDeviceSamples(int networkSamples);
private: private:
int _outputFormatChannelsTimesSampleRate; int _outputFormatChannelsTimesSampleRate;
}; };