OSDN Git Service

run loop input and output of wave
[internetcity/break_prototype.git] / source / CWaveData.cpp
1 // \8b\9e
2
3 #include "CWaveData.h"
4
5 #include <windows.h>
6 #include <tchar.h>
7
8 ////////////////////////////////////////////////////////////////////////////////
9 // \83R\83\93\83X\83g\83\89\83N\83^
10 ////////////////////////////////////////////////////////////////////////////////
11 CWaveData::CWaveData()
12 {
13         // Wave\83t\83H\81[\83}\83b\83g
14         m_WaveFormat.wFormatTag      = WAVE_FORMAT_PCM;
15         m_WaveFormat.nChannels       = 1;
16         m_WaveFormat.nSamplesPerSec  = 22050;
17         m_WaveFormat.wBitsPerSample  = 8;
18         m_WaveFormat.nBlockAlign     = m_WaveFormat.wBitsPerSample / 8 * m_WaveFormat.nChannels;
19         m_WaveFormat.nAvgBytesPerSec = m_WaveFormat.nSamplesPerSec * m_WaveFormat.nBlockAlign;
20 }
21
22 ////////////////////////////////////////////////////////////////////////////////
23 // \83f\83X\83g\83\89\83N\83^
24 ////////////////////////////////////////////////////////////////////////////////
25 CWaveData::~CWaveData()
26 {
27         freeBuffer();
28 }
29
30 ////////////////////////////////////////////////////////////////////////////////
31 // \8f\89\8aú\89»
32 ////////////////////////////////////////////////////////////////////////////////
33 void CWaveData::initialize()
34 {
35         // \8c»\8fó\83t\83H\81[\83}\83b\83g\82Í\8c\88\82ß\82¤\82¿
36         m_WaveFormat.wFormatTag      = WAVE_FORMAT_PCM;
37         m_WaveFormat.nChannels       = 1;
38         m_WaveFormat.nSamplesPerSec  = 22050;
39         m_WaveFormat.wBitsPerSample  = 8;
40         m_WaveFormat.nBlockAlign     = m_WaveFormat.wBitsPerSample / 8 * m_WaveFormat.nChannels;
41         m_WaveFormat.nAvgBytesPerSec = m_WaveFormat.nSamplesPerSec * m_WaveFormat.nBlockAlign;
42 }
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // \83o\83b\83t\83@\82ð\8am\95Û
46 ////////////////////////////////////////////////////////////////////////////////
47 bool CWaveData::allocBuffer(int in_BufferNumber, DWORD in_RecorMilliSecond)
48 {
49         if(in_BufferNumber < 1 || in_RecorMilliSecond == 0){
50                 return false;
51         }
52
53         if(m_WaveBuffers.empty()){
54                 // free
55                 if(!freeBuffer()){
56                         return false;
57                 }
58         }
59
60         for(int i = 0; i < in_BufferNumber; i++){
61                 StructWaveBuffer tempWaveBuffer;
62                 tempWaveBuffer.m_RecorMilliSecond = in_RecorMilliSecond;
63                 tempWaveBuffer.m_BufferSize   = m_WaveFormat.nAvgBytesPerSec * in_RecorMilliSecond / 1000;
64                 tempWaveBuffer.m_pWaveBuffer = new char[tempWaveBuffer.m_BufferSize];
65
66                 m_WaveBuffers.push_back(tempWaveBuffer);
67         }
68
69         // \93Ç\82Ý\8eæ\82è\83o\83b\83t\83@\82Æ\8f\91\82«\8d\9e\82Ý\83o\83b\83t\83@\82ð\8ew\92è\82µ\82Ä\82¨\82­
70         m_ReadOfWaveBuffers = m_WaveBuffers.begin();
71         m_WriteOfWaveBuffers = m_WaveBuffers.begin();
72
73         return true;
74 }
75
76 ////////////////////////////////////////////////////////////////////////////////
77 // \83o\83b\83t\83@\82ð\89ð\95ú
78 ////////////////////////////////////////////////////////////////////////////////
79 bool CWaveData::freeBuffer()
80 {
81         if(!m_WaveBuffers.empty()){
82                 WaveBufferTable::iterator tempIterator = m_WaveBuffers.begin();
83                 while(tempIterator != m_WaveBuffers.end()){
84                         delete tempIterator->m_pWaveBuffer;
85                         tempIterator++;
86                 }
87         }
88         return true;
89 }