[Interest] Receiving audio through USB frame grabber and playing it
Anisha Kaul
born.rebel.83 at gmail.com
Fri Aug 12 08:32:18 CEST 2016
Thanks for the response and apologies for my error.
This morning I discovered that I was able to hear on 24 bit samples but not
on 16 bit sample because I hadn't raised volume to its maximum.
Now, with 16 bit samples I am able to hear the "buzzing sound". Nothing
more than that.
Now the settings are as follows:
desiredFormat1.setChannelCount(2);
desiredFormat1.setCodec("audio/pcm");
desiredFormat1.setSampleType(QAudioFormat::UnSignedInt);
desiredFormat1.setSampleRate(44100);
desiredFormat1.setSampleSize(16);
I do not know whether I use unsigned int, or signed int? How is that
decided? anyways I tried both, it didn't work.
On 12 August 2016 at 11:01, Maurice Kalinowski <Maurice.Kalinowski at qt.io>
wrote:
> 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.io at qt-
> project.org] *On Behalf Of *Anisha Kaul
> *Sent:* Thursday, August 11, 2016 5:40 PM
> *To:* interest at 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
>
--
Anisha Kaul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160812/59cb22bf/attachment.html>
More information about the Interest
mailing list