Important: Please read the Qt Code of Conduct -

How can read data from .wav file with true rate?

  • I want to read the .wav file at the written speed, I used part of the QT Spectrum project
    (wavfile class) in my project and I did not understand how the QT spectrum project handles reading speed, I do this but it's not work correctly, I think the timer not set correctly, Is there a better way to do this?

    QByteArray ReadFile::ReadData()
        QTimer* timer = new QTimer(this);
        connect(timer, &QTimer::timeout, this, &ReadFile::fetchData);
        QString dataFilePath = QDir::homePath().append("/sample.wav");
        mDataFile = new QFile(dataFilePath);
        QByteArray bytes = mDataFile->readAll();
        double DemodSize = 32768;
            SampleRate = waveFile->m_fileFormat.sampleRate();
            sample_size = waveFile->m_fileFormat.sampleSize();
            NumChannel = waveFile->m_fileFormat.channelCount();
            if(NumChannel == 1)
                DemodSize = DemodSize/4;
            else if(NumChannel == 2)
                DemodSize = DemodSize/2;
           int  seek = 44;
            dataRead = sample_size * NumChannel / 8;  //size of each data
        if(SampleRate>0 && DemodSize>0)
            timer->start(DemodSize/SampleRate);   //timer for each reading
        return byte;
    void ReadFile::fetchData()
        for (int i = 0; i <FFTvalue; i++) {    //loop use FFT size
            QByteArray iq= mDataFile->read(dataRead);
            mDataFile->seek(mDataFile->pos()+dataRead);  //for read next data
         //add to buffer

  • Lifetime Qt Champion


    Did you check the values you actually get ?
    Do they make sense ?

  • @SGaist Yes, I print it, no problem
    I'm not sure if my method is correct

  • Lifetime Qt Champion

    Can you described exactly what is happening that is wrong ?

Log in to reply