]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wave.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if defined(__BORLANDC__)
30 #include "wx/msw/wave.h"
31 #include "wx/msw/private.h"
35 #if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
36 #include "wx/msw/gnuwin32/extra.h"
42 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
46 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
47 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
49 Create(sFileName
, isResource
);
52 wxWave::wxWave(int size
, const wxByte
* data
)
53 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
63 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
72 #if defined(__WIN32__)
74 hresInfo
= ::FindResourceW((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
76 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
79 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
84 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
88 m_waveData
= (wxByte
*)::LockResource(waveData
);
89 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
92 return (m_waveData
? TRUE
: FALSE
);
99 if (!fileWave
.Open(fileName
, wxFile::read
))
102 m_waveLength
= (int) fileWave
.Length();
104 m_waveData
= (wxByte
*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
108 fileWave
.Read(m_waveData
, m_waveLength
);
114 bool wxWave::Create(int size
, const wxByte
* data
)
117 m_isResource
= FALSE
;
119 m_waveData
= (wxByte
*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
123 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
127 bool wxWave::Play(bool async
, bool looped
) const
133 return ( ::PlaySound((LPCTSTR
)m_waveData
, NULL
, SND_MEMORY
|
134 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
136 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
137 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
146 HGLOBAL waveData
= (HGLOBAL
) m_waveData
;
147 #elif defined(__WIN32__)
148 HGLOBAL waveData
= GlobalHandle(m_waveData
);
150 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
157 ::FreeResource(waveData
);
161 GlobalUnlock(waveData
);
162 GlobalFree(waveData
);