AxibugEmuOnline/References/virtuanessrc097-master/WaveRec.cpp
2024-08-05 17:58:53 +08:00

59 lines
2.5 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Wave record class
//
#include "WaveRec.h"
CWaveRec::CWaveRec()
{
::ZeroMemory( &wavefile, sizeof(wavefile) );
fp = NULL;
::CopyMemory( wavefile.tagRIFF, "RIFF", sizeof(wavefile.tagRIFF) );
::CopyMemory( wavefile.tagTYPE, "WAVEfmt ", sizeof(wavefile.tagTYPE) );
::CopyMemory( wavefile.tagDATA, "data", sizeof(wavefile.tagDATA) );
wavefile.dwChunkOffset = 0x0010;
wavefile.wCodingType = 0x0001;
}
CWaveRec::~CWaveRec()
{
if( fp )
Stop();
}
void CWaveRec::Start( LPSTR szFile, INT nSample, INT nBits, BOOL bStereo )
{
if( fp )
Stop();
if( (fp = ::fopen( szFile, "wb" )) ) {
wavefile.wChannel = bStereo?2:1;
wavefile.dwSample = nSample;
wavefile.wBits = nBits;
wavefile.wBytesPerSample = (WORD)(nBits>>3)*wavefile.wChannel;
wavefile.dwBytesPerSec = nSample*wavefile.wBytesPerSample;
}
}
void CWaveRec::Stop()
{
if( fp ) {
DWORD size = (DWORD)::ftell( fp );
wavefile.dwFileSize = (DWORD)size-8;
wavefile.dwDataSize = (DWORD)size-sizeof(WAVEFILE);
::fseek( fp, 0, SEEK_SET );
::fwrite( &wavefile, sizeof(WAVEFILE), 1, fp );
::fclose( fp );
fp = NULL;
}
}
void CWaveRec::Out( LPVOID lpBuf, DWORD dwSize )
{
if( fp ) {
::fwrite( lpBuf, dwSize, 1, fp );
}
}