-
Notifications
You must be signed in to change notification settings - Fork 226
/
WAVStreamer.h
102 lines (81 loc) · 2.67 KB
/
WAVStreamer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//--------------------------------------------------------------------------------------
// WAVStreamer.h
//
// Simple .wav file parser
//
// Xbox Advanced Technology Group (ATG).
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#define RIFFCHUNK_FLAGS_VALID 0x00000001
//--------------------------------------------------------------------------------------
// Name: class RiffChunk
// Desc: RIFF chunk utility class
//--------------------------------------------------------------------------------------
class RiffChunk
{
const RiffChunk* m_pParentChunk; // Parent chunk
HANDLE m_hFile;
uint32_t m_fccChunkId; // Chunk identifier
uint32_t m_dwDataOffset; // Chunk data offset
uint32_t m_dwDataSize; // Chunk data size
uint32_t m_dwFlags; // Chunk flags
public:
RiffChunk() noexcept;
RiffChunk(const RiffChunk&) = delete;
RiffChunk& operator =(const RiffChunk&) = delete;
void Initialize(uint32_t fccChunkId,
_In_opt_ const RiffChunk* pParentChunk,
HANDLE hFile);
_Check_return_
HRESULT Open();
bool IsValid() const
{
return !!(m_dwFlags & RIFFCHUNK_FLAGS_VALID);
}
_Check_return_
HRESULT ReadData(LONG lOffset,
_Out_writes_(dwDataSize) void* pData,
uint32_t dwDataSize,
_In_opt_ OVERLAPPED* pOL) const;
uint32_t GetChunkId() const
{
return m_fccChunkId;
}
uint32_t GetDataSize() const
{
return m_dwDataSize;
}
uint32_t GetDataOffset() const
{
return m_dwDataOffset;
}
};
//--------------------------------------------------------------------------------------
// Name: class WaveFile
// Desc: Wave file utility class
//--------------------------------------------------------------------------------------
class WaveFile
{
HANDLE m_hFile; // File handle
RiffChunk m_RiffChunk; // RIFF chunk
RiffChunk m_FormatChunk; // Format chunk
RiffChunk m_DataChunk; // Data chunk
public:
WaveFile() noexcept;
~WaveFile();
WaveFile(const WaveFile&) = delete;
WaveFile& operator =(const WaveFile&) = delete;
HRESULT Open(_In_z_ const wchar_t* strFileName);
void Close();
HRESULT GetFormat(_Out_ WAVEFORMATEX* pwfxFormat, _In_ size_t maxsize) const;
HRESULT ReadSample(
uint32_t dwPosition,
_Out_writes_(dwBufferSize) void* pBuffer,
uint32_t dwBufferSize,
_Out_opt_ uint32_t* pdwRead) const;
uint32_t GetDuration() const
{
return m_DataChunk.GetDataSize();
}
};