]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/sound.h
Make Smartphone buildable with current flags.
[wxWidgets.git] / include / wx / unix / sound.h
CommitLineData
9be32e8f 1/////////////////////////////////////////////////////////////////////////////
cad1a197 2// Name: 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
65571936 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
VS
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
29class wxSoundBackend;
30class wxSound;
31class wxDynamicLibrary;
32
33/// Sound data, as loaded from .wav file:
34class wxSoundData
35{
36public:
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
53private:
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:
62class wxSound : public wxSoundBase
63{
64public:
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; }
83f7f12d
VS
76
77 // Stop playing any sound
78 static void Stop();
79
80 // Returns true if a sound is being played
81 static bool IsPlaying();
9be32e8f
VS
82
83 // for internal use
84 static void UnloadBackend();
85
86protected:
cad1a197 87 bool DoPlay(unsigned flags) const;
9be32e8f
VS
88
89 static void EnsureBackend();
90 void Free();
91 bool LoadWAV(const wxUint8 *data, size_t length, bool copyData);
92
93 static wxSoundBackend *ms_backend;
94#if wxUSE_LIBSDL && wxUSE_PLUGINS
95 // FIXME - temporary, until we have plugins architecture
96 static wxDynamicLibrary *ms_backendSDL;
97#endif
98
99private:
100 wxSoundData *m_data;
101};
102
103
104// ----------------------------------------------------------------------------
105// wxSoundBackend:
106// ----------------------------------------------------------------------------
107
108// This is interface to sound playing implementation. There are multiple
77ffb593 109// sound architectures in use on Unix platforms and wxWidgets can use several
9be32e8f 110// of them for playback, depending on their availability at runtime; hence
77ffb593
JS
111// the need for backends. This class is for use by wxWidgets and people writing
112// additional backends only, it is _not_ for use by applications!
9be32e8f 113
83f7f12d
VS
114// Structure that holds playback status information
115struct wxSoundPlaybackStatus
116{
117 // playback is in progress
118 bool m_playing;
119 // main thread called wxSound::Stop()
120 bool m_stopRequested;
121};
122
123// Audio backend interface
9be32e8f
VS
124class wxSoundBackend
125{
126public:
127 virtual ~wxSoundBackend() {}
128
129 // Returns the name of the backend (e.g. "Open Sound System")
130 virtual wxString GetName() const = 0;
131
132 // Returns priority (higher priority backends are tried first)
133 virtual int GetPriority() const = 0;
134
135 // Checks if the backend's audio system is available and the backend can
136 // be used for playback
137 virtual bool IsAvailable() const = 0;
138
139 // Returns true if the backend is capable of playing sound asynchronously.
77ffb593 140 // If false, then wxWidgets creates a playback thread and handles async
9be32e8f 141 // playback, otherwise it is left up to the backend (will usually be more
83f7f12d 142 // effective).
9be32e8f 143 virtual bool HasNativeAsyncPlayback() const = 0;
83f7f12d
VS
144
145 // Plays the sound. flags are same flags as those passed to wxSound::Play.
146 // The function should periodically check the value of
147 // status->m_stopRequested and terminate if it is set to true (it may
148 // be modified by another thread)
149 virtual bool Play(wxSoundData *data, unsigned flags,
150 volatile wxSoundPlaybackStatus *status) = 0;
151
152 // Stops playback (if something is played).
153 virtual void Stop() = 0;
154
155 // Returns true if the backend is playing anything at the moment.
156 // (This method is never called for backends that don't support async
157 // playback.)
158 virtual bool IsPlaying() const = 0;
9be32e8f
VS
159};
160
161
cad1a197 162#endif // wxUSE_SOUND
9be32e8f
VS
163
164#endif