// testFile.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Windows.h"
#include "Mmsystem.h"
#pragma comment(lib, "Winmm.lib")
int main(int argc, char* argv[])
{
printf("Hello World!\n");
/*
FILE * h = fopen("c:\\pp.t","wb+");
DWORD tmp = mmioFOURCC('W','A','V','E');
fwrite(&tmp,sizeof(DWORD),1,h);
fclose(h);
*/
WAVEFORMATEX wfx;
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.cbSize=0 ;
wfx.wFormatTag=1 ;
wfx.wBitsPerSample=16 ;
wfx.nChannels=2 ;
wfx.nSamplesPerSec=22050 ;
wfx.nAvgBytesPerSec=44100 ;
wfx.nBlockAlign=4 ;
HMMIO m_hWaveFile;
MMCKINFO m_MMCKInfoParent;
MMCKINFO m_MMCKInfoChild;
m_hWaveFile = ::mmioOpen("c:\\p1p.t", NULL, MMIO_CREATE|MMIO_WRITE|MMIO_EXCLUSIVE|MMIO_ALLOCBUF);
ZeroMemory ( &m_MMCKInfoParent, sizeof(MMCKINFO) );
m_MMCKInfoParent.fccType = mmioFOURCC('W','A','V','E');//四个字符合成一个DWORD四字节编码,放到一个
MMRESULT mmResult = ::mmioCreateChunk( m_hWaveFile, &m_MMCKInfoParent, MMIO_CREATERIFF);
ZeroMemory ( &m_MMCKInfoChild, sizeof(MMCKINFO) );
m_MMCKInfoChild.ckid = mmioFOURCC('f','m','t',' ');
m_MMCKInfoChild.cksize = sizeof(WAVEFORMATEX) + wfx.cbSize;
mmResult = ::mmioCreateChunk(m_hWaveFile, &m_MMCKInfoChild, 0);
mmResult = ::mmioWrite(m_hWaveFile, (char*)&wfx, sizeof(WAVEFORMATEX) + wfx.cbSize);
mmResult = ::mmioAscend(m_hWaveFile, &m_MMCKInfoChild, 0);
m_MMCKInfoChild.ckid = mmioFOURCC('d', 'a', 't', 'a');
mmResult = ::mmioCreateChunk ( m_hWaveFile, &m_MMCKInfoChild, 0 );
::mmioFlush(m_hWaveFile,1);
return 0;
}
亲测:写一个RIFF文件的头
最新推荐文章于 2024-08-27 04:12:17 发布
这是一个RIFF文件的头,数据部分未写,实现这个功能的简单代码如下:
把一个WAV文件和自己存的比较,如下图: