// // AvatarAudioStream.cpp // assignment-client/src/audio // // Created by Stephen Birarda on 6/5/13. // Copyright 2013 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include #include "AvatarAudioStream.h" AvatarAudioStream::AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings) : PositionalAudioStream(PositionalAudioStream::Microphone, isStereo, settings) { } int AvatarAudioStream::parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples) { int readBytes = 0; if (type == PacketTypeSilentAudioFrame) { const char* dataAt = packetAfterSeqNum.constData(); quint16 numSilentSamples = *(reinterpret_cast(dataAt)); readBytes += sizeof(quint16); numAudioSamples = (int)numSilentSamples; // read the positional data readBytes += parsePositionalData(packetAfterSeqNum.mid(readBytes)); } else { _shouldLoopbackForNode = (type == PacketTypeMicrophoneAudioWithEcho); // read the channel flag quint8 channelFlag = packetAfterSeqNum.at(readBytes); bool isStereo = channelFlag == 1; readBytes += sizeof(quint8); // if isStereo value has changed, restart the ring buffer with new frame size if (isStereo != _isStereo) { _ringBuffer.resizeForFrameSize(isStereo ? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO : NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL); _isStereo = isStereo; } // read the positional data readBytes += parsePositionalData(packetAfterSeqNum.mid(readBytes)); // calculate how many samples are in this packet int numAudioBytes = packetAfterSeqNum.size() - readBytes; numAudioSamples = numAudioBytes / sizeof(int16_t); } return readBytes; }