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. QAudioInput "Unknown Error"
Forum Updated to NodeBB v4.3 + New Features

QAudioInput "Unknown Error"

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 476 Views 1 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.
  • S Offline
    S Offline
    smrk007
    wrote on last edited by
    #1

    I'm trying to read audio data from a microphone using the QT API, and have been having some trouble with setting up a QIODevice that will let me read the data into a buffer.

    Below is my existing code:

    int main() {
    QAudioInput *audio;
    
    // Specifying format
    QAudioFormat format;
    format.setSampleRate(16000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);
    
    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    qWarning() << "Device being used:" << info.deviceName();
    
    if (!info.isFormatSupported(format)) {
        qWarning() << "Default format not supported, trying to use the nearest.";
        format = info.nearestFormat(format);
    }
    
    // Setting up the input
    audio = new QAudioInput(format);
    qWarning() << "\nAudio initialisation error:" << audio->error();
    qWarning() << "Audio initialisation state:" << audio->state() << "\n";
    
    
    QIODevice *inputStream = audio->start();
    qWarning() << "Audio stream start error:" << audio->error();
    qWarning() << "Audio stream start state:" << audio->state() << "\n";
    
    if (inputStream->waitForReadyRead(1000) == false) {
        qWarning() << inputStream->errorString();
        exit(1);
    }
    
    char input_data[512];
    while (true) {
        inputStream->read(input_data,512);
    }
    
    return 0;
    }
    

    My output when I run is:

    Device being used: "Built-in Microphone"
    
    Audio initialisation error: NoError
    Audio initialisation state: StoppedState 
    
    QObject::startTimer: Timers can only be used with threads started with QThread
    Audio stream start error: NoError
    Audio stream start state: IdleState 
    
    "Unknown error"
    

    I'm sure part of the problem is in the QObject::startTimer error, which clearly has to do with something that is happening inside of the QAudioInput object, but I have not been able to trace where this is coming from within the QAudioInput object by looking through the documentation.

    In summary, what I'd like to know:

    • What is happening inside of QAudioInput when I call start(), and why would it cause the warning shown above?
    • Where could I find the implementation of the start() function so that I can see what's happening under the hood?
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      First thing, your not creating a QCoreApplication as the first step in your application, therefore Qt can't initialise it's internal state. Then you use a blocking loop so Qt wouldn't be able to work since you'd be strangulating the event loop. Finally, you don't start the event loop, so Qt can't do it's work.

      The QAudioInput documentation shows some basics to get you started.

      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

      • Login

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