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 <mutex>
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  std::mutex _mutex;
90 
91  // See dox in sound_handler.h
92  void mix(std::int16_t* outSamples, std::int16_t* inSamples,
93  unsigned int nSamples, float volume);
94 
95  void MixAudio (std::uint8_t *dst, const std::uint8_t *src, std::uint32_t len, int volume);
96 
97 public:
98 
100 
102 
103  // See dox in sound_handler.h
104  virtual int create_sound(std::unique_ptr<SimpleBuffer> data, std::unique_ptr<media::SoundInfo> sinfo);
105 
106  // See dox in sound_handler.h
107  // overridden to serialize access to the data buffer slot
108  virtual StreamBlockId addSoundBlock(unsigned char* data,
109  unsigned int data_bytes,
110  unsigned int sample_count,
111  int streamId);
112 
113  // See dox in sound_handler.h
114  virtual void stop_sound(int sound_handle);
115 
116  // See dox in sound_handler.h
117  virtual void delete_sound(int sound_handle);
118 
119  // See dox in sound_handler.h
120  virtual void reset();
121 
122  // See dox in sound_handler.h
123  virtual void stop_all_sounds();
124 
125  // See dox in sound_handler.h
126  virtual int get_volume(int sound_handle);
127 
128  // See dox in sound_handler.h
129  virtual void set_volume(int sound_handle, int volume);
130 
131  // See dox in sound_handler.h
132  virtual media::SoundInfo* get_sound_info(int soundHandle);
133 
134  // See dox in sound_handler.h
135  // overridden to close audio card
136  virtual void pause();
137 
138  // See dox in sound_handler.h
139  // overridden to open audio card
140  virtual void unpause();
141 
142  // See dox in sound_handler.h
143  virtual unsigned int get_duration(int sound_handle);
144 
145  // See dox in sound_handler.h
146  virtual unsigned int tell(int sound_handle);
147 
148  // See dox in sound_handler.h
149  // Overridden to unpause SDL audio
150  void plugInputStream(std::unique_ptr<InputStream> in);
151 
152  // See dox in sound_handler.h
153  void fetchSamples(std::int16_t* to, unsigned int nSamples);
154 
155  int audioTask();
156 };
157 
158 
159 
160 } // gnash.sound namespace
161 } // namespace gnash
162 
163 #endif // SOUND_HANDLER_AHI_H
virtual unsigned int get_duration(int sound_handle)
Definition: sound_handler_ahi.cpp:250
virtual int get_volume(int sound_handle)
Definition: sound_handler_ahi.cpp:228
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:73
virtual void stop_sound(int sound_handle)
Definition: sound_handler_ahi.cpp:205
virtual void stop_all_sounds()
Mixed functions:
Definition: sound_handler_ahi.cpp:220
virtual void delete_sound(int sound_handle)
Discard the sound data for an embedded event sound.
Definition: sound_handler_ahi.cpp:213
Sound mixer.
Definition: sound_handler.h:87
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
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:257
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:69
~AOS4_sound_handler()
Definition: sound_handler_ahi.cpp:82
virtual media::SoundInfo * get_sound_info(int soundHandle)
Definition: sound_handler_ahi.cpp:243
virtual void set_volume(int sound_handle, int volume)
Sets the volume for a given event sound.
Definition: sound_handler_ahi.cpp:236
void plugInputStream(std::unique_ptr< InputStream > in)
Plug an InputStream to the mixer.
Definition: sound_handler_ahi.cpp:396
void fetchSamples(std::int16_t *to, unsigned int nSamples)
Fetch mixed samples.
Definition: sound_handler_ahi.cpp:271
virtual void pause()
gnash calls this to pause audio
Definition: sound_handler_ahi.cpp:413
virtual void reset()
Discard all sound inputs (slots and aux streamers) and clear scheduling.
Definition: sound_handler_ahi.cpp:179
int audioTask()
Definition: sound_handler_ahi.cpp:504
virtual int create_sound(std::unique_ptr< SimpleBuffer > data, std::unique_ptr< media::SoundInfo > sinfo)
Definition: sound_handler_ahi.cpp:187
unsigned long StreamBlockId
Identifier of a streaming sound block.
Definition: sound_handler.h:97
virtual StreamBlockId addSoundBlock(unsigned char *data, unsigned int data_bytes, unsigned int sample_count, int streamId)
Definition: sound_handler_ahi.cpp:195
Definition: GnashKey.h:159
virtual void unpause()
gnash calls this to unpause audio
Definition: sound_handler_ahi.cpp:424