2004-02-01 13:25:12 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-17 10:44:52 -04:00
|
|
|
// Name: wx/unix/sound.h
|
2004-02-01 13:25:12 -05:00
|
|
|
// Purpose: wxSound class
|
|
|
|
// Author: Julian Smart, Vaclav Slavik
|
|
|
|
// Modified by:
|
|
|
|
// Created: 25/10/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart, Vaclav Slavik
|
2006-10-17 10:44:52 -04:00
|
|
|
// Licence: wxWindows licence
|
2004-02-01 13:25:12 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_SOUND_H_
|
|
|
|
#define _WX_SOUND_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2004-02-02 08:16:31 -05:00
|
|
|
#if wxUSE_SOUND
|
2004-02-01 13:25:12 -05:00
|
|
|
|
|
|
|
#include "wx/object.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxSound: simple audio playback class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-08-02 14:16:51 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxSoundBackend;
|
|
|
|
class WXDLLIMPEXP_ADV wxSound;
|
|
|
|
class WXDLLIMPEXP_BASE wxDynamicLibrary;
|
2004-02-01 13:25:12 -05:00
|
|
|
|
|
|
|
/// Sound data, as loaded from .wav file:
|
2005-08-02 14:16:51 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxSoundData
|
2004-02-01 13:25:12 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxSoundData() : m_refCnt(1) {}
|
|
|
|
void IncRef();
|
|
|
|
void DecRef();
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 13:25:12 -05:00
|
|
|
// .wav header information:
|
|
|
|
unsigned m_channels; // num of channels (mono:1, stereo:2)
|
|
|
|
unsigned m_samplingRate;
|
|
|
|
unsigned m_bitsPerSample; // if 8, then m_data contains unsigned 8bit
|
|
|
|
// samples (wxUint8), if 16 then signed 16bit
|
|
|
|
// (wxInt16)
|
|
|
|
unsigned m_samples; // length in samples:
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 13:25:12 -05:00
|
|
|
// wave data:
|
|
|
|
size_t m_dataBytes;
|
|
|
|
wxUint8 *m_data; // m_dataBytes bytes of data
|
|
|
|
|
|
|
|
private:
|
|
|
|
~wxSoundData();
|
|
|
|
unsigned m_refCnt;
|
|
|
|
wxUint8 *m_dataWithHeader; // ditto, but prefixed with .wav header
|
|
|
|
friend class wxSound;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Simple sound class:
|
2005-08-02 14:16:51 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxSound : public wxSoundBase
|
2004-02-01 13:25:12 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxSound();
|
|
|
|
wxSound(const wxString& fileName, bool isResource = false);
|
|
|
|
wxSound(int size, const wxByte* data);
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxSound();
|
2004-02-01 13:25:12 -05:00
|
|
|
|
|
|
|
// Create from resource or file
|
|
|
|
bool Create(const wxString& fileName, bool isResource = false);
|
|
|
|
// Create from data
|
|
|
|
bool Create(int size, const wxByte* data);
|
|
|
|
|
|
|
|
bool IsOk() const { return m_data != NULL; }
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 19:49:39 -05:00
|
|
|
// Stop playing any sound
|
|
|
|
static void Stop();
|
|
|
|
|
|
|
|
// Returns true if a sound is being played
|
|
|
|
static bool IsPlaying();
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 13:25:12 -05:00
|
|
|
// for internal use
|
|
|
|
static void UnloadBackend();
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 13:25:12 -05:00
|
|
|
protected:
|
2004-02-02 08:16:31 -05:00
|
|
|
bool DoPlay(unsigned flags) const;
|
2004-02-01 13:25:12 -05:00
|
|
|
|
|
|
|
static void EnsureBackend();
|
|
|
|
void Free();
|
|
|
|
bool LoadWAV(const wxUint8 *data, size_t length, bool copyData);
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 13:25:12 -05:00
|
|
|
static wxSoundBackend *ms_backend;
|
|
|
|
#if wxUSE_LIBSDL && wxUSE_PLUGINS
|
|
|
|
// FIXME - temporary, until we have plugins architecture
|
|
|
|
static wxDynamicLibrary *ms_backendSDL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxSoundData *m_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2006-10-17 10:44:52 -04:00
|
|
|
// wxSoundBackend:
|
2004-02-01 13:25:12 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// This is interface to sound playing implementation. There are multiple
|
2004-05-23 10:56:36 -04:00
|
|
|
// sound architectures in use on Unix platforms and wxWidgets can use several
|
2004-02-01 13:25:12 -05:00
|
|
|
// of them for playback, depending on their availability at runtime; hence
|
2004-05-23 10:56:36 -04:00
|
|
|
// the need for backends. This class is for use by wxWidgets and people writing
|
|
|
|
// additional backends only, it is _not_ for use by applications!
|
2004-02-01 13:25:12 -05:00
|
|
|
|
2004-02-01 19:49:39 -05:00
|
|
|
// Structure that holds playback status information
|
|
|
|
struct wxSoundPlaybackStatus
|
|
|
|
{
|
|
|
|
// playback is in progress
|
|
|
|
bool m_playing;
|
|
|
|
// main thread called wxSound::Stop()
|
|
|
|
bool m_stopRequested;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Audio backend interface
|
2005-08-02 14:16:51 -04:00
|
|
|
class WXDLLIMPEXP_ADV wxSoundBackend
|
2004-02-01 13:25:12 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~wxSoundBackend() {}
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 13:25:12 -05:00
|
|
|
// Returns the name of the backend (e.g. "Open Sound System")
|
|
|
|
virtual wxString GetName() const = 0;
|
|
|
|
|
|
|
|
// Returns priority (higher priority backends are tried first)
|
|
|
|
virtual int GetPriority() const = 0;
|
|
|
|
|
|
|
|
// Checks if the backend's audio system is available and the backend can
|
|
|
|
// be used for playback
|
|
|
|
virtual bool IsAvailable() const = 0;
|
|
|
|
|
|
|
|
// Returns true if the backend is capable of playing sound asynchronously.
|
2004-05-23 10:56:36 -04:00
|
|
|
// If false, then wxWidgets creates a playback thread and handles async
|
2004-02-01 13:25:12 -05:00
|
|
|
// playback, otherwise it is left up to the backend (will usually be more
|
2004-02-01 19:49:39 -05:00
|
|
|
// effective).
|
2004-02-01 13:25:12 -05:00
|
|
|
virtual bool HasNativeAsyncPlayback() const = 0;
|
2006-10-17 10:44:52 -04:00
|
|
|
|
2004-02-01 19:49:39 -05:00
|
|
|
// Plays the sound. flags are same flags as those passed to wxSound::Play.
|
|
|
|
// The function should periodically check the value of
|
|
|
|
// status->m_stopRequested and terminate if it is set to true (it may
|
|
|
|
// be modified by another thread)
|
|
|
|
virtual bool Play(wxSoundData *data, unsigned flags,
|
|
|
|
volatile wxSoundPlaybackStatus *status) = 0;
|
|
|
|
|
|
|
|
// Stops playback (if something is played).
|
|
|
|
virtual void Stop() = 0;
|
|
|
|
|
|
|
|
// Returns true if the backend is playing anything at the moment.
|
|
|
|
// (This method is never called for backends that don't support async
|
|
|
|
// playback.)
|
|
|
|
virtual bool IsPlaying() const = 0;
|
2004-02-01 13:25:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-02 08:16:31 -05:00
|
|
|
#endif // wxUSE_SOUND
|
2004-02-01 13:25:12 -05:00
|
|
|
|
2006-10-19 09:09:48 -04:00
|
|
|
#endif // _WX_SOUND_H_
|
|
|
|
|