PDA

View Full Version : Receiving audio through USB frame grabber and playing it



TheIndependentAquarius
10th August 2016, 12:09
Following is what I have tried.



#include "audiooutput.h"

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

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


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

d = l[0];

QAudioFormat format;
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(format)) {
format = info.nearestFormat(format);
}

audioInpu = new QAudioInput(d, format, this);
audioInpu->setVolume(100);
//QIODevice *p = audioInpu->start();

QAudioFormat format1;
QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
if (!info1.isFormatSupported(format1)) {
format1 = info.nearestFormat(format1);
}

audioOutpu = new QAudioOutput(format1, this);
connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
audioOutpu->setVolume(100);
audioOutpu->start( audioInpu->start());
}

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

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

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


Following is the output of the program


Device name in: "Line (2- USB Audio Device)"
Device name out: "Speakers (Realtek High Definiti"
jjjjjj


The input and output devices are being detected as you can see in the output, but "jjjjjj" being printed means "idle state".

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.

anda_skoa
10th August 2016, 13:48
The input and output devices are being detected as you can see in the output, but "jjjjjj" being printed means "idle state".

Which is logical given that your code does not attempt to play anything.



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.


My guess you be that you create a QAudioInput and pass the QIODevice you get from its start() method to the start(QIODevice*) of the QAudioOutput or vice versa.

Cheers,
_

TheIndependentAquarius
10th August 2016, 15:44
Thanks for the response.

Why did you say that I am not attempting to play anything? I have called that start function of QAudioOutput. What else is the way?

anda_skoa
10th August 2016, 17:03
Right, sorry!

I must have overlooked that you are already passing the input's device to the output's start as suggested.

Hmm, have you checked the state transitions of the audio input object?

Are the two formats equal?

Cheers,
_

TheIndependentAquarius
10th August 2016, 17:22
I request you to explain me what do you mean by state transitions?

Also, you mean I should check whether input and output formats are same? But, I have used their default states.

I have also checked the input device through vlc player. It does work properly.

TheIndependentAquarius
11th August 2016, 10:00
Well, now I am explicitly setting the formats:

For audio input:

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

For audio output:


desiredFormat1.setChannelCount(5);
desiredFormat1.setCodec("audio/pcm");
desiredFormat1.setSampleType(QAudioFormat::SignedI nt);
desiredFormat1.setSampleRate(44100);
desiredFormat1.setSampleSize(24);


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 means buzzing sound, real audio is not being heard in any case.

Audio Input is being shown idle now.

Can you help?

anda_skoa
11th August 2016, 10:30
My guess is that the formats need to be the same for the simple "hand over device" approach to work.

Different formats will likely need to be made compatible by converting the input data to fit the output's needs.

Cheers,
_

TheIndependentAquarius
11th August 2016, 10:35
Different formats will likely need to be made compatible by converting the input data to fit the output's needs.

what would be the way to do that here?

anda_skoa
11th August 2016, 13:25
No idea, never used that before.

Cheers,
_