From c559c4b3efb01eceaeeb2a2bbc279cb9367e131c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Sep 2011 15:08:02 +0000 Subject: [PATCH] Change wxSound ctor from in-memory data to use size_t/void *. This constructor previously used int and, especially annoyingly, wxByte* for the data. Use standard void* for untyped binary data instead. Also document this ctor as it seems to be implemented in all ports. Closes #13451. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69178 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/sound.h | 4 ++-- include/wx/msw/sound.h | 4 ++-- include/wx/os2/sound.h | 4 ++-- include/wx/osx/sound.h | 4 ++-- include/wx/palmos/sound.h | 4 ++-- include/wx/unix/sound.h | 6 +++--- interface/wx/sound.h | 10 ++++++++++ src/msw/sound.cpp | 8 ++++---- src/os2/sound.cpp | 6 +++--- src/osx/carbon/sound.cpp | 6 +++--- src/osx/core/sound.cpp | 2 +- src/osx/sound_osx.cpp | 2 +- src/palmos/sound.cpp | 4 ++-- src/unix/sound.cpp | 8 +++++--- 14 files changed, 42 insertions(+), 30 deletions(-) diff --git a/include/wx/cocoa/sound.h b/include/wx/cocoa/sound.h index 1a6f7de02d..75ded5c136 100644 --- a/include/wx/cocoa/sound.h +++ b/include/wx/cocoa/sound.h @@ -25,7 +25,7 @@ public: wxSound(const wxString& fileName, bool isResource = false) : m_cocoaNSSound(NULL) { Create(fileName, isResource); } - wxSound(int size, const wxByte* data) + wxSound(size_t size, const void* data) : m_cocoaNSSound(NULL) { LoadWAV(data,size,true); } wxSound(const wxSound& sound); // why not? @@ -43,7 +43,7 @@ public: { return m_cocoaNSSound; } protected: bool DoPlay(unsigned flags) const; - bool LoadWAV(const wxUint8 *data, size_t length, bool copyData); + bool LoadWAV(const void* data, size_t length, bool copyData); private: WX_NSSound m_cocoaNSSound; static const wxObjcAutoRefFromAlloc sm_cocoaDelegate; diff --git a/include/wx/msw/sound.h b/include/wx/msw/sound.h index 47a6967156..5be1eefc8f 100644 --- a/include/wx/msw/sound.h +++ b/include/wx/msw/sound.h @@ -19,14 +19,14 @@ class WXDLLIMPEXP_ADV wxSound : public wxSoundBase public: wxSound(); wxSound(const wxString& fileName, bool isResource = false); - wxSound(int size, const wxByte* data); + wxSound(size_t size, const void* data); virtual ~wxSound(); // Create from resource or file bool Create(const wxString& fileName, bool isResource = false); // Create from data - bool Create(int size, const wxByte* data); + bool Create(size_t size, const void* data); bool IsOk() const { return m_data != NULL; } diff --git a/include/wx/os2/sound.h b/include/wx/os2/sound.h index 43d09536ba..f19bc3a712 100644 --- a/include/wx/os2/sound.h +++ b/include/wx/os2/sound.h @@ -20,14 +20,14 @@ class wxSound : public wxSoundBase public: wxSound(); wxSound(const wxString& fileName, bool isResource = FALSE); - wxSound(int size, const wxByte* data); + wxSound(size_t size, const void* data); virtual ~wxSound(); public: // Create from resource or file bool Create(const wxString& fileName, bool isResource = FALSE); // Create from data - bool Create(int size, const wxByte* data); + bool Create(size_t size, const void* data); bool IsOk() const { return (m_waveData ? TRUE : FALSE); }; diff --git a/include/wx/osx/sound.h b/include/wx/osx/sound.h index d9da4e1eca..fd3978f616 100644 --- a/include/wx/osx/sound.h +++ b/include/wx/osx/sound.h @@ -49,13 +49,13 @@ class WXDLLIMPEXP_ADV wxSound : public wxSoundBase public: wxSound(); wxSound(const wxString& fileName, bool isResource = false); - wxSound(int size, const wxByte* data); + wxSound(size_t size, const void* data); virtual ~wxSound(); // Create from resource or file bool Create(const wxString& fileName, bool isResource = false); // Create from data - bool Create(int size, const wxByte* data); + bool Create(size_t size, const void* data); bool IsOk() const { return m_data != NULL; } diff --git a/include/wx/palmos/sound.h b/include/wx/palmos/sound.h index 9322b2031d..279e70687f 100644 --- a/include/wx/palmos/sound.h +++ b/include/wx/palmos/sound.h @@ -21,14 +21,14 @@ class WXDLLIMPEXP_ADV wxSound : public wxSoundBase public: wxSound(); wxSound(const wxString& fileName, bool isResource = false); - wxSound(int size, const wxByte* data); + wxSound(size_t size, const void* data); virtual ~wxSound(); public: // Create from resource or file bool Create(const wxString& fileName, bool isResource = false); // Create from data - bool Create(int size, const wxByte* data); + bool Create(size_t size, const void* data); bool IsOk() const { return (m_waveData ? true : false); }; diff --git a/include/wx/unix/sound.h b/include/wx/unix/sound.h index 797eacd1fa..95665e8dab 100644 --- a/include/wx/unix/sound.h +++ b/include/wx/unix/sound.h @@ -60,13 +60,13 @@ class WXDLLIMPEXP_ADV wxSound : public wxSoundBase public: wxSound(); wxSound(const wxString& fileName, bool isResource = false); - wxSound(int size, const wxByte* data); + wxSound(size_t size, const void* data); virtual ~wxSound(); // Create from resource or file bool Create(const wxString& fileName, bool isResource = false); // Create from data - bool Create(int size, const wxByte* data); + bool Create(size_t size, const void* data); bool IsOk() const { return m_data != NULL; } @@ -84,7 +84,7 @@ protected: static void EnsureBackend(); void Free(); - bool LoadWAV(const wxUint8 *data, size_t length, bool copyData); + bool LoadWAV(const void* data, size_t length, bool copyData); static wxSoundBackend *ms_backend; #if wxUSE_LIBSDL && wxUSE_PLUGINS diff --git a/interface/wx/sound.h b/interface/wx/sound.h index def7b84b55..5f2c78300b 100644 --- a/interface/wx/sound.h +++ b/interface/wx/sound.h @@ -37,6 +37,16 @@ public: */ wxSound(const wxString& fileName, bool isResource = false); + /** + Constructs a wave object from in-memory data. + + @param size + Size of the buffer pointer to by @a data. + @param data + The buffer containing the sound data in WAV format. + */ + wxSound(size_t size, const void* data); + /** Destroys the wxSound object. */ diff --git a/src/msw/sound.cpp b/src/msw/sound.cpp index 334afd484d..feaab0dc9a 100644 --- a/src/msw/sound.cpp +++ b/src/msw/sound.cpp @@ -58,7 +58,7 @@ class wxSoundDataMemory : public wxSoundData { public: // we copy the data - wxSoundDataMemory(int size, const wxByte *buf); + wxSoundDataMemory(size_t size, const void* buf); void *GetPtr() const { return m_waveDataPtr; } @@ -101,7 +101,7 @@ private: // wxSoundData-derived classes // ---------------------------------------------------------------------------- -wxSoundDataMemory::wxSoundDataMemory(int size, const wxByte *buf) +wxSoundDataMemory::wxSoundDataMemory(size_t size, const void* buf) : m_waveData(size), m_waveDataPtr(m_waveData) { @@ -131,7 +131,7 @@ wxSound::wxSound(const wxString& filename, bool isResource) Create(filename, isResource); } -wxSound::wxSound(int size, const wxByte *data) +wxSound::wxSound(size_t size, const void* data) { Init(); Create(size, data); @@ -164,7 +164,7 @@ bool wxSound::Create(const wxString& filename, bool isResource) return CheckCreatedOk(); } -bool wxSound::Create(int size, const wxByte* data) +bool wxSound::Create(size_t size, const void* data) { Free(); diff --git a/src/os2/sound.cpp b/src/os2/sound.cpp index 21d0498c1e..a901a8dc33 100644 --- a/src/os2/sound.cpp +++ b/src/os2/sound.cpp @@ -42,7 +42,7 @@ wxSound::wxSound(const wxString& sFileName, bool isResource) Create(sFileName, isResource); } -wxSound::wxSound(int size, const wxByte* data) +wxSound::wxSound(size_t size, const void* data) : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) { Create(size, data); @@ -108,7 +108,7 @@ bool wxSound::Create(const wxString& fileName, bool isResource) } } -bool wxSound::Create(int size, const wxByte* data) +bool wxSound::Create(size_t size, const void* data) { Free(); m_isResource = FALSE; @@ -117,7 +117,7 @@ bool wxSound::Create(int size, const wxByte* data) if (!m_waveData) return FALSE; - for (int i=0; i(data_); + WAVEFORMAT waveformat; memcpy(&waveformat, &data[FMT_INDEX + 4], sizeof(WAVEFORMAT)); waveformat.uiSize = wxUINT32_SWAP_ON_BE(waveformat.uiSize); -- 2.45.2