Following is what I have tried.
#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);
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;
}
}
#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);
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;
}
}
To copy to clipboard, switch view to plain text mode
Following is the output of the program
Device name in: "Line (2- USB Audio Device)"
Device name out: "Speakers (Realtek High Definiti"
jjjjjj
Device name in: "Line (2- USB Audio Device)"
Device name out: "Speakers (Realtek High Definiti"
jjjjjj
To copy to clipboard, switch view to plain text mode
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.
Bookmarks