Files
Client/GameTools/SoundLib/OggLoader.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
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>
2025-11-29 20:17:20 +09:00

132 lines
2.6 KiB
C++

// OggLoader.cpp: implementation of the COggLoader class.
//
//////////////////////////////////////////////////////////////////////
#include "OggLoader.h"
COggLoader::COggLoader() : m_dwBufferSize(0),
m_dwNumSamples(0),
m_pVorbisInfo(NULL),
m_bEOF(false),
m_bOpen(false),
m_pFP(NULL)
{
}
COggLoader::~COggLoader()
{
Close();
}
bool COggLoader::Open( char* strFileName )
{
if(m_bOpen) return false;
m_bOpen = true;
m_pFP = fopen( strFileName, "rb" );
if (ov_open(m_pFP, &m_VorbisFile, NULL, 0) < 0)
{
char buf[MAX_PATH] = {0};
sprintf( buf, "해당파일을 열수가 없습니다. : %s \n COggLoader::Open", strFileName );
MessageBox( NULL, buf, "사운드에러", MB_OK );
return false;
}
if( !GetStreamInfo() )
{
char buf[MAX_PATH] = {0};
sprintf( buf, "해당파일의 스트림정보를 얻어올수 없습니다. : %s \n COggLoader::Open", strFileName );
MessageBox( NULL, buf, "사운드에러", MB_OK );
return false;
}
return true;
}
bool COggLoader::Close()
{
if(!m_bOpen) return false;
if( ov_clear(&m_VorbisFile) < 0 )
return false;
if( m_pFP ) fclose( m_pFP );
return true;
}
bool COggLoader::Read( BYTE* pBuffer, DWORD dwSizeToRead, DWORD* pdwSizeRead )
{
if(!m_bOpen) return false;
char* pCurBuffer = (char*)pBuffer;
DWORD dwBytesRead = 0;
int iSection = 0;
while( (dwBytesRead < dwSizeToRead) && !m_bEOF )
{
int iRet = ov_read(&m_VorbisFile, pCurBuffer, dwSizeToRead - dwBytesRead, 0, 2, 1, &iSection);
if (iRet == 0 || iSection != 0)
{
m_bEOF = true;
}
else if (iRet < 0)
{
return false;
}
dwBytesRead += iRet;
pCurBuffer += iRet;
}
*pdwSizeRead = dwBytesRead;
return true;
}
bool COggLoader::Reset()
{
if(!m_bOpen)
return false;
m_bEOF = false;
ov_pcm_seek(&m_VorbisFile, 0);
return true;
}
DWORD COggLoader::GetSize()
{
return m_dwNumSamples * m_WaveFormatEx.nChannels * m_WaveFormatEx.wBitsPerSample / 8;
}
bool COggLoader::GetStreamInfo()
{
// Get vorbis file information
m_pVorbisInfo = ov_info(&m_VorbisFile,-1);
if( !m_pVorbisInfo ) return false;
// Get the number of PCM samples in this file
m_dwNumSamples = (long)ov_pcm_total(&m_VorbisFile,-1);
// set up the WaveFormatEx structure
m_WaveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
m_WaveFormatEx.nChannels = m_pVorbisInfo->channels;
m_WaveFormatEx.nSamplesPerSec = m_pVorbisInfo->rate;
m_WaveFormatEx.wBitsPerSample = 16;
m_WaveFormatEx.nBlockAlign = m_WaveFormatEx.nChannels * m_WaveFormatEx.wBitsPerSample / 8;
m_WaveFormatEx.nAvgBytesPerSec = m_WaveFormatEx.nSamplesPerSec * m_WaveFormatEx.nBlockAlign;
m_WaveFormatEx.cbSize = 0;
return true;
}