Unsolved Open a microphone device with QAudioInput
-
Hello everybody,
I try to open a microphone device under ubuntu like the tutorial : http://doc.qt.io/qt-5/qtmultimedia-multimedia-spectrum-example.html
void AudioRecorder::startListening(){ if(m_audioInput == NULL){ m_format.setChannelCount(1); m_format.setCodec("audio/pcm"); m_format.setSampleSize(16); m_format.setSampleRate(48000); // Select the device that I want QList<QAudioDeviceInfo> availableDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for(int i=0;i<availableDevices.size();i++){ qDebug() << availableDevices.at(i).deviceName(); if(!availableDevices.at(i).deviceName().compare("plughw:CARD=C525,DEV=0")){ //plughw:CARD=C525,DEV=0 plughw:CARD=r0,DEV=0 m_audioInputDevice = availableDevices.at(i); qDebug() << "Selected device :" << m_audioInputDevice.deviceName(); break; } } // Check format is OK if(!m_audioInputDevice.isFormatSupported(m_format)){ qWarning() << "Default format not supported, trying to use the nearest."; m_format = m_audioInputDevice.nearestFormat(m_format); qDebug() << "Codec:" << m_format.codec(); qDebug() << "Channel count:" << m_format.channelCount(); qDebug() << "Sample size:" << m_format.sampleSize(); qDebug() << "Sample rate:" << m_format.sampleRate(); } if(m_format.isValid()){ // Initialisation du micro m_audioInput = new QAudioInput(m_audioInputDevice,m_format,this); m_audioInput->setNotifyInterval(100); connect(m_audioInput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(audioStateChanged(QAudio::State))); m_audioInputIODevice = m_audioInput->start(); qDebug() << m_audioInput->error(); connect(m_audioInputIODevice,SIGNAL(readyRead()),this,SLOT(audioDataReady())); qDebug() << "Start listening event" << m_audioInputIODevice << m_audioInput; } else { qCritical() << "Problem audio format"; } } }
The problem is the fonction "m_audioInput->start();" return always null pointer and I have an error for connect "connect(m_audioInputIODevice,SIGNAL(readyRead()),this,SLOT(audioDataReady()));" :
QObject::connect: Cannot connect (null)::readyRead() to AudioRecorder::audioDataReady()
Type variables are :
QAudioInput *m_audioInput; QIODevice *m_audioInputIODevice; QAudioDeviceInfo m_audioInputDevice; QAudioFormat m_format;
If someone can tell me where is my mistake ...
Thank a lot !
-
Hi
I would also check the error stuff and see if it says
http://doc.qt.io/qt-5/qaudioinput.html#error
If it gives QAudio::OpenError
or why it cannot start.I assume that
qtmultimedia-multimedia-spectrum-example
Does in fact fully work so its not a driver issue. -
I check the error with :
qDebug() << m_audioInput->error();
return :
NoError
I try to change the device and it works with alsa_input.pci-0000_00_1b.0.analog-stereo. But it's not the microphone that I want to used.
I think the microphone i want to used, it is not detected by alsa library ...How can I do the detection of the microphone to alsa library ?
Knowing the microphone is detected with the alsamixer application ...
-
In fact, when i use QAudioRecorder I must put "alsa:plughw:CARD=C525,DEV=0"and when i use QAudioInput I must put "alsa_input.usb-046d_HD_Webcam_C525_D01D63D0-00.analog-mono".
Why ? And have not always the "alsa_input.usb ..." for all input device ...
-
Hi,
Did you try to enumarate all the available inputs ? Does the microphone appear in that list ?
-
Yes :
"default" "pulse" "sysdefault:CARD=C525" "front:CARD=C525,DEV=0" "surround21:CARD=C525,DEV=0" "surround40:CARD=C525,DEV=0" "surround41:CARD=C525,DEV=0" "surround50:CARD=C525,DEV=0" "surround51:CARD=C525,DEV=0" "surround71:CARD=C525,DEV=0" "iec958:CARD=C525,DEV=0" "dmix:CARD=C525,DEV=0" "dsnoop:CARD=C525,DEV=0" "hw:CARD=C525,DEV=0" "plughw:CARD=C525,DEV=0" "sysdefault:CARD=r0" "front:CARD=r0,DEV=0" "surround21:CARD=r0,DEV=0" "surround40:CARD=r0,DEV=0" "surround41:CARD=r0,DEV=0" "surround50:CARD=r0,DEV=0" "surround51:CARD=r0,DEV=0" "surround71:CARD=r0,DEV=0" "iec958:CARD=r0,DEV=0" "dmix:CARD=r0,DEV=0" "dsnoop:CARD=r0,DEV=0" "hw:CARD=r0,DEV=0" "plughw:CARD=r0,DEV=0" "alsa_output.0.analog-stereo.monitor" "alsa_input.usb-046d_HD_Webcam_C525_D01D63D0-00-C525.analog-mono" default input device "alsa_output.0.analog-stereo.monitor"
I think pulseaudio create :
"alsa_output.0.analog-stereo.monitor" // For stereo output "alsa_input.usb-046d_HD_Webcam_C525_D01D63D0-00-C525.analog-mono" // For the microphone of my webcam CARD=C525
But it does anything for the microphone CARD=r0 ....
I don't know why ... Do you how to create a device with pulseaudio ?