Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Open a microphone device with QAudioInput
Forum Updated to NodeBB v4.3 + New Features

Open a microphone device with QAudioInput

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 4.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arthux
    wrote on last edited by
    #1

    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 !

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arthux
        wrote on last edited by
        #3

        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 ...

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Arthux
          wrote on last edited by Arthux
          #4

          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 ...

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Did you try to enumarate all the available inputs ? Does the microphone appear in that list ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • A Offline
              A Offline
              Arthux
              wrote on last edited by
              #6

              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 ?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved