Use radio samplerate for opus

monitor
Phil Taylor 2021-08-14 10:06:17 +01:00
rodzic f5913dc099
commit d2098996ac
1 zmienionych plików z 11 dodań i 17 usunięć

Wyświetl plik

@ -72,20 +72,12 @@ bool audioHandler::init(audioSetup setupIn)
if (setup.codec == 0x01 || setup.codec == 0x20) {
setup.ulaw = true;
}
if (setup.codec == 0x08 || setup.codec == 0x10 || setup.codec == 0x20) {
if (setup.codec == 0x08 || setup.codec == 0x10 || setup.codec == 0x20 || setup.codec == 0x80) {
setup.radioChan = 2;
}
if (setup.codec == 0x04 || setup.codec == 0x10) {
if (setup.codec == 0x04 || setup.codec == 0x10 || setup.codec == 0x40 || setup.codec == 0x80) {
setup.bits = 16;
}
if (setup.codec == 0x40 || setup.codec == 0x80)
{
setup.bits = 16;
}
if (setup.codec == 0x80)
{
setup.radioChan = 2;
}
ringBuf = new wilt::Ring<audioPacket>(100); // Should be customizable.
@ -497,20 +489,22 @@ void audioHandler::incomingAudio(audioPacket inPacket)
if (setup.codec == 0x40 || setup.codec == 0x80) {
unsigned char* in = (unsigned char*)inPacket.data.data();
qInfo(logAudio()) << "Opus Packet Received: << " << opus_packet_get_nb_channels(in) << "channels, " << opus_packet_get_nb_samples(in, inPacket.data.size(),setup.samplerate) << "samples";
qInfo(logAudio()) << "Opus Packet Received: << " << opus_packet_get_nb_channels(in)
<< "channels, " << opus_packet_get_nb_samples(in, inPacket.data.size(),setup.samplerate)
<< "samples" << opus_decoder_get_nb_samples(decoder,in,inPacket.data.size()) << "decoded samples";
qInfo(logAudio()) << "Radio: channels" << setup.radioChan << "samplerate" << setup.samplerate;
/* Decode the frame. */
//QByteArray outPacket(this->chunkSize * sizeof(qint16) * setup.radioChan, (char)0xff); // Preset the output buffer size.
QByteArray outPacket(this->chunkSize * sizeof(qint16) * setup.radioChan, (char)0xff); // Preset the output buffer size.
QByteArray outPacket((setup.samplerate / 50) * sizeof(qint16) * setup.radioChan, (char)0xff); // Preset the output buffer size.
qint16* out = (qint16*)outPacket.data();
int nSamples = 0;
if (lastSentSeq > 0 && lastSentSeq+1 < inPacket.seq)
{
nSamples = opus_decode(decoder, NULL, 0, out, this->chunkSize, 1);
nSamples = opus_decode(decoder, NULL, 0, out, (setup.samplerate / 50), 1);
}
else {
nSamples = opus_decode(decoder, in, inPacket.data.size(), out, this->chunkSize, 0);
nSamples = opus_decode(decoder, in, inPacket.data.size(), out, (setup.samplerate / 50), 0);
}
if (nSamples < 0)
@ -527,7 +521,7 @@ void audioHandler::incomingAudio(audioPacket inPacket)
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decoded" << inPacket.data.size() << "bytes, into" << outPacket.length() << "bytes";
inPacket.data.clear();
inPacket.data = outPacket; // Replace incoming data with converted.
qint16* in16 = (qint16*)inPacket.data.data();
//qint16* in16 = (qint16*)inPacket.data.data();
//for (int i = 0; i < inPacket.data.length() / 2; i++)
// in16[i] = qToLittleEndian(in16[i]);
}
@ -700,7 +694,7 @@ void audioHandler::getNextAudioChunk(QByteArray& ret)
QByteArray outPacket(1275, (char)0xff); // Preset the output buffer size to MAXIMUM possible Opus frame size
unsigned char* out = (unsigned char*)outPacket.data();
int nbBytes = opus_encode(encoder, in, this->chunkSize, out, outPacket.length());
int nbBytes = opus_encode(encoder, in, (setup.samplerate / 50), out, outPacket.length());
if (nbBytes < 0)
{
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus encode failed:" << opus_strerror(nbBytes);