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