Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
100 lines
1.9 KiB
C++
100 lines
1.9 KiB
C++
|
|
#include "WavFile.h"
|
|
#include "Wave.h"
|
|
#include "SoundGlobal.h"
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
|
|
CWavFile::CWavFile()
|
|
: m_pWaveFile( new CWaveFile )
|
|
, m_pszFilename( NULL )
|
|
{
|
|
}
|
|
|
|
CWavFile::CWavFile( const char * szFilename )
|
|
: m_pWaveFile( new CWaveFile )
|
|
, m_pszFilename( NULL )
|
|
{
|
|
Create( szFilename );
|
|
}
|
|
|
|
CWavFile::~CWavFile()
|
|
{
|
|
Destroy();
|
|
delete m_pWaveFile;
|
|
}
|
|
|
|
void CWavFile::Create( const char * szFilename )
|
|
{
|
|
if( m_pszFilename )
|
|
delete [] m_pszFilename;
|
|
|
|
m_pszFilename = new char[ strlen( szFilename ) + 1 ];
|
|
strcpy( m_pszFilename, szFilename );
|
|
|
|
HRESULT hr = m_pWaveFile->Open( (char*)szFilename, NULL, WAVEFILE_READ );
|
|
if( hr != S_OK )
|
|
SNDError( "Cannot open wave file : %s, ErrorCode : 0x%x", szFilename, hr );
|
|
}
|
|
|
|
void CWavFile::Destroy()
|
|
{
|
|
delete [] m_pszFilename;
|
|
m_pszFilename = NULL;
|
|
|
|
HRESULT hr = m_pWaveFile->Close();
|
|
if( hr != S_OK )
|
|
SNDError( "Cannot close wave file" );
|
|
}
|
|
|
|
WORD CWavFile::GetBitsPerSample()
|
|
{
|
|
WAVEFORMATEX * pwfx = m_pWaveFile->GetFormat();
|
|
return pwfx->wBitsPerSample;
|
|
}
|
|
|
|
DWORD CWavFile::GetSamplePerSec()
|
|
{
|
|
WAVEFORMATEX * pwfx = m_pWaveFile->GetFormat();
|
|
return pwfx->nSamplesPerSec;
|
|
}
|
|
|
|
WORD CWavFile::GetChannelCount()
|
|
{
|
|
WAVEFORMATEX * pwfx = m_pWaveFile->GetFormat();
|
|
return pwfx->nChannels;
|
|
}
|
|
|
|
DWORD CWavFile::GetSize()
|
|
{
|
|
return m_pWaveFile->GetSize();
|
|
}
|
|
|
|
void CWavFile::Reset()
|
|
{
|
|
HRESULT hr = m_pWaveFile->ResetFile();
|
|
if( hr != S_OK )
|
|
SNDError( "Reset wave file failed!! ErrorCode : 0x%x", hr );
|
|
}
|
|
|
|
size_t CWavFile::Read( void * pBuf, size_t readSize )
|
|
{
|
|
DWORD sizeRead;
|
|
HRESULT hr = m_pWaveFile->Read( (BYTE*)pBuf, readSize, &sizeRead );
|
|
if( hr != S_OK )
|
|
SNDError( "Cannot read wave file" );
|
|
|
|
return sizeRead;
|
|
}
|
|
|
|
size_t CWavFile::ReadWhole( void * pBuf )
|
|
{
|
|
return Read( pBuf, 0xffffffff );
|
|
}
|
|
|
|
const char * CWavFile::GetFilename()
|
|
{
|
|
return m_pszFilename;
|
|
}
|