首页 > 其他 > 详细

Qt由pcm数据生成wav文件

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

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文件

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!