Subversion Repositories tpanel

Rev

Rev 474 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 474 Rev 477
Line 168... Line 168...
168
        {
168
        {
169
            const QList<QAudioDevice> audioDevices = QMediaDevices::audioInputs();
169
            const QList<QAudioDevice> audioDevices = QMediaDevices::audioInputs();
170
 
170
 
171
            for (const QAudioDevice &device : audioDevices)
171
            for (const QAudioDevice &device : audioDevices)
172
            {
172
            {
173
                MSG_DEBUG("ID: " << device.id().toStdString());
173
                MSG_DEBUG("In ID: " << device.id().toStdString());
174
                MSG_DEBUG("Description: " << device.description().toStdString());
174
                MSG_DEBUG("In Description: " << device.description().toStdString());
175
                MSG_DEBUG("Is default: " << (device.isDefault() ? "Yes" : "No"));
175
                MSG_DEBUG("In Is default: " << (device.isDefault() ? "Yes" : "No"));
176
            }
176
            }
177
        }
177
        }
178
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
178
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
179
#   if QT_VERSION_CHECK(6, 6, 0)
179
#   if QT_VERSION_CHECK(6, 6, 0)
180
        QMicrophonePermission microphonePermission;
180
        QMicrophonePermission microphonePermission;
Line 205... Line 205...
205
        {
205
        {
206
            const QList<QAudioDevice> audioDevices = QMediaDevices::audioOutputs();
206
            const QList<QAudioDevice> audioDevices = QMediaDevices::audioOutputs();
207
 
207
 
208
            for (const QAudioDevice &device : audioDevices)
208
            for (const QAudioDevice &device : audioDevices)
209
            {
209
            {
210
                MSG_DEBUG("ID: " << device.id().toStdString());
210
                MSG_DEBUG("Out ID: " << device.id().toStdString());
211
                MSG_DEBUG("Description: " << device.description().toStdString());
211
                MSG_DEBUG("Out Description: " << device.description().toStdString());
212
                MSG_DEBUG("Is default: " << (device.isDefault() ? "Yes" : "No"));
212
                MSG_DEBUG("Out Is default: " << (device.isDefault() ? "Yes" : "No"));
213
 
213
 
214
                if (device.isDefault())
214
                if (device.isDefault())
215
                    mAudioMicDevice = device;
215
                    mAudioMicDevice = device;
216
            }
216
            }
217
        }
217
        }
Line 361... Line 361...
361
                }
361
                }
362
                else if (len == 0)
362
                else if (len == 0)
363
                {
363
                {
364
                    if (!mMicOpen)
364
                    if (!mMicOpen)
365
                    {
365
                    {
366
                        QByteArray buffer(DATA_SIZE, uLawEncode(0));
366
                        QByteArray buffer(DATA_SIZE, uLawEncodeDigital(0));
367
                        QByteArray wbuf(PACKET_SIZE, 0);
367
                        QByteArray wbuf(PACKET_SIZE, 0);
368
                        len = getNextBlock(&wbuf, buffer);
368
                        len = getNextBlock(&wbuf, buffer);
369
                        MSG_DEBUG("Writing bytes: " << len);
369
                        MSG_DEBUG("Writing bytes: " << len);
370
                        mUdpTalker->write(wbuf.data(), len);
370
                        mUdpTalker->write(wbuf.data(), len);
371
                        TError::logHex(wbuf.data(), len);
371
                        TError::logHex(wbuf.data(), len);
Line 539... Line 539...
539
            for (qsizetype i = 0; i < data.size(); ++i)
539
            for (qsizetype i = 0; i < data.size(); ++i)
540
            {
540
            {
541
                if (i < HEADER_SIZE)
541
                if (i < HEADER_SIZE)
542
                    continue;
542
                    continue;
543
 
543
 
544
                uint16_t word = uLawDecode(data[i]);
544
                uint16_t word = muLawToLinear(data[i]);
545
                uint8_t hbyte = word >> 8;
545
                uint8_t hbyte = word >> 8;
546
                uint8_t lbyte = word;
546
                uint8_t lbyte = word;
547
                mReadBuffer.append(hbyte);
547
                mReadBuffer.append(hbyte);
548
                mReadBuffer.append(lbyte);
548
                mReadBuffer.append(lbyte);
549
            }
549
            }
Line 665... Line 665...
665
        case QAbstractSocket::TemporaryError:                   MSG_ERROR(msg << ": A temporary error occurred (e.g., operation would block and socket is non-blocking)."); break;
665
        case QAbstractSocket::TemporaryError:                   MSG_ERROR(msg << ": A temporary error occurred (e.g., operation would block and socket is non-blocking)."); break;
666
        case QAbstractSocket::UnknownSocketError:               MSG_ERROR(msg << ": An unidentified error occurred."); break;
666
        case QAbstractSocket::UnknownSocketError:               MSG_ERROR(msg << ": An unidentified error occurred."); break;
667
    }
667
    }
668
}
668
}
669
 
669
 
670
int16_t TQIntercom::uLawDecode(int8_t number)
-
 
671
{
-
 
672
//    DECL_TRACER("TQIntercom::uLawDecode(int8_t number)");
-
 
673
 
-
 
674
    const uint16_t MULAW_BIAS = 33;
-
 
675
    uint8_t sign = 0, position = 0;
-
 
676
    int16_t decoded = 0;
-
 
677
    number = ~number;
-
 
678
 
-
 
679
    if (number & 0x80)
-
 
680
    {
-
 
681
        number &= ~(1 << 7);
-
 
682
        sign = -1;
-
 
683
    }
-
 
684
 
-
 
685
    position = ((number & 0xF0) >> 4) + 5;
-
 
686
    decoded = ((1 << position) | ((number & 0x0F) << (position - 4)) | (1 << (position - 5))) - MULAW_BIAS;
-
 
687
    return (sign == 0) ? (decoded) : (-(decoded));
-
 
688
}
-
 
689
 
-
 
690
int8_t TQIntercom::uLawEncode(int16_t number)
-
 
691
{
-
 
692
    //    DECL_TRACER("TQIntercom::uLawEncode(int16_t number)");
-
 
693
 
-
 
694
    const uint16_t MULAW_MAX = 0x1FFF;
-
 
695
    const uint16_t MULAW_BIAS = 33;
-
 
696
    uint16_t mask = 0x1000;
-
 
697
    uint8_t sign = 0;
-
 
698
    uint8_t position = 12;
-
 
699
    uint8_t lsb = 0;
-
 
700
 
-
 
701
    if (number < 0)
-
 
702
    {
-
 
703
        number = -number;
-
 
704
        sign = 0x80;
-
 
705
    }
-
 
706
 
-
 
707
    number += MULAW_BIAS;
-
 
708
 
-
 
709
    if (number > MULAW_MAX)
-
 
710
        number = MULAW_MAX;
-
 
711
 
-
 
712
    for (; ((number & mask) != mask && position >= 5); mask >>= 1, position--)
-
 
713
        ;
-
 
714
 
-
 
715
    lsb = (number >> (position - 4)) & 0x0f;
-
 
716
    return (~(sign | ((position - 5) << 4) | lsb));
-
 
717
}
-
 
718
 
-
 
719
long TQIntercom::getNextBlock(QByteArray* target, const QByteArray& data)
670
long TQIntercom::getNextBlock(QByteArray* target, const QByteArray& data)
720
{
671
{
721
    DECL_TRACER("TQIntercom::getNextBlock(QByteArray* target, const QByteArray& data)");
672
    DECL_TRACER("TQIntercom::getNextBlock(QByteArray* target, const QByteArray& data)");
722
 
673
 
723
    if (!target)
674
    if (!target)
Line 810... Line 761...
810
            if (bigEndian)
761
            if (bigEndian)
811
                word = ((hbyte << 8) & 0xff00) | lbyte;
762
                word = ((hbyte << 8) & 0xff00) | lbyte;
812
            else
763
            else
813
                word = ((lbyte << 8) & 0xff00) | hbyte;
764
                word = ((lbyte << 8) & 0xff00) | hbyte;
814
 
765
 
815
            *(data+posData) = uLawEncode(word);
766
            *(data+posData) = linearToMuLaw(word);
816
            posData++;
767
            posData++;
817
        }
768
        }
818
 
769
 
819
        mBuffer.remove(0, posBuffer);
770
        mBuffer.remove(0, posBuffer);
820
        total = posData;
771
        total = posData;
Line 838... Line 789...
838
{
789
{
839
//    DECL_TRACER("TMicrophone::bytesAvailable() const");
790
//    DECL_TRACER("TMicrophone::bytesAvailable() const");
840
 
791
 
841
    return (mBuffer.size() / 2) + QIODevice::bytesAvailable();
792
    return (mBuffer.size() / 2) + QIODevice::bytesAvailable();
842
}
793
}
843
 
-
 
844
int8_t TMicrophone::uLawEncode(int16_t number)
-
 
845
{
-
 
846
//    DECL_TRACER("_audioIO::uLawEncode(int16_t number)");
-
 
847
 
-
 
848
    const uint16_t MULAW_MAX = 0x1FFF;
-
 
849
    const uint16_t MULAW_BIAS = 33;
-
 
850
    uint16_t mask = 0x1000;
-
 
851
    uint8_t sign = 0;
-
 
852
    uint8_t position = 12;
-
 
853
    uint8_t lsb = 0;
-
 
854
 
-
 
855
    if (number < 0)
-
 
856
    {
-
 
857
        number = -number;
-
 
858
        sign = 0x80;
-
 
859
    }
-
 
860
 
-
 
861
    number += MULAW_BIAS;
-
 
862
 
-
 
863
    if (number > MULAW_MAX)
-
 
864
        number = MULAW_MAX;
-
 
865
 
-
 
866
    for (; ((number & mask) != mask && position >= 5); mask >>= 1, position--)
-
 
867
        ;
-
 
868
 
-
 
869
    lsb = (number >> (position - 4)) & 0x0f;
-
 
870
    return (~(sign | (((position - 5) << 4) & 0xf0) | lsb));
-
 
871
}
-