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
This commit is contained in:
parent
7ed24cb652
commit
c559c4b3ef
@ -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;
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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); };
|
||||
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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); };
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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" );
|
||||
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user