Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cWaveData.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cWaveData_H
7 #define _INC_cWaveData_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cWaveFormat.h"
13 
14 #ifdef _WIN32
15 #include "../WinAPI/cWinResource.h"
16 #include "../Math/cValueRange.h"
19 
20 namespace GrayLib
21 {
22  typedef BYTE FAR* P_WAV_DATA_t;
23  typedef const BYTE FAR* P_WAV_CDATA_t;
24  class cWaveData;
25 
26  class GRAYLIB_LINK cWaveRange : public cValueRange<WAVE_BLOCKS_t>
27  {
32 
33  typedef cValueRange<WAVE_BLOCKS_t> SUPER_t;
34 
35  public:
36  cWaveRange(WAVE_BLOCKS_t tLo = 0, WAVE_BLOCKS_t tHi = 0)
37  : cValueRange<WAVE_BLOCKS_t>(tLo, tHi)
38  {
39  }
40  ~cWaveRange()
41  {
42  }
43  WAVE_BLOCKS_t get_Start(void) const
44  {
45  return m_Lo;
46  }
47  WAVE_BLOCKS_t get_End(void) const
48  {
50  return m_Hi;
51  }
52  WAVE_BLOCKS_t get_Size(void) const
53  {
54  return(m_Hi - m_Lo);
55  }
56  };
57 
58  //************************************************************
59 
60  class GRAYLIB_LINK cWaveBuffer
61  : public cListNodeRef<cWaveBuffer>
62  {
67 
68  friend class cWaveData;
69  typedef cListNodeRef<cWaveBuffer> SUPER_t;
70 
71  public:
72  CWinGlobalV m_Data;
73  WAVE_BLOCKS_t m_sizeBlocks;
74  WAVE_BLOCKS_t m_index;
75  STREAM_POS_t m_nFileOffset;
76 
77  public:
78  cWaveBuffer(WAVE_BLOCKS_t size, HGLOBAL hData);
79  virtual ~cWaveBuffer();
80 
82 
83  void Discard(void);
84  void LoadOnDemand();
85  virtual void onFinalRelease() override;
86 
87  P_WAV_DATA_t get_Data()
88  {
89  if (m_Data.get_Data() == nullptr)
90  {
91  LoadOnDemand();
92  }
93  return (P_WAV_DATA_t)m_Data.get_Data();
94  }
95  cWaveData* get_Parent() const;
96  };
97 
98  typedef cRefPtr<cWaveBuffer> cWaveBufferPtr;
99 
100  class GRAYLIB_LINK cWaveSampleRef
101  {
104  public:
105  cWaveBufferPtr m_Buffer;
106  P_WAV_DATA_t m_pBufferData;
107  WAVE_BLOCKS_t m_dwBufferSize;
108  public:
109  cWaveSampleRef()
110  : m_pBufferData(nullptr)
111  , m_dwBufferSize(0)
112  {
113  }
114  };
115 
116  //***********************************************************************
117 
118  class GRAYLIB_LINK cWaveData : public cListT<cWaveBuffer>
119  {
124 
125  typedef cListT<cWaveBuffer> SUPER_t;
126 
127  public:
128  cWaveFormatN m_Form;
129  private:
130  WAVE_BLOCKS_t m_size;
131 
132  protected:
133  virtual void RemoveListNode(cListNodeBase* pObRec);
134  void BufferAdjustIndexes(cWaveBuffer* pBuffer);
135 
136  public:
137  cWaveData();
138  virtual ~cWaveData();
139 
140  virtual void OnSizeChange(WAVE_BLOCKS_t sizeold, WAVE_BLOCKS_t sizenew) = 0;
141 
142  WAVE_BLOCKS_t get_DataSize() const
143  {
144  return m_size;
145  }
146  cWaveFormat& ref_WaveFormat()
147  {
148  return m_Form;
149  }
150 
151  cWaveBufferPtr BufferLink(WAVE_BLOCKS_t size, HGLOBAL hData, cWaveBuffer* pPrv);
152  HRESULT BufferChangeSize(cWaveBuffer* pBuffer, WAVE_BLOCKS_t size);
153  bool BufferSplit(cWaveBuffer* pBuf, WAVE_BLOCKS_t size);
154  cWaveBufferPtr BufferFind(WAVE_BLOCKS_t index);
155  };
156 
157  inline cWaveData* cWaveBuffer::get_Parent() const
158  {
159  return(CHECKPTR_CAST(cWaveData, cListNodeBase::get_Parent()));
160  }
161 }
162 
163 #ifdef GRAY_DLL // force implementation/instantiate for DLL/SO.
164 namespace Gray
165 {
166  template class GRAYLIB_LINK cListT<GrayLib::cWaveBuffer>;
167 }
168 #endif
169 
170 #endif // _WIN32
171 #endif // _INC_cWaveData_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define CHECKPTR_CAST(t, p)
Definition: PtrCast.h:50
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define CHEAPOBJECT_IMPL
Definition: cHeapObject.h:32
cListBase * get_Parent() const noexcept
Definition: cList.h:60
Definition: cMesh.h:22
UINT WAVE_BLOCKS_t
Index in blocks (not bytes or samples) of current wave format in sound buffer.
Definition: cWaveFormat.h:67
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
ULONG_PTR STREAM_POS_t
NOT same as FILE_SIZE_t in 32 bit. Why not ?
Definition: cOSHandle.h:54
uint16 index
Definition: sample3.cpp:29