Gnash  0.8.10
sound_handler_ahi.h
Go to the documentation of this file.
00001 // sound_handler_ahi.h: Sound handling using standard AHI
00002 //
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 #ifndef SOUND_HANDLER_AHI_H
00021 #define SOUND_HANDLER_AHI_H
00022 
00023 #include "sound_handler.h" // for inheritance
00024 
00025 #include <set> // for composition (InputStreams)
00026 #include <boost/thread/mutex.hpp>
00027 
00028 #include <proto/dos.h>
00029 #include <proto/exec.h>
00030 #include <proto/ahi.h>
00031 
00032 #include <devices/ahi.h>
00033 #include <exec/memory.h>
00034 
00035 #include <sys/types.h>
00036 // Forward declarations
00037 namespace gnash {
00038     class SimpleBuffer;
00039     namespace sound {
00040         class EmbedSound;
00041         class InputStream;
00042     }
00043 }
00044 
00045 namespace gnash {
00046 namespace sound {
00047 
00049 class AOS4_sound_handler : public sound_handler
00050 {
00051 private:
00052         struct MsgPort          *_port;
00053         uint32                           _timerSig;
00054         struct TimeRequest      *_timerio;
00055         struct TimerIFace       *ITimer;
00056 
00057         struct AHIIFace         *IAHI;
00058         struct Library          *AHIBase;
00059         struct MsgPort          *AHImp;                                 //AHI Message Port
00060         struct AHIRequest       *AHIio;
00061         BYTE                             AHIDevice;
00062         struct AHIRequest       *AHIios[2];
00063         APTR                             AHIiocopy;
00064         ULONG                            AHICurBuf;
00065         bool                             AHIReqSent[2];
00066         UBYTE                           *PlayBuffer[2];
00067         ULONG                            BufferFill;
00068         UBYTE                           *BufferPointer;
00069         ULONG                            Buffer;
00070 
00071         struct Process          *AudioPump;
00072 
00073         bool TimerInit(void);
00074         void TimerExit(void);
00075         void TimerReset(uint32 microDelay);
00076 
00078     void initAudio();
00079     void openAudio();
00080     void closeAudio();
00081 
00082     bool _audioOpened;
00083         bool _closing;
00084 
00085         struct DeathMessage *_dmsg;     // the child Death Message
00086         struct MsgPort *_DMreplyport;   // and its port
00087         
00089     boost::mutex _mutex;
00090 
00092     mutable boost::mutex _mutedMutex;
00093 
00094     // See dox in sound_handler.h
00095     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
00096                 unsigned int nSamples, float volume);
00097 
00098         void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, boost::uint32_t len, int volume);
00099 
00100 public:
00101 
00102     AOS4_sound_handler(media::MediaHandler* m);
00103 
00104     ~AOS4_sound_handler();
00105 
00106     // See dox in sound_handler.h
00107     virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
00108 
00109     // See dox in sound_handler.h
00110     // overridden to serialize access to the data buffer slot
00111     virtual StreamBlockId addSoundBlock(unsigned char* data,
00112                                        unsigned int data_bytes,
00113                                        unsigned int sample_count,
00114                                        int streamId);
00115 
00116     // See dox in sound_handler.h
00117     virtual void    stop_sound(int sound_handle);
00118 
00119     // See dox in sound_handler.h
00120     virtual void    delete_sound(int sound_handle);
00121 
00122     // See dox in sound_handler.h
00123     virtual void reset();
00124 
00125     // See dox in sound_handler.h
00126     virtual void    stop_all_sounds();
00127 
00128     // See dox in sound_handler.h
00129     virtual int get_volume(int sound_handle);
00130 
00131     // See dox in sound_handler.h
00132     virtual void    set_volume(int sound_handle, int volume);
00133 
00134     // See dox in sound_handler.h
00135     virtual media::SoundInfo* get_sound_info(int soundHandle);
00136 
00137     // See dox in sound_handler.h
00138     // overridden to serialize access to the _muted member
00139     virtual void mute();
00140 
00141     // See dox in sound_handler.h
00142     // overridden to serialize access to the _muted member
00143     virtual void unmute();
00144 
00145     // See dox in sound_handler.h
00146     // overridden to serialize access to the _muted member
00147     virtual bool is_muted() const;
00148 
00149     // See dox in sound_handler.h
00150     // overridden to close audio card
00151     virtual void pause();
00152 
00153     // See dox in sound_handler.h
00154     // overridden to open audio card
00155     virtual void unpause();
00156 
00157     // See dox in sound_handler.h
00158     virtual unsigned int get_duration(int sound_handle);
00159 
00160     // See dox in sound_handler.h
00161     virtual unsigned int tell(int sound_handle);
00162 
00163     // See dox in sound_handler.h
00164     // Overridden to unpause SDL audio
00165     void plugInputStream(std::auto_ptr<InputStream> in);
00166 
00167     // See dox in sound_handler.h
00168     void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00169 
00170         int audioTask();
00171 };
00172 
00173 
00174 
00175 } // gnash.sound namespace
00176 } // namespace gnash
00177 
00178 #endif // SOUND_HANDLER_AHI_H