1 // sound_handler_haiku.h: Sound handling using Mkit media kit
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
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.
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.
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
20 #ifndef SOUND_HANDLER_MKIT_H
21 #define SOUND_HANDLER_MKIT_H
23 #include "sound_handler.h" // for inheritance
25 #include <set> // for composition (InputStreams)
26 #include <boost/thread/mutex.hpp>
27 #include <boost/scoped_ptr.hpp>
29 #include <SoundPlayer.h>
31 // Forward declarations
43 /// Mkit media kit based sound_handler
44 class Mkit_sound_handler
: public sound_handler
46 boost::scoped_ptr
<BSoundPlayer
> _soundplayer
;
48 /// play buffer handler function
49 static void FillNextBuffer(void *cookie
, void *buffer
, size_t size
,
50 const media_raw_audio_format
&format
);
52 /// @throw SoundException on error
57 /// Mutex for making sure threads doesn't mess things up
60 /// Mutex protecting _muted (defined in base class)
61 mutable boost::mutex _mutedMutex
;
63 // See dox in sound_handler.h
64 void mix(boost::int16_t* outSamples
, boost::int16_t* inSamples
,
65 unsigned int nSamples
, float volume
);
67 void MixAudio (boost::uint8_t *dst
, const boost::uint8_t *src
, boost::uint32_t len
, int volume
);
70 Mkit_sound_handler(media::MediaHandler
* m
);
72 ~Mkit_sound_handler();
74 // See dox in sound_handler.h
75 virtual int create_sound(std::auto_ptr
<SimpleBuffer
> data
, std::auto_ptr
<media::SoundInfo
> sinfo
);
77 // See dox in sound_handler.h
78 // overridden to serialize access to the data buffer slot
79 virtual StreamBlockId
addSoundBlock(unsigned char* data
,
80 unsigned int data_bytes
,
81 unsigned int sample_count
,
84 // See dox in sound_handler.h
85 virtual void stop_sound(int sound_handle
);
87 // See dox in sound_handler.h
88 virtual void delete_sound(int sound_handle
);
90 // See dox in sound_handler.h
93 // See dox in sound_handler.h
94 virtual void stop_all_sounds();
96 // See dox in sound_handler.h
97 virtual int get_volume(int sound_handle
);
99 // See dox in sound_handler.h
100 virtual void set_volume(int sound_handle
, int volume
);
102 // See dox in sound_handler.h
103 virtual media::SoundInfo
* get_sound_info(int soundHandle
);
105 // See dox in sound_handler.h
106 // overridden to serialize access to the _muted member
109 // See dox in sound_handler.h
110 // overridden to serialize access to the _muted member
111 virtual void unmute();
113 // See dox in sound_handler.h
114 // overridden to serialize access to the _muted member
115 virtual bool is_muted() const;
117 // See dox in sound_handler.h
118 // overridden to close audio card
119 virtual void pause();
121 // See dox in sound_handler.h
122 // overridden to open audio card
123 virtual void unpause();
125 // See dox in sound_handler.h
126 virtual unsigned int get_duration(int sound_handle
);
128 // See dox in sound_handler.h
129 virtual unsigned int tell(int sound_handle
);
131 // See dox in sound_handler.h
132 // Overridden to unpause SDL audio
133 void plugInputStream(std::auto_ptr
<InputStream
> in
);
135 // See dox in sound_handler.h
136 void fetchSamples(boost::int16_t* to
, unsigned int nSamples
);
139 } // gnash.sound namespace
142 #endif // SOUND_HANDLER_MKIT_H