46 CWaveFormat(DWORD samplesPerSec = 44100, WORD bitsPerSample = 16, WORD channels = 2)
48 wFormatTag = WAVE_FORMAT_PCM;
49 cbSize =
sizeof(WAVEFORMATEX);
50 Set(samplesPerSec, bitsPerSample, channels);
59 WAVEFORMATEX* P =
this;
70 void Set(DWORD samplesPerSec, WORD bitsPerSample, WORD channels)
72 nSamplesPerSec = samplesPerSec;
73 wBitsPerSample = bitsPerSample;
75 nBlockAlign =
static_cast<WORD
>(nChannels * wBitsPerSample / 8);
76 nAvgBytesPerSec = nSamplesPerSec * nBlockAlign;
86 ULONGLONG r = samples;
88 return static_cast<DWORD
>((r + nSamplesPerSec - 1) / nSamplesPerSec);
100 return static_cast<size_t>(r / 1000);
164 v.
Copy(m_map.GetKeysAdapter());
177 return m_map.HasKey(cc);
190 if ( m_map.HasKey(cc) )
204 void Set(FOURCC cc, LPCTSTR lpsz)
217 vb.
AddElements(4,
reinterpret_cast<const BYTE*
>(
"INFO"));
218 loop ( i, m_map.GetSize() )
220 FOURCC cc = m_map.At(i).first;
221 const CAscii& s = m_map.At(i).second;
223 vb.
AddElements(4,
reinterpret_cast<const BYTE*
>(&cc));
224 vb.
AddElements(4,
reinterpret_cast<const BYTE*
>(&len));
225 vb.
AddElements(len,
reinterpret_cast<const BYTE*
>(s.operator LPCSTR()));
226 if ( (len & 1) != 0 )
247 sz = c.
GetElements(
sizeof(FOURCC),
reinterpret_cast<BYTE*
>(&type), pos);
248 if ( sz !=
sizeof(FOURCC) )
253 if ( type != MAKEFOURCC(
'I',
'N',
'F',
'O') )
260 sz = c.
GetElements(
sizeof(chunk),
reinterpret_cast<BYTE*
>(&chunk), pos);
261 if ( sz !=
sizeof(chunk) )
266 size_t len = chunk.
length;
267 if ( (len & 1) != 0 )
305 CWaveFile(
void) : m_dataSize(0), m_dataOffset(0), m_adapter(NULL, 0)
345 bool Open(LPCTSTR fileName,
const WAVEFORMATEX& format)
349 if ( ! m_file.
Open(fileName) )
353 if ( ! m_file16.
Open(fileName) )
372 if ( ! m_file.
Open(fileName) )
378 pos += m_file.
GetElements(
sizeof(fileChunk),
reinterpret_cast<BYTE*
>(&fileChunk), pos);
380 pos += m_file.
GetElements(
sizeof(riffType),
reinterpret_cast<BYTE*
>(&riffType), pos);
383 while( pos < m_file.
GetSize() )
386 pos += m_file.
GetElements(
sizeof(chunk),
reinterpret_cast<BYTE*
>(&chunk), pos);
387 if ( chunk.
type == FC_FMT )
389 m_file.
GetElements(
sizeof(m_format),
reinterpret_cast<BYTE*
>(&m_format), pos);
390 WORD bps = m_format.wBitsPerSample;
391 if ( bps != 8 && bps != 16 )
395 if ( m_format.wFormatTag != WAVE_FORMAT_PCM )
399 if ( m_format.nChannels != 1 && m_format.nChannels != 2 )
405 else if ( chunk.
type == FC_DATA )
408 m_dataSize = chunk.
length;
415 m_chunkMap[chunk.
type] = cm;
425 if ( m_file16.
Open(fileName, m_dataOffset, m_dataSize /
sizeof(
short)) )
450 if ( m_format.nBlockAlign == 0 )
454 return m_dataSize / m_format.nBlockAlign;
463 if ( m_format.nBlockAlign == 0 || m_format.nSamplesPerSec == 0 )
467 ULONGLONG r = (m_dataSize / m_format.nBlockAlign);
469 return static_cast<DWORD
>((r + m_format.nSamplesPerSec - 1) / m_format.nSamplesPerSec);
527 if ( m_chunkMap.
HasKey(cc) )
532 return m_nullCollection;
563 _head.
Resize(
sizeof(TWaveFileHeader));
564 TWaveFileHeader* P =
reinterpret_cast<TWaveFileHeader*
>(_head.
Ref());
565 P->fileChunk.type = FC_RIFF;
566 P->fileChunk.length = dataSize + extendSize +
sizeof(TWaveFileHeader) - 8;
567 P->fileType = FC_WAVE;
568 P->format.wf.wFormatTag = WAVE_FORMAT_PCM;
569 P->format.wf.nChannels =
static_cast<WORD
>(channels);
570 P->format.wf.nSamplesPerSec = rate;
571 P->format.wBitsPerSample = bit;
572 P->format.wf.nBlockAlign =
static_cast<WORD
>(channels * bit / 8);
573 P->format.wf.nAvgBytesPerSec = channels * bit / 8 * rate;
574 P->formatChunk.type = FC_FMT;
575 P->formatChunk.length =
sizeof(PCMWAVEFORMAT);
576 P->dataChunk.type = FC_DATA;
577 P->dataChunk.length = dataSize;
578 return sizeof(TWaveFileHeader);
585 FC_RIFF = MAKEFOURCC(
'R',
'I',
'F',
'F'),
586 FC_WAVE = MAKEFOURCC(
'W',
'A',
'V',
'E'),
587 FC_FMT = MAKEFOURCC(
'f',
'm',
't',
' '),
588 FC_DATA = MAKEFOURCC(
'd',
'a',
't',
'a'),
591 struct TWaveFileHeader
593 TChunkHeader fileChunk;
595 TChunkHeader formatChunk;
596 PCMWAVEFORMAT format;
597 TChunkHeader dataChunk;
#define loop(VAR, CNT)
loop構文.
virtual size_t GetSize(void) const
[取得] 要素数取得.
bool Open(LPCTSTR lpszName, LONGLONG offset=0, size_t size=INVALID_SIZE)
[操作] オープン.
bool IsOpened(void) const
[確認] オープン確認.
void Close(void)
[操作] クローズ.
virtual bool RemoveAll(void)
[削除] すべてのキーと値を削除
bool HasKey(INK key) const
[確認] キー有無
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
size_t GetLength(void) const
[取得] 文字列長
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
virtual bool RemoveAll(void)
[削除] 空化
virtual size_t AddElements(size_t size, const TYP *P=NULL)
[追加] 複数要素追加.
virtual const TYP * ReferBuffer(void) const
[取得] データアドレス取得
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
bool Analyze(size_t size, const BYTE *P)
[解析] チャンクブロック解析.
bool Analyze(const IConstCollectionT< BYTE > &c)
[解析] チャンクブロック解析.
bool Has(FOURCC cc) const
[確認] タイプ確認.
CVectorT< FOURCC > EnumType(void) const
[取得] タイプ一覧取得.
void Set(FOURCC cc, LPCTSTR lpsz)
[設定] 文字列取得.
bool Get(CAscii &_str, FOURCC cc) const
[取得] 文字列取得.
CByteVector Make(void) const
[作成] チャンクブロック作成.
bool Open(LPCTSTR fileName, const WAVEFORMATEX &format)
[設定] PCMファイルオープン
bool GetListInfoChunk(CListInfoChunk &_lic) const
[取得] LIST,INFO チャンクデータ取得
const IConstCollectionT< BYTE > & GetChunk(FOURCC cc) const
[取得] チャンクデータ取得.
const BYTE * RefData(INDEX i=0) const
[取得] 波形データポインタ取得.
size_t GetDataSize(void) const
[取得] 波形データサイズ取得.
bool IsOpened(void) const
[確認] オープン確認.
void Close(void)
[設定] クローズ
size_t GetSamples(void) const
[取得] 波形データ数取得.
static size_t MakeWaveHeader(CWorkMem &_head, int channels, long rate, WORD bit, size_t dataSize, size_t extendSize=0)
[作成] Wavファイルヘッダ作成.
const IConstCollectionT< short > & GetShortData(void) const
[取得] 16bit波形データ取得.
const IConstCollectionT< BYTE > & GetByteData(void) const
[取得] 8bit波形データ取得.
bool Open(LPCTSTR fileName)
[設定] WAVファイルオープン
DWORD GetTotalTime(void) const
[取得] 波形データ時間取得.
const CWaveFormat & RefFormat(void) const
[参照] Waveフォーマット参照
void Resize(size_t l)
[設定] サイズ再設定
const TYP * Ref(void) const
[取得] ポインタ取得
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
virtual size_t Copy(const IConstCollectionT< TYP > &c)
[設定] コピー.
virtual size_t GetElements(size_t size, TYP *_P, INDEX offset=0) const
[取得] 複数要素取り出し.
bool IsEmpty(void) const
[確認] 要素の有無確認.
virtual size_t GetSize(void) const =0
[取得] 要素数取得.