Gnash  0.8.11dev
sound_handler_sdl.h
Go to the documentation of this file.
1 // sound_handler_sdl.h: Sound handling using standard SDL
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 
21 #ifndef SOUND_HANDLER_SDL_H
22 #define SOUND_HANDLER_SDL_H
23 
24 
25 #include "sound_handler.h" // for inheritance
26 
27 #include <SDL_audio.h>
28 #include <boost/thread/mutex.hpp>
29 
30 // Forward declarations
31 namespace gnash {
32  class SimpleBuffer;
33  namespace sound {
34  class EmbedSound;
35  class InputStream;
36  }
37 }
38 
39 namespace gnash {
40 namespace sound {
41 
44 {
45 private:
46 
48  SDL_AudioSpec audioSpec;
49 
51  void initAudio();
52 
53  void openAudio();
54 
55  void closeAudio();
56 
57  bool _audioOpened;
58 
60  mutable boost::mutex _mutex;
61 
63  mutable boost::mutex _mutedMutex;
64 
65  // See dox in sound_handler.h
66  void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
67  unsigned int nSamples, float volume);
68 
69 
71  //
86  static void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in);
87 
88 public:
89 
91 
93 
94  virtual int createStreamingSound(const media::SoundInfo& sinfo);
95 
96  // See dox in sound_handler.h
97  virtual int create_sound(std::auto_ptr<SimpleBuffer> data,
98  const media::SoundInfo& sinfo);
99 
100  // See dox in sound_handler.h
101  // overridden to serialize access to the data buffer slot
102  virtual StreamBlockId addSoundBlock(std::auto_ptr<SimpleBuffer> buf,
103  size_t sample_count, int seekSamples, int streamId);
104 
105  // See dox in sound_handler.h
106  virtual void stopEventSound(int sound_handle);
107 
108  // See dox in sound_handler.h
109  virtual void stopAllEventSounds();
110 
111  virtual void stopStreamingSound(int sound_handle);
112 
113  // See dox in sound_handler.h
114  virtual void delete_sound(int sound_handle);
115 
116  // See dox in sound_handler.h
117  virtual void reset();
118 
119  // See dox in sound_handler.h
120  virtual void stop_all_sounds();
121 
122  // See dox in sound_handler.h
123  virtual int get_volume(int sound_handle) const;
124 
125  // See dox in sound_handler.h
126  virtual void set_volume(int sound_handle, int volume);
127 
128  // See dox in sound_handler.h
129  virtual media::SoundInfo* get_sound_info(int soundHandle) const;
130 
131  // See dox in sound_handler.h
132  // overridden to serialize access to the _muted member
133  virtual void mute();
134 
135  // See dox in sound_handler.h
136  // overridden to serialize access to the _muted member
137  virtual void unmute();
138 
139  // See dox in sound_handler.h
140  // overridden to serialize access to the _muted member
141  virtual bool is_muted() const;
142 
143  // See dox in sound_handler.h
144  // overridden to close audio card
145  virtual void pause();
146 
147  // See dox in sound_handler.h
148  // overridden to open audio card
149  virtual void unpause();
150 
151  // See dox in sound_handler.h
152  virtual unsigned int get_duration(int sound_handle) const;
153 
154  // See dox in sound_handler.h
155  virtual unsigned int tell(int sound_handle) const;
156 
157  // See dox in sound_handler.h
158  // Overridden to unpause SDL audio
159  void plugInputStream(std::auto_ptr<InputStream> in);
160 
161  // Overidden to provide thread safety.
162  void unplugInputStream(InputStream* id);
163 
164  // See dox in sound_handler.h
165  void fetchSamples(boost::int16_t* to, unsigned int nSamples);
166 };
167 
168 } // gnash.sound namespace
169 } // namespace gnash
170 
171 #endif // SOUND_HANDLER_SDL_H
A sound input stream.
Definition: InputStream.h:47
void fetchSamples(boost::int16_t *to, unsigned int nSamples)
Fetch mixed samples.
Definition: sound_handler_sdl.cpp:241
Definition: klash_part.cpp:331
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
virtual int createStreamingSound(const media::SoundInfo &sinfo)
Streaming sound functions:
Definition: sound_handler_sdl.cpp:137
virtual void unmute()
Call this to unmute audio.
Definition: sound_handler_sdl.cpp:323
virtual int get_volume(int sound_handle) const
Gets the volume for a given sound buffer slot.
Definition: sound_handler_sdl.cpp:199
virtual void stop_all_sounds()
Mixed functions:
Definition: sound_handler_sdl.cpp:191
virtual void stopEventSound(int sound_handle)
Remove scheduled requests to play the specified sound buffer slot.
Definition: sound_handler_sdl.cpp:162
void plugInputStream(std::auto_ptr< InputStream > in)
Plug an InputStream to the mixer.
Definition: sound_handler_sdl.cpp:298
void unplugInputStream(InputStream *id)
Unplug an external InputStream from the mixer.
Definition: sound_handler_sdl.cpp:355
virtual void stopAllEventSounds()
Stop all instances of all playing event sounds.
Definition: sound_handler_sdl.cpp:169
virtual StreamBlockId addSoundBlock(std::auto_ptr< SimpleBuffer > buf, size_t sample_count, int seekSamples, int streamId)
Definition: sound_handler_sdl.cpp:152
Sound mixer.
Definition: sound_handler.h:87
virtual bool is_muted() const
Returns whether or not sound is muted.
Definition: sound_handler_sdl.cpp:330
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
virtual void mute()
Call this to mute audio.
Definition: sound_handler_sdl.cpp:316
virtual unsigned int tell(int sound_handle) const
Gets the playhead position in milliseconds of an event sound.
Definition: sound_handler_sdl.cpp:228
virtual media::SoundInfo * get_sound_info(int soundHandle) const
Returns a SoundInfo object for the sound with the given id.
Definition: sound_handler_sdl.cpp:214
virtual unsigned int get_duration(int sound_handle) const
Gets the duration in milliseconds of an event sound.
Definition: sound_handler_sdl.cpp:221
virtual void unpause()
gnash calls this to unpause audio
Definition: sound_handler_sdl.cpp:344
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:68
virtual void reset()
Discard all sound inputs (slots and aux streamers) and clear scheduling.
Definition: sound_handler_sdl.cpp:116
virtual void pause()
gnash calls this to pause audio
Definition: sound_handler_sdl.cpp:337
virtual void delete_sound(int sound_handle)
Discard the sound data for an embedded event sound.
Definition: sound_handler_sdl.cpp:184
SDL-based sound_handler.
Definition: sound_handler_sdl.h:43
~SDL_sound_handler()
Definition: sound_handler_sdl.cpp:122
virtual void stopStreamingSound(int sound_handle)
Remove scheduled requests to play the specified sound buffer slot.
Definition: sound_handler_sdl.cpp:176
unsigned long StreamBlockId
Identifier of a streaming sound block.
Definition: sound_handler.h:97
Definition: GnashKey.h:159
SDL_sound_handler(media::MediaHandler *m)
Definition: sound_handler_sdl.cpp:107
virtual void set_volume(int sound_handle, int volume)
Sets the volume for a given event sound.
Definition: sound_handler_sdl.cpp:207
virtual int create_sound(std::auto_ptr< SimpleBuffer > data, const media::SoundInfo &sinfo)
Event sound functions:
Definition: sound_handler_sdl.cpp:144