Gnash  0.8.11dev
sound_handler_ahi.h
Go to the documentation of this file.
1 // sound_handler_ahi.h: Sound handling using standard AHI
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 #ifndef SOUND_HANDLER_AHI_H
21 #define SOUND_HANDLER_AHI_H
22 
23 #include "sound_handler.h" // for inheritance
24 
25 #include <set> // for composition (InputStreams)
26 #include <boost/thread/mutex.hpp>
27 
28 #include <proto/dos.h>
29 #include <proto/exec.h>
30 #include <proto/ahi.h>
31 
32 #include <devices/ahi.h>
33 #include <exec/memory.h>
34 
35 #include <sys/types.h>
36 // Forward declarations
37 namespace gnash {
38  class SimpleBuffer;
39  namespace sound {
40  class EmbedSound;
41  class InputStream;
42  }
43 }
44 
45 namespace gnash {
46 namespace sound {
47 
50 {
51 private:
52  struct MsgPort *_port;
53  uint32 _timerSig;
54  struct TimeRequest *_timerio;
55  struct TimerIFace *ITimer;
56 
57  struct AHIIFace *IAHI;
58  struct Library *AHIBase;
59  struct MsgPort *AHImp; //AHI Message Port
60  struct AHIRequest *AHIio;
61  BYTE AHIDevice;
62  struct AHIRequest *AHIios[2];
63  APTR AHIiocopy;
64  ULONG AHICurBuf;
65  bool AHIReqSent[2];
66  UBYTE *PlayBuffer[2];
67  ULONG BufferFill;
68  UBYTE *BufferPointer;
69  ULONG Buffer;
70 
71  struct Process *AudioPump;
72 
73  bool TimerInit(void);
74  void TimerExit(void);
75  void TimerReset(uint32 microDelay);
76 
78  void initAudio();
79  void openAudio();
80  void closeAudio();
81 
82  bool _audioOpened;
83  bool _closing;
84 
85  struct DeathMessage *_dmsg; // the child Death Message
86  struct MsgPort *_DMreplyport; // and its port
87 
89  boost::mutex _mutex;
90 
92  mutable boost::mutex _mutedMutex;
93 
94  // See dox in sound_handler.h
95  void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
96  unsigned int nSamples, float volume);
97 
98  void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, boost::uint32_t len, int volume);
99 
100 public:
101 
103 
105 
106  // See dox in sound_handler.h
107  virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
108 
109  // See dox in sound_handler.h
110  // overridden to serialize access to the data buffer slot
111  virtual StreamBlockId addSoundBlock(unsigned char* data,
112  unsigned int data_bytes,
113  unsigned int sample_count,
114  int streamId);
115 
116  // See dox in sound_handler.h
117  virtual void stop_sound(int sound_handle);
118 
119  // See dox in sound_handler.h
120  virtual void delete_sound(int sound_handle);
121 
122  // See dox in sound_handler.h
123  virtual void reset();
124 
125  // See dox in sound_handler.h
126  virtual void stop_all_sounds();
127 
128  // See dox in sound_handler.h
129  virtual int get_volume(int sound_handle);
130 
131  // See dox in sound_handler.h
132  virtual void set_volume(int sound_handle, int volume);
133 
134  // See dox in sound_handler.h
135  virtual media::SoundInfo* get_sound_info(int soundHandle);
136 
137  // See dox in sound_handler.h
138  // overridden to serialize access to the _muted member
139  virtual void mute();
140 
141  // See dox in sound_handler.h
142  // overridden to serialize access to the _muted member
143  virtual void unmute();
144 
145  // See dox in sound_handler.h
146  // overridden to serialize access to the _muted member
147  virtual bool is_muted() const;
148 
149  // See dox in sound_handler.h
150  // overridden to close audio card
151  virtual void pause();
152 
153  // See dox in sound_handler.h
154  // overridden to open audio card
155  virtual void unpause();
156 
157  // See dox in sound_handler.h
158  virtual unsigned int get_duration(int sound_handle);
159 
160  // See dox in sound_handler.h
161  virtual unsigned int tell(int sound_handle);
162 
163  // See dox in sound_handler.h
164  // Overridden to unpause SDL audio
165  void plugInputStream(std::auto_ptr<InputStream> in);
166 
167  // See dox in sound_handler.h
168  void fetchSamples(boost::int16_t* to, unsigned int nSamples);
169 
170  int audioTask();
171 };
172 
173 
174 
175 } // gnash.sound namespace
176 } // namespace gnash
177 
178 #endif // SOUND_HANDLER_AHI_H
virtual unsigned int get_duration(int sound_handle)
Definition: sound_handler_ahi.cpp:251
virtual int get_volume(int sound_handle)
Definition: sound_handler_ahi.cpp:229
virtual bool is_muted() const
Returns whether or not sound is muted.
Definition: sound_handler_ahi.cpp:428
Definition: klash_part.cpp:331
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
AOS4_sound_handler(media::MediaHandler *m)
Definition: sound_handler_ahi.cpp:74
virtual void stop_sound(int sound_handle)
Definition: sound_handler_ahi.cpp:206
virtual void stop_all_sounds()
Mixed functions:
Definition: sound_handler_ahi.cpp:221
virtual void delete_sound(int sound_handle)
Discard the sound data for an embedded event sound.
Definition: sound_handler_ahi.cpp:214
Sound mixer.
Definition: sound_handler.h:87
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
AHI-based sound_handler.
Definition: sound_handler_ahi.h:49
virtual unsigned int tell(int sound_handle)
Definition: sound_handler_ahi.cpp:258
void plugInputStream(std::auto_ptr< InputStream > in)
Plug an InputStream to the mixer.
Definition: sound_handler_ahi.cpp:397
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:68
~AOS4_sound_handler()
Definition: sound_handler_ahi.cpp:83
virtual media::SoundInfo * get_sound_info(int soundHandle)
Definition: sound_handler_ahi.cpp:244
virtual void set_volume(int sound_handle, int volume)
Sets the volume for a given event sound.
Definition: sound_handler_ahi.cpp:237
virtual void unmute()
Call this to unmute audio.
Definition: sound_handler_ahi.cpp:421
virtual void pause()
gnash calls this to pause audio
Definition: sound_handler_ahi.cpp:435
virtual void reset()
Discard all sound inputs (slots and aux streamers) and clear scheduling.
Definition: sound_handler_ahi.cpp:180
int audioTask()
Definition: sound_handler_ahi.cpp:526
virtual int create_sound(std::auto_ptr< SimpleBuffer > data, std::auto_ptr< media::SoundInfo > sinfo)
Definition: sound_handler_ahi.cpp:188
unsigned long StreamBlockId
Identifier of a streaming sound block.
Definition: sound_handler.h:97
virtual void mute()
Call this to mute audio.
Definition: sound_handler_ahi.cpp:414
virtual StreamBlockId addSoundBlock(unsigned char *data, unsigned int data_bytes, unsigned int sample_count, int streamId)
Definition: sound_handler_ahi.cpp:196
Definition: GnashKey.h:159
void fetchSamples(boost::int16_t *to, unsigned int nSamples)
Fetch mixed samples.
Definition: sound_handler_ahi.cpp:272
virtual void unpause()
gnash calls this to unpause audio
Definition: sound_handler_ahi.cpp:446