Have you considered converting manually between 16 and 24 bit samplesizes?

Obviously you pass the wrong sample size to the output, and that one takes data 
as is as this is just a byte stream. That is why you need to check that either 
the formats are compatible or do a conversion. This is nothing Qt Multimedia 
should handle by default.

“but input works only with 16 and output only with 24.”
How did you identify/verify this?

Maurice


From: Interest 
[mailto:interest-bounces+maurice.kalinowski=qt...@qt-project.org] On Behalf Of 
Anisha Kaul
Sent: Thursday, August 11, 2016 5:40 PM
To: interest@qt-project.org
Subject: [Interest] Receiving audio through USB frame grabber and playing it


HI,

Following is the re-producable example:

**header file:********************************************************

    #ifndef AUDIOOUTPUT
    #define AUDIOOUTPUT

    #include <QQuickItem>
    #include <QAudioOutput>
    #include <QAudioInput>

    class Output: public QObject
    {
    private:
        Q_OBJECT

    public:
        Output();
        ~Output() {}

        QAudioOutput* audioOutpu;
        QAudioInput* audioInpu;

    public slots:
        handleStateChanged(QAudio::State newState);
        handleStateChanged0(QAudio::State newState);
    };

    #endif // AUDIOOUTPUT


**Source file:*****************************************************

    #include <QTimer>
    #include "audiooutput.h"

    Output::Output()
    {
        foreach (const QAudioDeviceInfo &deviceInfo, 
QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
            qDebug() << "Device name in: " << deviceInfo.deviceName();

        foreach (const QAudioDeviceInfo &deviceInfo, 
QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
            qDebug() << "Device name out: " << deviceInfo.deviceName();

        QAudioDeviceInfo d;
        QList<QAudioDeviceInfo> l = d.availableDevices(QAudio::AudioInput);

        qDebug() << l.first().supportedCodecs();
        qDebug() << l.first().supportedChannelCounts();
        qDebug() << l.first().supportedSampleTypes();
        qDebug() << l.first().supportedSampleRates();
        qDebug() << l.first().supportedSampleSizes();

        QAudioFormat desiredFormat;
        desiredFormat.setChannelCount(5);
        desiredFormat.setCodec("audio/pcm");
        desiredFormat.setSampleType(QAudioFormat::SignedInt);
        desiredFormat.setSampleRate(44100);
        desiredFormat.setSampleSize(16);

        QAudioDeviceInfo info(l.first());
        if (!info.isFormatSupported(desiredFormat)) {
               qWarning() << "Default format not supported, trying to use the 
nearest.";
               desiredFormat = info.nearestFormat(desiredFormat);
           }

        audioInpu = new QAudioInput(l.first(), desiredFormat, this);
        connect(audioInpu, SIGNAL(stateChanged(QAudio::State)), this, 
SLOT(handleStateChanged0(QAudio::State)));
        audioInpu->setVolume(500);

        QAudioDeviceInfo d1;
        QList<QAudioDeviceInfo> l1 = d1.availableDevices(QAudio::AudioOutput);
        qDebug() << "======================================================";
        qDebug() << l1.first().supportedCodecs();
        qDebug() << l1.first().supportedChannelCounts();
        qDebug() << l1.first().supportedSampleTypes();
        qDebug() << l1.first().supportedSampleRates();
        qDebug() << l1.first().supportedSampleSizes();

        QAudioFormat desiredFormat1;
        desiredFormat1.setChannelCount(5);
        desiredFormat1.setByteOrder(QAudioFormat::LittleEndian);
        desiredFormat1.setCodec("audio/pcm");
        desiredFormat1.setSampleType(QAudioFormat::SignedInt);
        desiredFormat1.setSampleRate(44100);
        desiredFormat1.setSampleSize(24);

        QAudioDeviceInfo info1(l1.first());
        if (!info1.isFormatSupported(desiredFormat1))
        {
               qWarning() << "Default format not supported, trying to use the 
nearest.";
               desiredFormat1 = info1.nearestFormat(desiredFormat1);
        }

        audioOutpu = new QAudioOutput(desiredFormat1, this);
        connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), this, 
SLOT(handleStateChanged(QAudio::State)));
        audioOutpu->setVolume(500);

        audioOutpu->start(audioInpu->start());
    }

    Output::handleStateChanged(QAudio::State newState)
    {
       switch (newState) {
        case QAudio::ActiveState:
            qDebug() << "active state out";
        break;

        case QAudio::IdleState:
            qDebug() <<"IdleState out";
            break;

        case QAudio::StoppedState:
            if (audioInpu->error() != QAudio::NoError)
            {
                qDebug() << "\naudio stopped: " <<audioInpu->error();
            }
            break;

        default:
            // ... other cases as appropriate
            break;
       }
    }

    Output::handleStateChanged0(QAudio::State newState)
    {
        switch (newState) {
            case QAudio::IdleState:
                qDebug() <<"IdleState inp";
                break;

            case QAudio::StoppedState:
                if (audioInpu->error() != QAudio::NoError)
                {
                    qDebug() << "\naudio stopped: " <<audioInpu->error();
                }
                break;

            default:
                // ... other cases as appropriate
                break;
        }
    }


**Output:********************************************

    QML debugging is enabled. Only use this in a safe environment.
    Device name in:  "Line (2- USB Audio Device)"
    Device name out:  "Speakers (Realtek High Definiti"
    ("audio/pcm")
    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)
    (SignedInt, UnSignedInt, Float)
    (8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 192000)
    (8, 16, 24, 32, 48, 64)
    ======================================================
    ("audio/pcm")
    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)
    (SignedInt, UnSignedInt, Float)
    (8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 192000)
    (8, 16, 24, 32, 48, 64)
    IdleState inp

***************************************************

As you can see that sample size for output is 24 and input is 16. The problem 
is that if I keep both these values same, no sound is produced.
I have tried with different variations of sample sizes, but input works only 
with 16 and output only with 24.

Works here means buzzing sound, real audio is not being heard in any case.

Audio Input is being shown idle now. Output state is being shown active.

The input and output devices are being detected as you can see in the output.

**Problem is that I don't know how to pass the audio input to the speakers. I 
cannot hear anything other than a buzzing sound.**

Please guide.



--
Anisha Kaul
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to