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. Get sound level from audio input
QtWS25 Last Chance

Get sound level from audio input

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.1k Views
  • 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.
  • K Offline
    K Offline
    kamac
    wrote on last edited by
    #1

    Hey there.

    What would be the most simpliest way of getting the sound level (or rather, I suppose it'd be a function that'd process audio data) form the default input device?

    I've found examples, but they're so overcomplicated.. I just need to detect sound "loudness".

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

      Hi,

      The most straightforward way would be to do the math yourself on the data from coming from QAudioInput

      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
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi,

        What do you want to do with the information about sound loudness? Do you need it to be very accurate? Or do you just need it to be able to tell the difference between a "loud input" and "soft input"?

        There are many ways to measure "loudness" -- e.g. sound intensity level, sound power level, sound pressure level, etc. Is there a particular one that you want? (Note that a "sound level meter" measures sound pressure level)

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kamac
          wrote on last edited by
          #4

          I'm not really sure - I'm quite inexperienced with audio, but I need a bar that displays sound "loudness" like that when you click the sound icon in the right-bottom corner on windows, to adjust your sound level. It has a gray bar jumping up & down that displays what appears to be loudness.

          I suppose that I just want sample value. Aka something like this:

          @// "loudness" in percent
          float loudness = abs(sample) / std::numeric_limits<decltype(sample)>::max() * 100.0f;@

          That is how I at the moment calculate "loudness" in my other program, not Qt related. I suppose this could be wrong though.. I know like, nothing about audio. I've no idea how would I get intensity level or pressure or any of those things. I just need a reliable way to detect sound loudness - if you can tell me what would be a good way, then I'd be grateful (and I'd use that in my other non Qt related program aswell, instead of the current way, since I guess the current way is wrong)

          @EDIT

          Oh, I've found this:
          http://cnx.org/contents/031da8d3-b525-429c-80cf-6c8ed997733a@8.8:131

          Could prove quite useful. I suppose I just need to process captured audio samples then.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamac
            wrote on last edited by
            #5

            Okay, nevermind what I wrote before - what I need now is to somebody to tell me how would I process audio samples as it records them.

            At the moment, I've setup QAudioInput this way:

            @QAudioFormat format;
            // set up the format you want, eg.
            format.setSampleRate(44100);
            format.setChannelCount(1);
            format.setSampleSize(16);
            format.setCodec("audio/pcm");
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
            if (!info.isFormatSupported(format)) {
            format = info.nearestFormat(format);
            }
            m_audioInput = new QAudioInput(format,NULL);
            QTimer::singleShot(3000, this, SLOT(resetRecording()));
            m_ioDevice = m_audioInput->start();@

            and in resetRecording(), I've this:

            @m_audioInput->reset();@

            But I'm not really sure how to process that data as it records. Should I start a new thread that'd constantly check if m_ioDevice has any bytes to read, and if yes, process them?

            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