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. How to playback raw audio data files?
QtWS25 Last Chance

How to playback raw audio data files?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtmultimediaaudio
2 Posts 2 Posters 1.4k 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.
  • S Offline
    S Offline
    scottnat
    wrote on 5 Oct 2017, 07:40 last edited by
    #1

    So first of all:
    I have a written some 40 frames of audio data to a text file in DWORD format.
    From the text file using it as a QIODevice.
    But i am unable to play back due to the backend not supporting raw audio. Is there any work around?
    Thanks

    
    QString myfilename="DataAudioData123.txt";
     QFile sourceFile( myfilename );
     sourceFile.open(QIODevice::ReadWrite);
    
     for (int k = 0; k < frameMax ; k++){
      qDebug()<<audioData[k];
          QTextStream stream( &sourceFile );
          stream << audioData[k]  << endl;
     }
    
     QAudioOutput* audio; // class member.
    
     QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    
         QAudioFormat format;
         // Set up the format, eg.
         format.setSampleRate(mSampleRate);
         format.setChannelCount(1);
         format.setSampleSize(16);
         format.setCodec("audio/pcm");
         format.setByteOrder(QAudioFormat::BigEndian);
         format.setSampleType(QAudioFormat::UnSignedInt);
    
         if (!info.isFormatSupported(format)) {
             qWarning() << "Raw audio format not supported by backend, cannot play audio.";
             return;
         }
    
         audio = new QAudioOutput(format, this);
         connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
         audio->start(&sourceFile);
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Oct 2017, 22:00 last edited by
      #2

      Hi and welcome to devnet,

      You should check what your device support, QAudioDeviceInfo gives you all the various channel counts, sample sizes etc. that are supported by the device you want to use.

      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

      2/2

      5 Oct 2017, 22:00

      • Login

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