?? cwavefile.cpp
字號:
NULL,
dwCreationDistribution,
dwFlagsAndAttributes,
NULL );
if( INVALID_HANDLE_VALUE == hRiffSize )
{
RETAILMSG(1, (TEXT("ERROR:CREATE: hRiffSize == INVALID_HANDLE_VALUE")));
return dwLastError = GetLastError();
}
hWaveSize = CreateFile( lpFileName,
dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
dwCreationDistribution,
dwFlagsAndAttributes,
NULL );
if( INVALID_HANDLE_VALUE == hWaveSize )
{
RETAILMSG(1, (TEXT("ERROR:CREATE: hRiffSize == INVALID_HANDLE_VALUE")));
return dwLastError = GetLastError();
}
} // if( GENERIC_WRITE )
/* --------------------------------------------------------------------
If file exists and has data verify that data is for a WAVE-RIFF
file. If so copy <wave-formate> and <PCM-format-specific> data to
lpPcmWaveFormat.
-------------------------------------------------------------------- */
if( GetFileSize( hWaveData, NULL ) )
{
return GetFormat( lplpWaveFormat, lplpInfo );
}
/* --------------------------------------------------------------------
Initalize the WAVE-RIFF file
-------------------------------------------------------------------- */
return InitFile( (PCMWAVEFORMAT *)*lplpWaveFormat, lplpInfo );
} // end DWORD CWaveFile::Create( ... )
/*++
CWave::ReadData:
This function reads the wave data from a wave file and puts it in the
passed buffer.
Arguments:
lpWaveData, // address of buffer that receives WAVE data
nNumberOfBytesToRead, // number of bytes to read
lpNumberOfBytesRead, // address of number of bytes read
lpOverlapped // address of structure for data
Return Value:
Same as ReadFile
Notes:
--*/
BOOL CWaveFile::ReadData( LPVOID lpWaveData,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead )
{
BOOL bRtn;
if(NULL == lpWaveData) {
dwLastError = ERROR_INVALID_PARAMETER;
return bRtn = FALSE;
}
bRtn = ReadFile( hWaveData,
lpWaveData,
nNumberOfBytesToRead,
lpNumberOfBytesRead,
NULL );
dwLastError = GetLastError();
return bRtn;
} // end BOOL CWaveFile::ReadData( ... )
/*++
CWaveFile::WriteData:
This function writes a buffers worth of WAVE data to the WAVE file.
Arguments:
lpWaveData, // address of buffer that receives WAVE data
nNumberOfBytesToWrite, // number of bytes to write
lpNumberOfBytesWritten, // address of number of bytes written
lpOverlapped // address of structure for data
Return Value:
SameAsWriteFile
Notes:
--*/
BOOL CWaveFile::WriteData( LPCVOID lpWaveData,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten )
{
BOOL bRtn;
if(NULL == lpWaveData) {
RETAILMSG(1, (TEXT("ERROR: WRITEDATA: NULL == lpWaveData")));
dwLastError = ERROR_INVALID_PARAMETER;
return bRtn = false;
}
if(hWaveData == INVALID_HANDLE_VALUE)
{
RETAILMSG(1, (TEXT("ERROR: WRITEDATA: hWaveData == INVALID_HANDLE_VALUE")));
}
bRtn = WriteFile( hWaveData,
lpWaveData,
nNumberOfBytesToWrite,
lpNumberOfBytesWritten,
NULL );
dwLastError = GetLastError();
if( bRtn != 0 )
{
nRiffSize += *lpNumberOfBytesWritten;
nWaveSize += *lpNumberOfBytesWritten;
/* ----------------------------------------------------------------
Set the sizes sizes.
---------------------------------------------------------------- */
//SetEndOfFile( hWaveData ),
//WriteSize( hRiffSize, nRiffSize );
//WriteSize( hWaveSize, nWaveSize );
if(hWaveData == INVALID_HANDLE_VALUE)
RETAILMSG(1, (TEXT("ERROR: WRITEDATA hWaveData == INVALID_HANDLE_VALUE")));
//if( !SetEndOfFile( hWaveData ));
// RETAILMSG(1, (TEXT("ERROR: Unable to set end of file %d"), GetLastError() ));
// In current Builds SetEndOfFile returns error code 50, yet still works, so for now we'll disable this spew
SetEndOfFile( hWaveData );
if(hRiffSize == INVALID_HANDLE_VALUE)
RETAILMSG(1, (TEXT("ERROR: WRITEDATA hRiffSize == INVALID_HANDLE_VALUE")));
if(!WriteSize( hRiffSize, nRiffSize ))
RETAILMSG(1, (TEXT("ERROR: Unable to write RIFF size to file")));
if(!WriteSize( hWaveSize, nWaveSize ))
RETAILMSG(1, (TEXT("ERROR: Unable to write WAVE size to file")));
} // end if( bRtn )
else
{
RETAILMSG(1, (TEXT("ERROR: In WriteData, bRtn was FALSE")));
RETAILMSG(1, (TEXT("ERROR: WRITEDATA: GetLastError Was %d"), dwLastError));
}
return bRtn;
} // end BOOL CWaveFile::WriteData( ... );
/*++
DWORD CWaveFile::Rewind:
This function rewinds the hWaveData pointer to
the start of the wave data.
Arguments:
NONE
Return Value:
TRUE -> Success
FALSE -> Failure
Notes:
--*/
BOOL CWaveFile::Rewind()
{
DWORD dwRtn;
dwRtn = SetFilePointer( hWaveData, dwDataOffSet, NULL, FILE_BEGIN );
dwLastError = GetLastError();
return 0xFFFFFFFF != dwRtn;
} // end BOOL CWaveFile::Rewind()
/*++
DWORD CWaveFile::End:
This function puts the hWaveData file pointer at the end of the file
Arguments:
NONE
Return Value:
TRUE -> Success
FALSE -> Failure
Notes:
--*/
BOOL CWaveFile::End()
{
DWORD dwRtn;
dwRtn = SetFilePointer( hWaveData, dwDataOffSet, NULL, FILE_END );
dwLastError = GetLastError();
return 0xFFFFFFFF != dwRtn;
} // end BOOL CWaveFile::End()
/*++
CWaveFile::MoveTo:
This function moves the file pointer to passed sample offset.
Arguments:
dwSample The sample to move the file pointer to.
Return Value:
== dwSample Move was a success.
< dwSample Move is not at end of file
0 Some other error check CWaveFile::LastError()
Notes:
--*/
DWORD CWaveFile::MoveTo( DWORD dwSample )
{
DWORD dwOffset;
DWORD dwRtn;
dwOffset = dwDataOffSet + m_PcmWaveFormat.wf.nBlockAlign * dwSample;
dwRtn = SetFilePointer( hWaveData, dwOffset, NULL, FILE_BEGIN );
if( 0xFFFFFFFF == dwRtn )
{
WaveFileError();
return 0;
}
return (dwRtn - dwDataOffSet) / m_PcmWaveFormat.wf.nBlockAlign;
} // end DWORD CWaveFile::MoveTo( DWORD dwSample )
/*++
CWaveFile::GetFormat:
This function reads the wave file from the front to determine if it
is a WAVE-RIFF file and to read the format data.
Arguments:
PCMWAVEFORMAT* lpPcmWaveFormat -> Pointer to the structure to fill with
the wave format data.
LPWAVEAUXINFO lpWaveAuxInfo -> Currently not used, zeroed if not NULL.
Return Value:
If the file is not a WAVE-RIFF file then ERROR_FILE_CORRUPT.
Other errors will return file error codes
For sucess ERROR_NOERROR is returned.
Notes:
--*/
DWORD CWaveFile::GetFormat( LPVOID* lplpWaveFormat,
LPVOID* lplpInfo )
{
DWORD dwBuffer;
DWORD dwRtn;
BOOL bRtn;
if(NULL == lplpWaveFormat) {
dwLastError = ERROR_INVALID_PARAMETER;
return bRtn = FALSE;
}
if( NULL != lplpInfo ) *lplpInfo = NULL;
/* --------------------------------------------------------------------
Verify that the file is a RIFF formated file.
-------------------------------------------------------------------- */
bRtn = ReadFile( hWaveData, &dwBuffer, 4, &dwRtn, NULL );
if( (!bRtn) || (4 != dwRtn) ) return WaveFileError();
if( RIFF_FOURCC != dwBuffer ) return WaveFileError( ERROR_FILE_CORRUPT );
/* --------------------------------------------------------------------
If writing, set the file pointer to the RIFF chunk size DWORD.
-------------------------------------------------------------------- */
if( INVALID_HANDLE_VALUE != hRiffSize )
{
dwRtn = SetFilePointer( hRiffSize, 4, NULL, FILE_BEGIN );
if( 0xFFFFFFFF == dwRtn ) return WaveFileError();
}
/* --------------------------------------------------------------------
Read RIFF chunk size
-------------------------------------------------------------------- */
bRtn = ReadFile( hWaveData, &nRiffSize, 4, &dwRtn, NULL );
if( (!bRtn) || (4 != dwRtn) ) return WaveFileError();
/* --------------------------------------------------------------------
Verify that the file is a WAVE type.
-------------------------------------------------------------------- */
bRtn = ReadFile( hWaveData, &dwBuffer, 4, &dwRtn, NULL );
if( (!bRtn) || (4 != dwRtn) ) return WaveFileError();
if( WAVE_FOURCC != dwBuffer ) return WaveFileError( ERROR_FILE_CORRUPT );
/* --------------------------------------------------------------------
Read the next FOURCC
-------------------------------------------------------------------- */
bRtn = ReadFile( hWaveData, &dwBuffer, 4, &dwRtn, NULL );
if( (!bRtn) || (4 != dwRtn) ) return WaveFileError();
/* --------------------------------------------------------------------
Read all of the non data chunks.
-------------------------------------------------------------------- */
while ( data_FOURCC != dwBuffer )
{
switch( dwBuffer ) // FOURCC
{
case fmt_FOURCC:
if ( ReadWaveFormat( lplpWaveFormat ) )
return dwLastError;
break;
case LIST_FOURCC:
if ( ReadListInfo( lplpInfo ) )
delete [] *lplpInfo; // cleanup since we dont use lplpInfo
*lplpInfo = NULL;
return dwLastError;
break;
case fact_FOURCC:
if ( ReadFactChunk( ) )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -