]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/sound.h
c85b0ef8666d7df02d6b4b369b3067c24b05c207
[wxWidgets.git] / include / wx / unix / sound.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wave.h
3 // Purpose: wxSound class
4 // Author: Julian Smart, Vaclav Slavik
5 // Modified by:
6 // Created: 25/10/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart, Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_SOUND_H_
13 #define _WX_SOUND_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_WAVE
18
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "sound.h"
21 #endif
22
23 #include "wx/object.h"
24
25 // ----------------------------------------------------------------------------
26 // wxSound: simple audio playback class
27 // ----------------------------------------------------------------------------
28
29 class wxSoundBackend;
30 class wxSound;
31 class wxDynamicLibrary;
32
33 /// Sound data, as loaded from .wav file:
34 class wxSoundData
35 {
36 public:
37 wxSoundData() : m_refCnt(1) {}
38 void IncRef();
39 void DecRef();
40
41 // .wav header information:
42 unsigned m_channels; // num of channels (mono:1, stereo:2)
43 unsigned m_samplingRate;
44 unsigned m_bitsPerSample; // if 8, then m_data contains unsigned 8bit
45 // samples (wxUint8), if 16 then signed 16bit
46 // (wxInt16)
47 unsigned m_samples; // length in samples:
48
49 // wave data:
50 size_t m_dataBytes;
51 wxUint8 *m_data; // m_dataBytes bytes of data
52
53 private:
54 ~wxSoundData();
55 unsigned m_refCnt;
56 wxUint8 *m_dataWithHeader; // ditto, but prefixed with .wav header
57 friend class wxSound;
58 };
59
60
61 /// Simple sound class:
62 class wxSound : public wxSoundBase
63 {
64 public:
65 wxSound();
66 wxSound(const wxString& fileName, bool isResource = false);
67 wxSound(int size, const wxByte* data);
68 ~wxSound();
69
70 // Create from resource or file
71 bool Create(const wxString& fileName, bool isResource = false);
72 // Create from data
73 bool Create(int size, const wxByte* data);
74
75 bool IsOk() const { return m_data != NULL; }
76
77 // for internal use
78 static void UnloadBackend();
79
80 protected:
81 bool DoPlay(unsigned flags);
82
83 static void EnsureBackend();
84 void Free();
85 bool LoadWAV(const wxUint8 *data, size_t length, bool copyData);
86
87 static wxSoundBackend *ms_backend;
88 #if wxUSE_LIBSDL && wxUSE_PLUGINS
89 // FIXME - temporary, until we have plugins architecture
90 static wxDynamicLibrary *ms_backendSDL;
91 #endif
92
93 private:
94 wxSoundData *m_data;
95 };
96
97
98 // ----------------------------------------------------------------------------
99 // wxSoundBackend:
100 // ----------------------------------------------------------------------------
101
102 // This is interface to sound playing implementation. There are multiple
103 // sound architectures in use on Unix platforms and wxWindows can use several
104 // of them for playback, depending on their availability at runtime; hence
105 // the need for backends. This class is for use by wxWindows and people writing
106 // additional backends only, it is _not_ for use by applications!
107
108 class wxSoundBackend
109 {
110 public:
111 virtual ~wxSoundBackend() {}
112
113 // Returns the name of the backend (e.g. "Open Sound System")
114 virtual wxString GetName() const = 0;
115
116 // Returns priority (higher priority backends are tried first)
117 virtual int GetPriority() const = 0;
118
119 // Checks if the backend's audio system is available and the backend can
120 // be used for playback
121 virtual bool IsAvailable() const = 0;
122
123 // Returns true if the backend is capable of playing sound asynchronously.
124 // If false, then wxWindows creates a playback thread and handles async
125 // playback, otherwise it is left up to the backend (will usually be more
126 // effective)
127 virtual bool HasNativeAsyncPlayback() const = 0;
128
129 // Plays the sound. flags are same flags as those passed to wxSound::Play
130 virtual bool Play(wxSoundData *data, unsigned flags) = 0;
131 };
132
133
134 #endif // wxUSE_WAVE
135
136 #endif