QT creator monitor audio input



  • Hello,
    I wonder is there any way to monitor audio input by using QAudioProbe with QAudioInput or QAudioDeviceInfo as a source?

    I know I can monitor by using by QAudioProbe with QAudioRecorder as a source, but in this case I also initialize recording to file and I want to prevent that.

    As I know QAudioProbe accept also QMediaObject as a source, but don't you know how to convert QAudioInput to QMediaObject?

    Yes I know there is documentation for QMediaObject and I can check, but I am totally begginer, and I am affraid that I would spend a lot of time to read whole documentation to understand and in the and I will fall with answer "No. It is not possible".

    So maybe some of you know the answer and be so kind to just inform me is it possible what I am asking or not? And If not, could you give any advice how to solve my issue?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What do you mean by monitor ?



  • Hello,
    thanks for your reply.
    By "monitor" I mean something like on that video: https://www.youtube.com/watch?v=JYqQCP0yo2o

    I know how to make it easly when I use QAudioRecorder as a source for QAudioProbe, something like that:
    QAudioProbe->setSource(QAudioRecorder); // It works great

    but that:
    QAudioProbe->setSource(QAudioInput); // That doesn't work

    I know QAudioProbe accepts as a source QAudioRecorder or QMediaObject. So the goal is how to convert QAudioInput to be QMediaObject?


  • Lifetime Qt Champion

    Then there's no real need for QAudioProbe in your case, you can process the audio data you get from QAudioInput.



  • Hello,
    great thanks for your reply, but could you give any advaice (not asking for solution but any advice) how to do that?

    And I still think I need QAudioProbe also because later I want also check and display the musical tone frequency of recorded audio. So don't you think it's good idea to use QAudioProbe? Or maybe for that case I don't need it also?


  • Lifetime Qt Champion

    You likely going to get stereo data most of the time then check the buffer size and you'll known how many audio frame you have in one sample, then convert its content in DB so you can then paint your scale based on that.

    As for audio probe, just keep the common code in one place so you can re-use it with your probe.



  • Hello,
    great thanks for your reply. I trained a little bit with QAudioProbe and now I think I understand it a little bit more.

    But I am not sure what you mean, and how to understand your answer.
    To be clear my code is:

    QAudioRecorder * audioRecorder = new QAudioRecorder(this);
            probe = new QAudioProbe;
            connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer)));
            probka->setSource(audioRecorder);
    

    And slot looks like that:

    void MainWindow::processBuffer(const QAudioBuffer& buffer)
    {
        qDebug() << buffer.byteCount();
        qDebug() << sizeof(buffer);
        qDebug() << buffer.frameCount();
    }
    

    And my doubts to your answer are:

    1. "You likely going to get stereo data most of the time..." - actually I am going to record only mono microphone signal, so why you suppose I going to get stereo?

    2. What do you mean "check buffer size"? If I use just regular C++ sizeof(QAudioBuffer) I get just a lot of eights, like that: 888888888888....
      But when I use QAudioBuffer.byteCount(); I get a lot of 4096.
      When I use buffer.frameCount(); I get a lot of 2048.

    3. What do you mean DB? Are you talking about decibels? So then we are not talking about frequency but about loudness/volume? Actually now I know how to get and set audio volume. As you told: I don't even need QAudioProbe. QAudioRecorder::Volume, and setVolume do the job. But now my issue is to get frequency of recorded audio. Something like in guitar tuner. And I have no idea how to get that. Even don't know if QAudioProbe can provide me that solution? Maybe I should focus on something totally differen?


  • Lifetime Qt Champion

    1. Most of the times people listen in stereo

    2. frameCount/byteCount

    3. Decibel indeed. The video you showed is a VU-meter so it's not showing the volume you set but the loudness of the sound at the volume you set. So in fact you'd like to make a Spectrogram ?



  • Hello,
    thanks for your reply.
    But actually I'm not sure what is frameCount and byteCount. It gives me always the same value. For frameCount it is 2048, and for byteCount it is 4096. But I have no idea how to take advantage of it? How to use those values?


  • Lifetime Qt Champion

    Frame count is the number of audio frames available in the buffer. Its value will depend on the format of the audio input. The bye count is the number of bytes of data in the buffer.



  • Hello, thanks for your repy,
    yes I think I understand what is frames count and byte count. But I have no idea how to use those valu to my issue. As you told they depend on the format of the audio input, and ones you set it they are always the same valu, so how I can take the advantage of it?

    For any help thanks in advance.
    Best Regards


  • Lifetime Qt Champion

    You then know how the data are arranged in your array as well as there range and the number of millisecond worth of them.