mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Play the flushed encoder sound at end
Basically 0-padding the end of the sound buffer. Next do that in AudioMixer and we should be good.
This commit is contained in:
parent
6a61762659
commit
d00a73dde1
2 changed files with 16 additions and 17 deletions
|
@ -474,10 +474,9 @@ void Agent::processAgentAvatar() {
|
||||||
nodeList->broadcastToNodes(std::move(avatarPacket), NodeSet() << NodeType::AvatarMixer);
|
nodeList->broadcastToNodes(std::move(avatarPacket), NodeSet() << NodeType::AvatarMixer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Agent::flushEncoder() {
|
void Agent::flushEncoder(QByteArray& encodedZeros) {
|
||||||
_flushEncoder = false;
|
_flushEncoder = false;
|
||||||
static QByteArray zeros(AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL, 0);
|
static const QByteArray zeros(AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL, 0);
|
||||||
static QByteArray encodedZeros;
|
|
||||||
if (_encoder) {
|
if (_encoder) {
|
||||||
_encoder->encode(zeros, encodedZeros);
|
_encoder->encode(zeros, encodedZeros);
|
||||||
}
|
}
|
||||||
|
@ -485,13 +484,6 @@ void Agent::flushEncoder() {
|
||||||
|
|
||||||
void Agent::processAgentAvatarAudio() {
|
void Agent::processAgentAvatarAudio() {
|
||||||
if (_isAvatar && (_isListeningToAudioStream || _avatarSound)) {
|
if (_isAvatar && (_isListeningToAudioStream || _avatarSound)) {
|
||||||
// after sound is done playing, encoder has a bit of state in it,
|
|
||||||
// and needs some 0s to forget or you get a little click next time
|
|
||||||
// you play something
|
|
||||||
if (_flushEncoder) {
|
|
||||||
flushEncoder();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have an avatar audio stream then send it out to our audio-mixer
|
// if we have an avatar audio stream then send it out to our audio-mixer
|
||||||
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
|
||||||
bool silentFrame = true;
|
bool silentFrame = true;
|
||||||
|
@ -528,7 +520,7 @@ void Agent::processAgentAvatarAudio() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto audioPacket = NLPacket::create(silentFrame
|
auto audioPacket = NLPacket::create(silentFrame && !_flushEncoder
|
||||||
? PacketType::SilentAudioFrame
|
? PacketType::SilentAudioFrame
|
||||||
: PacketType::MicrophoneAudioNoEcho);
|
: PacketType::MicrophoneAudioNoEcho);
|
||||||
|
|
||||||
|
@ -564,13 +556,20 @@ void Agent::processAgentAvatarAudio() {
|
||||||
glm::quat headOrientation = scriptedAvatar->getHeadOrientation();
|
glm::quat headOrientation = scriptedAvatar->getHeadOrientation();
|
||||||
audioPacket->writePrimitive(headOrientation);
|
audioPacket->writePrimitive(headOrientation);
|
||||||
|
|
||||||
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
|
|
||||||
QByteArray encodedBuffer;
|
QByteArray encodedBuffer;
|
||||||
// encode it
|
if (_flushEncoder) {
|
||||||
if(_encoder) {
|
// after sound is done playing, encoder has a bit of state in it,
|
||||||
_encoder->encode(decodedBuffer, encodedBuffer);
|
// and needs some 0s to forget or you get a little click next time
|
||||||
|
// you play something. So, basically 0-pad the end of the sound buffer
|
||||||
|
flushEncoder(encodedBuffer);
|
||||||
} else {
|
} else {
|
||||||
encodedBuffer = decodedBuffer;
|
// encode it
|
||||||
|
QByteArray decodedBuffer(reinterpret_cast<const char*>(nextSoundOutput), numAvailableSamples*sizeof(int16_t));
|
||||||
|
if (_encoder) {
|
||||||
|
_encoder->encode(decodedBuffer, encodedBuffer);
|
||||||
|
} else {
|
||||||
|
encodedBuffer = decodedBuffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
audioPacket->write(encodedBuffer.constData(), encodedBuffer.size());
|
audioPacket->write(encodedBuffer.constData(), encodedBuffer.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ signals:
|
||||||
private:
|
private:
|
||||||
void negotiateAudioFormat();
|
void negotiateAudioFormat();
|
||||||
void selectAudioFormat(const QString& selectedCodecName);
|
void selectAudioFormat(const QString& selectedCodecName);
|
||||||
void flushEncoder();
|
void flushEncoder(QByteArray& encodedZeros);
|
||||||
|
|
||||||
std::unique_ptr<ScriptEngine> _scriptEngine;
|
std::unique_ptr<ScriptEngine> _scriptEngine;
|
||||||
EntityEditPacketSender _entityEditSender;
|
EntityEditPacketSender _entityEditSender;
|
||||||
|
|
Loading…
Reference in a new issue