zoukankan      html  css  js  c++  java
  • Qt由pcm数据生成wav文件

    void AudioGrabber::saveWave(const QString &fileName, const QByteArray &raw, const QAudioFormat &format)
    {
        typedef struct{
            char riff_fileid[4];//"RIFF"
            DWORD riff_fileLen;
            char waveid[4];//"WAVE"

            char fmt_chkid[4];//"fmt"
            DWORD fmt_chkLen;

            WORD    wFormatTag;        /* format type */
            WORD    nChannels;         /* number of channels (i.e. mono, stereo, etc.) */
            DWORD   nSamplesPerSec;    /* sample rate */
            DWORD   nAvgBytesPerSec;   /* for buffer estimation */
            WORD    nBlockAlign;       /* block size of data */
            WORD    wBitsPerSample;


            char data_chkid[4];//"DATA"
            WORD data_chkLen;
        }WaveHeader;

        WaveHeader wh={0};
        strcpy(wh.riff_fileid, "RIFF");
        wh.riff_fileLen = raw.length() + 32;
        strcpy(wh.waveid, "WAVE");

        strcpy(wh.fmt_chkid, "fmt ");
        wh.fmt_chkLen = 16;

        wh.wFormatTag = WAVE_FORMAT_PCM;
        wh.nChannels = format.channels();
        wh.nSamplesPerSec = format.frequency();
        wh.wBitsPerSample = format.sampleSize();
        wh.nBlockAlign =wh.nChannels*wh.wBitsPerSample/8;
        wh.nAvgBytesPerSec =   wh.nBlockAlign*wh.nSamplesPerSec;

        strcpy(wh.data_chkid, "data");
        wh.data_chkLen = raw.length();

        QFile f(fileName);
        f.open(QFile::WriteOnly);
        f.write((char *)&wh, sizeof(wh));
        f.write(raw);
        f.close();
    }

  • 相关阅读:
    『题解』POJ1753 Flip Game
    『数论』乘法逆元
    『数据结构』RMQ问题
    UVA 253 Cube painting 【数学】
    POJ 1852 Ants 【水+Trick+贪心】
    POJ 2955 Brackets 【区间DP】
    LOJ 1422 Halloween Costumes【区间DP】
    HDU 4193 Non-negative Partial Sums 【单调队列】
    CodeForces-545C Woodcutters 【贪心+机智】
    CodeForces 19D A and B and Interesting Substrings 【前缀和】
  • 原文地址:https://www.cnblogs.com/danju/p/3716194.html
Copyright © 2011-2022 走看看