]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWave class implementation: optional
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/os2/wave.h"
21 #include "wx/os2/private.h"
33 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
37 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
38 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
40 Create(sFileName
, isResource
);
43 wxWave::wxWave(int size
, const wxByte
* data
)
44 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
54 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
65 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
67 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
72 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
76 m_waveData= (wxByte*)::LockResource(waveData);
77 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
80 return (m_waveData ? TRUE : FALSE);
89 if (!fileWave
.Open(fileName
, wxFile::read
))
92 m_waveLength
= (int) fileWave
.Length();
95 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
99 fileWave.Read(m_waveData, m_waveLength);
105 bool wxWave::Create(int size
, const wxByte
* data
)
108 m_isResource
= FALSE
;
110 m_waveData
= NULL
; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
114 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
118 bool wxWave::Play(bool async
, bool looped
) const
124 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
125 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
134 // HGLOBAL waveData = ::GlobalHandle(m_waveData);
141 ::FreeResource(waveData);
144 ::GlobalUnlock(waveData);
145 ::GlobalFree(waveData);