• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

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 Free Software
00004 //   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 <string>
00026 #include <set> // for composition (InputStreams)
00027 #include <fstream> // for composition (file_stream)
00028 #include <boost/thread/mutex.hpp>
00029 
00030 #include <proto/dos.h>
00031 #include <proto/exec.h>
00032 #include <proto/ahi.h>
00033 
00034 #include <devices/ahi.h>
00035 #include <exec/memory.h>
00036 
00037 #include <sys/types.h>
00038 // Forward declarations
00039 namespace gnash {
00040     class SimpleBuffer;
00041     namespace sound {
00042         class EmbedSound;
00043         class InputStream;
00044     }
00045 }
00046 
00047 namespace gnash {
00048 namespace sound {
00049 
00051 class AOS4_sound_handler : public sound_handler
00052 {
00053 private:
00054         struct MsgPort          *_port;
00055         uint32                           _timerSig;
00056         struct TimeRequest      *_timerio;
00057         struct TimerIFace       *ITimer;
00058 
00059         struct AHIIFace         *IAHI;
00060         struct Library          *AHIBase;
00061         struct MsgPort          *AHImp;                                 //AHI Message Port
00062         struct AHIRequest       *AHIio;
00063         BYTE                             AHIDevice;
00064         struct AHIRequest       *AHIios[2];
00065         APTR                             AHIiocopy;
00066         ULONG                            AHICurBuf;
00067         bool                             AHIReqSent[2];
00068         UBYTE                           *PlayBuffer[2];
00069         ULONG                            BufferFill;
00070         UBYTE                           *BufferPointer;
00071         ULONG                            Buffer;
00072 
00073         struct Process          *AudioPump;
00074 
00075         bool TimerInit(void);
00076         void TimerExit(void);
00077         void TimerReset(uint32 microDelay);
00078 
00080     void initAudio();
00081     void openAudio();
00082     void closeAudio();
00083 
00084     bool _audioOpened;
00085         bool _closing;
00086 
00087         struct DeathMessage *_dmsg;     // the child Death Message
00088         struct MsgPort *_DMreplyport;   // and its port
00089         
00091     boost::mutex _mutex;
00092 
00094     mutable boost::mutex _mutedMutex;
00095 
00097     //
00100     std::ofstream file_stream;
00101 
00102     // write a .WAV file header
00103     void write_wave_header(std::ofstream& outfile);
00104 
00105     // See dox in sound_handler.h
00106     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
00107                 unsigned int nSamples, float volume);
00108 
00109         void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, boost::uint32_t len, int volume);
00110 
00111 public:
00112 
00113     AOS4_sound_handler(media::MediaHandler* m);
00114 
00115     AOS4_sound_handler(media::MediaHandler* m, const std::string& wave_file);
00116 
00117     ~AOS4_sound_handler();
00118 
00119     // See dox in sound_handler.h
00120     virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
00121 
00122     // See dox in sound_handler.h
00123     // overridden to serialize access to the data buffer slot
00124     virtual StreamBlockId addSoundBlock(unsigned char* data,
00125                                        unsigned int data_bytes,
00126                                        unsigned int sample_count,
00127                                        int streamId);
00128 
00129     // See dox in sound_handler.h
00130     virtual void    stop_sound(int sound_handle);
00131 
00132     // See dox in sound_handler.h
00133     virtual void    delete_sound(int sound_handle);
00134 
00135     // See dox in sound_handler.h
00136     virtual void reset();
00137 
00138     // See dox in sound_handler.h
00139     virtual void    stop_all_sounds();
00140 
00141     // See dox in sound_handler.h
00142     virtual int get_volume(int sound_handle);
00143 
00144     // See dox in sound_handler.h
00145     virtual void    set_volume(int sound_handle, int volume);
00146 
00147     // See dox in sound_handler.h
00148     virtual media::SoundInfo* get_sound_info(int soundHandle);
00149 
00150     // See dox in sound_handler.h
00151     // overridden to serialize access to the _muted member
00152     virtual void mute();
00153 
00154     // See dox in sound_handler.h
00155     // overridden to serialize access to the _muted member
00156     virtual void unmute();
00157 
00158     // See dox in sound_handler.h
00159     // overridden to serialize access to the _muted member
00160     virtual bool is_muted() const;
00161 
00162     // See dox in sound_handler.h
00163     // overridden to close audio card
00164     virtual void pause();
00165 
00166     // See dox in sound_handler.h
00167     // overridden to open audio card
00168     virtual void unpause();
00169 
00170     // See dox in sound_handler.h
00171     virtual unsigned int get_duration(int sound_handle);
00172 
00173     // See dox in sound_handler.h
00174     virtual unsigned int tell(int sound_handle);
00175 
00176     // See dox in sound_handler.h
00177     // Overridden to unpause SDL audio
00178     void plugInputStream(std::auto_ptr<InputStream> in);
00179 
00180     // See dox in sound_handler.h
00181     void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00182 
00183         int audioTask();
00184 };
00185 
00186 
00187 
00188 } // gnash.sound namespace
00189 } // namespace gnash
00190 
00191 #endif // SOUND_HANDLER_AHI_H

Generated on Thu Sep 30 2010 14:35:03 for Gnash by  doxygen 1.7.1