]>
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"
30 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
34 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
35 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
37 Create(sFileName
, isResource
);
40 wxWave::wxWave(int size
, const wxByte
* data
)
41 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
51 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
62 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
64 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
69 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
73 m_waveData= (wxByte*)::LockResource(waveData);
74 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
77 return (m_waveData ? TRUE : FALSE);
86 if (!fileWave
.Open(fileName
, wxFile::read
))
89 m_waveLength
= (int) fileWave
.Length();
92 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
96 fileWave.Read(m_waveData, m_waveLength);
102 bool wxWave::Create(int size
, const wxByte
* data
)
105 m_isResource
= FALSE
;
107 m_waveData
= NULL
; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
111 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
115 bool wxWave::Play(bool async
, bool looped
) const
121 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
122 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
131 // HGLOBAL waveData = ::GlobalHandle(m_waveData);
138 ::FreeResource(waveData);
141 ::GlobalUnlock(waveData);
142 ::GlobalFree(waveData);