]> git.saurik.com Git - wxWidgets.git/commitdiff
Change wxSound ctor from in-memory data to use size_t/void *.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 21 Sep 2011 15:08:02 +0000 (15:08 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 21 Sep 2011 15:08:02 +0000 (15:08 +0000)
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

14 files changed:
include/wx/cocoa/sound.h
include/wx/msw/sound.h
include/wx/os2/sound.h
include/wx/osx/sound.h
include/wx/palmos/sound.h
include/wx/unix/sound.h
interface/wx/sound.h
src/msw/sound.cpp
src/os2/sound.cpp
src/osx/carbon/sound.cpp
src/osx/core/sound.cpp
src/osx/sound_osx.cpp
src/palmos/sound.cpp
src/unix/sound.cpp

index 1a6f7de02de32d668c94c1ce7739b6b722bc29f2..75ded5c136d7061f28def65ada26332a230bba24 100644 (file)
@@ -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<struct objc_object *> sm_cocoaDelegate;
index 47a69671565fd3cdfe58392df199d564179c8e5c..5be1eefc8fc29223708789143460935af5987995 100644 (file)
@@ -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; }
 
index 43d09536ba871a553d8615c62c95658416c6497a..f19bc3a712cc0de0a53737168c17f29907c7d973 100644 (file)
@@ -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); };
 
index d9da4e1eca776ef85f1d8c22c1bc3ac43f30a369..fd3978f616b040d1ae22ff01304eeba11e7ad4dd 100644 (file)
@@ -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; }
 
index 9322b2031d868e4c79f1d477781158063a7d4e78..279e70687fd3bc3f833d5bba62bca35895b00c47 100644 (file)
@@ -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); };
 
index 797eacd1fa2f5a91e7938448b80da6e812cd3a23..95665e8dab26168464eac1ee3ab131b789255bdc 100644 (file)
@@ -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
index def7b84b550dbd7a3899b60f1b590dd883c7e38d..5f2c78300b90a22180a5ab3794a00ba8ca2da621 100644 (file)
@@ -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.
     */
index 334afd484d091357355dd11a3039b61b99719d9e..feaab0dc9a0296f863e9dc499f643abfdee3f8d8 100644 (file)
@@ -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();
 
index 21d0498c1ecb088cb10f70dd502aa757804b6eac..a901a8dc338b7f9ed1e439ae698b5db42c991f0c 100644 (file)
@@ -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<size; i++) m_waveData[i] = data[i];
+  memcpy(m_waveData, data, size);
   return TRUE;
 }
 
index 3ae66a0b12134699580483e9e9ad6db6d4115aa0..cfd49959a9c2015c2290c8ce0c2449b5c99dcb5b 100644 (file)
@@ -188,7 +188,7 @@ class wxOSXQuickTimeSoundData : public wxSoundData
 {
 public:
     wxOSXQuickTimeSoundData(const wxString& fileName);
-    wxOSXQuickTimeSoundData(int size, const wxByte* data);
+    wxOSXQuickTimeSoundData(size_t size, const void* data);
     ~wxOSXQuickTimeSoundData();
 
     virtual bool Play(unsigned flags);
@@ -208,7 +208,7 @@ wxOSXQuickTimeSoundData::wxOSXQuickTimeSoundData(const wxString& fileName) :
     m_sndname = fileName;
 }
 
-wxOSXQuickTimeSoundData::wxOSXQuickTimeSoundData(int size, const wxByte* data) :
+wxOSXQuickTimeSoundData::wxOSXQuickTimeSoundData(size_t size, const void* data) :
     m_movie(NULL)
 {
     m_soundHandle = NewHandleClear((Size)size);
@@ -354,7 +354,7 @@ void wxOSXQuickTimeSoundData::SoundTask()
         MoviesTask(m_movie, MOVIE_DELAY); //Give QT time to play movie
 }
 
-bool wxSound::Create(int size, const wxByte* data)
+bool wxSound::Create(size_t size, const void* data)
 {
     m_data = new wxOSXQuickTimeSoundData(size,data);
     return true;
index ace90c2fde6fb410033baad27de683976153e553..aef9161af2ef9b3d6b435f1fed99b275ec320630 100644 (file)
@@ -129,7 +129,7 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags)
     return true;
 }
 
-bool wxSound::Create(int WXUNUSED(size), const wxByte* WXUNUSED(data))
+bool wxSound::Create(size_t WXUNUSED(size), const void* WXUNUSED(data))
 {
     wxFAIL_MSG( "not implemented" );
 
index 65492d2b285583c6111cdbca4eff4780630751d1..d671a5da22cdb7880fb84f0c36fb171dc454023a 100644 (file)
@@ -101,7 +101,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)
 {
     Init();
     Create( size, data );
index 6fc7f20d68a88827382cb77fa3026997784d3119..40e73365e378fd1da04269a5008480f9e6fa09bd 100644 (file)
@@ -36,7 +36,7 @@ wxSound::wxSound(const wxString& sFileName, bool 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)
 {
 }
@@ -50,7 +50,7 @@ bool wxSound::Create(const wxString& fileName, bool isResource)
     return false;
 }
 
-bool wxSound::Create(int size, const wxByte* data)
+bool wxSound::Create(size_t size, const void* data)
 {
     return false;
 }
index 500e8617182a2694fcdf62ac833096034204e19d..8543c66443b28243017bec3e436a274cbe69b36c 100644 (file)
@@ -435,7 +435,7 @@ wxSound::wxSound(const wxString& sFileName, bool isResource) : m_data(NULL)
     Create(sFileName, isResource);
 }
 
-wxSound::wxSound(int size, const wxByte* data) : m_data(NULL)
+wxSound::wxSound(size_t size, const void* data) : m_data(NULL)
 {
     Create(size, data);
 }
@@ -483,7 +483,7 @@ bool wxSound::Create(const wxString& fileName,
     return true;
 }
 
-bool wxSound::Create(int size, const wxByte* data)
+bool wxSound::Create(size_t size, const void* data)
 {
     wxASSERT( data != NULL );
 
@@ -623,7 +623,7 @@ typedef struct
 #define WAVE_INDEX       8
 #define FMT_INDEX       12
 
-bool wxSound::LoadWAV(const wxUint8 *data, size_t length, bool copyData)
+bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData)
 {
     // the simplest wave file header consists of 44 bytes:
     //
@@ -648,6 +648,8 @@ bool wxSound::LoadWAV(const wxUint8 *data, size_t length, bool copyData)
     if ( length < 44 )
         return false;
 
+    const wxUint8* data = static_cast<const wxUint8*>(data_);
+
     WAVEFORMAT waveformat;
     memcpy(&waveformat, &data[FMT_INDEX + 4], sizeof(WAVEFORMAT));
     waveformat.uiSize = wxUINT32_SWAP_ON_BE(waveformat.uiSize);