]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/sound.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / unix / sound.h
CommitLineData
9be32e8f 1/////////////////////////////////////////////////////////////////////////////
1b88201f 2// Name: wx/unix/sound.h
9be32e8f
VS
3// Purpose: wxSound class
4// Author: Julian Smart, Vaclav Slavik
5// Modified by:
6// Created: 25/10/98
9be32e8f 7// Copyright: (c) Julian Smart, Vaclav Slavik
1b88201f 8// Licence: wxWindows licence
9be32e8f
VS
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_SOUND_H_
12#define _WX_SOUND_H_
13
14#include "wx/defs.h"
15
cad1a197 16#if wxUSE_SOUND
9be32e8f 17
9be32e8f
VS
18#include "wx/object.h"
19
20// ----------------------------------------------------------------------------
21// wxSound: simple audio playback class
22// ----------------------------------------------------------------------------
23
b5dbe15d
VS
24class WXDLLIMPEXP_FWD_ADV wxSoundBackend;
25class WXDLLIMPEXP_FWD_ADV wxSound;
26class WXDLLIMPEXP_FWD_BASE wxDynamicLibrary;
9be32e8f
VS
27
28/// Sound data, as loaded from .wav file:
968eb2ef 29class WXDLLIMPEXP_ADV wxSoundData
9be32e8f
VS
30{
31public:
32 wxSoundData() : m_refCnt(1) {}
33 void IncRef();
34 void DecRef();
1b88201f 35
9be32e8f
VS
36 // .wav header information:
37 unsigned m_channels; // num of channels (mono:1, stereo:2)
38 unsigned m_samplingRate;
39 unsigned m_bitsPerSample; // if 8, then m_data contains unsigned 8bit
40 // samples (wxUint8), if 16 then signed 16bit
41 // (wxInt16)
42 unsigned m_samples; // length in samples:
1b88201f 43
9be32e8f
VS
44 // wave data:
45 size_t m_dataBytes;
46 wxUint8 *m_data; // m_dataBytes bytes of data
47
48private:
49 ~wxSoundData();
50 unsigned m_refCnt;
51 wxUint8 *m_dataWithHeader; // ditto, but prefixed with .wav header
52 friend class wxSound;
53};
54
55
56/// Simple sound class:
968eb2ef 57class WXDLLIMPEXP_ADV wxSound : public wxSoundBase
9be32e8f
VS
58{
59public:
60 wxSound();
61 wxSound(const wxString& fileName, bool isResource = false);
c559c4b3 62 wxSound(size_t size, const void* data);
d3c7fc99 63 virtual ~wxSound();
9be32e8f
VS
64
65 // Create from resource or file
66 bool Create(const wxString& fileName, bool isResource = false);
67 // Create from data
c559c4b3 68 bool Create(size_t size, const void* data);
9be32e8f
VS
69
70 bool IsOk() const { return m_data != NULL; }
1b88201f 71
83f7f12d
VS
72 // Stop playing any sound
73 static void Stop();
74
75 // Returns true if a sound is being played
76 static bool IsPlaying();
1b88201f 77
9be32e8f
VS
78 // for internal use
79 static void UnloadBackend();
1b88201f 80
9be32e8f 81protected:
cad1a197 82 bool DoPlay(unsigned flags) const;
9be32e8f
VS
83
84 static void EnsureBackend();
85 void Free();
c559c4b3 86 bool LoadWAV(const void* data, size_t length, bool copyData);
1b88201f 87
9be32e8f
VS
88 static wxSoundBackend *ms_backend;
89#if wxUSE_LIBSDL && wxUSE_PLUGINS
90 // FIXME - temporary, until we have plugins architecture
91 static wxDynamicLibrary *ms_backendSDL;
92#endif
93
94private:
95 wxSoundData *m_data;
96};
97
98
99// ----------------------------------------------------------------------------
1b88201f 100// wxSoundBackend:
9be32e8f
VS
101// ----------------------------------------------------------------------------
102
103// This is interface to sound playing implementation. There are multiple
77ffb593 104// sound architectures in use on Unix platforms and wxWidgets can use several
9be32e8f 105// of them for playback, depending on their availability at runtime; hence
77ffb593
JS
106// the need for backends. This class is for use by wxWidgets and people writing
107// additional backends only, it is _not_ for use by applications!
9be32e8f 108
83f7f12d
VS
109// Structure that holds playback status information
110struct wxSoundPlaybackStatus
111{
112 // playback is in progress
113 bool m_playing;
114 // main thread called wxSound::Stop()
115 bool m_stopRequested;
116};
117
118// Audio backend interface
968eb2ef 119class WXDLLIMPEXP_ADV wxSoundBackend
9be32e8f
VS
120{
121public:
122 virtual ~wxSoundBackend() {}
1b88201f 123
9be32e8f
VS
124 // Returns the name of the backend (e.g. "Open Sound System")
125 virtual wxString GetName() const = 0;
126
127 // Returns priority (higher priority backends are tried first)
128 virtual int GetPriority() const = 0;
129
130 // Checks if the backend's audio system is available and the backend can
131 // be used for playback
132 virtual bool IsAvailable() const = 0;
133
134 // Returns true if the backend is capable of playing sound asynchronously.
77ffb593 135 // If false, then wxWidgets creates a playback thread and handles async
9be32e8f 136 // playback, otherwise it is left up to the backend (will usually be more
83f7f12d 137 // effective).
9be32e8f 138 virtual bool HasNativeAsyncPlayback() const = 0;
1b88201f 139
83f7f12d
VS
140 // Plays the sound. flags are same flags as those passed to wxSound::Play.
141 // The function should periodically check the value of
142 // status->m_stopRequested and terminate if it is set to true (it may
143 // be modified by another thread)
144 virtual bool Play(wxSoundData *data, unsigned flags,
145 volatile wxSoundPlaybackStatus *status) = 0;
146
147 // Stops playback (if something is played).
148 virtual void Stop() = 0;
149
150 // Returns true if the backend is playing anything at the moment.
151 // (This method is never called for backends that don't support async
152 // playback.)
153 virtual bool IsPlaying() const = 0;
9be32e8f
VS
154};
155
156
cad1a197 157#endif // wxUSE_SOUND
9be32e8f 158
0c7e0a87
VZ
159#endif // _WX_SOUND_H_
160