码迷,mamicode.com
首页 > 其他好文 > 详细

Qt由pcm数据生成wav文件

时间:2014-05-09 05:01:23      阅读:434      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   width   c   2014   

bubuko.com,布布扣

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();
}

Qt由pcm数据生成wav文件,布布扣,bubuko.com

Qt由pcm数据生成wav文件

标签:style   blog   http   width   c   2014   

原文地址:http://www.cnblogs.com/danju/p/3716194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!