[Interest] Receiving audio through USB frame grabber and playing it
Anisha Kaul
born.rebel.83 at gmail.com
Thu Aug 11 17:39:33 CEST 2016
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160811/0f7517ef/attachment.html>
More information about the Interest
mailing list