How to playback raw audio data files?



  • 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);

  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.