///////////////////////////////////////////////////////////////////////////// // Name: sound.cpp // Purpose: wxSound class implementation: optional // Author: David Webster // Modified by: // Created: 10/17/99 // RCS-ID: $Id$ // Copyright: (c) David Webster // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "wx/file.h" #include "wx/sound.h" #define INCL_32 /* force 32 bit compile */ #define INCL_GPIBITMAPS #define INCL_DOSFILEMGR #define INCL_WIN #define INCL_GPI #define INCL_PM #include #include #include #include #include #include wxSound::wxSound() : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) { } wxSound::wxSound(const wxString& sFileName, bool isResource) : m_waveData(NULL), m_waveLength(0), m_isResource(isResource) { Create(sFileName, isResource); } wxSound::wxSound(int size, const wxByte* data) : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) { Create(size, data); } wxSound::~wxSound() { Free(); } bool wxSound::Create(const wxString& fileName, bool isResource) { Free(); if (isResource) { m_isResource = TRUE; // TODO: /* HRSRC hresInfo; #ifdef _UNICODE hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE")); #else hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE")); #endif if (!hresInfo) return FALSE; HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo); if (waveData) { m_waveData= (wxByte*)::LockResource(waveData); m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo); } return (m_waveData ? TRUE : FALSE); */ return FALSE; } else { m_isResource = FALSE; #if wxUSE_FILE wxFile fileWave; if (!fileWave.Open(fileName, wxFile::read)) return FALSE; m_waveLength = (int) fileWave.Length(); // TODO: /* m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); if (!m_waveData) return FALSE; fileWave.Read(m_waveData, m_waveLength); */ return TRUE; #else return FALSE; #endif //wxUSE_FILE } } bool wxSound::Create(int size, const wxByte* data) { Free(); m_isResource = FALSE; m_waveLength=size; m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); if (!m_waveData) return FALSE; for (int i=0; i