OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / moflib-1.0 / src / mof / sound / WaveFile.cpp
1 #include "mof/sound/WaveFile.hpp"
2 #include "mof/ConsoleIO.hpp"
3
4 mof::WaveFile::WaveFile(void)
5 {
6         m_impl = new mof::CWaveFile();
7 }
8
9 mof::WaveFile::~WaveFile(void)
10 {
11         m_impl->close();
12         delete m_impl;
13 }
14
15
16 bool mof::WaveFile::open(const mof::tstring& filename){
17         WAVEFORMATEX format;
18         if(FAILED(m_impl->open((LPTSTR)filename.c_str() , &format , WAVEFILE_READ)))return false;
19     return true;
20
21 }
22
23
24 bool mof::WaveFile::close(){
25   
26         if(FAILED(m_impl->close()))return false;
27     return true;
28
29
30 }
31
32
33 long mof::WaveFile::read( BYTE* pBuffer1, long bufferSize1 , BYTE* pBuffer2 , long bufferSize2 ){
34    
35
36         DWORD actualReadSize1 = 0;
37         DWORD offset = 0;
38         for(offset = 0 ; offset < bufferSize1 ; offset += actualReadSize1){
39                 if(FAILED(m_impl->read(pBuffer1 + offset , bufferSize1 - offset , &actualReadSize1)))return -1;
40                 else if(actualReadSize1 == 0)break;
41                 else if(bufferSize1 - offset != actualReadSize1)resetFile();
42                 
43         }
44
45         if(bufferSize2 < 0)return actualReadSize1;
46
47         DWORD actualReadSize2 = 0;
48         for(offset = 0 ; offset < bufferSize2 ; offset += actualReadSize2){
49                 if(FAILED(m_impl->read(pBuffer2 + offset , bufferSize2 - offset, &actualReadSize2)))return -1;
50                 else if(actualReadSize2 == 0)break;
51                 else if(bufferSize2 - offset != actualReadSize2)resetFile();
52         }
53
54         return actualReadSize1 + actualReadSize2;
55
56 }
57
58
59 long mof::WaveFile::getSize(){
60         return m_impl->getSize();
61 }
62
63
64
65 bool mof::WaveFile::resetFile(){
66         if(FAILED(m_impl->resetFile()))return false;
67     return true;
68 }
69
70
71 WAVEFORMATEX* mof::WaveFile::getFormat(){
72         return m_impl->getFormat();
73 }
74
75