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

sound_handler_sdl.h

Go to the documentation of this file.
00001 // sound_handler_sdl.h: Sound handling using standard SDL
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 
00021 #ifndef SOUND_HANDLER_SDL_H
00022 #define SOUND_HANDLER_SDL_H
00023 
00024 
00025 #include "sound_handler.h" // for inheritance
00026 
00027 #include <string>
00028 #include <set> // for composition (InputStreams)
00029 #include <fstream> // for composition (file_stream)
00030 #include <SDL_audio.h>
00031 #include <boost/thread/mutex.hpp>
00032 
00033 // Forward declarations
00034 namespace gnash {
00035     class SimpleBuffer;
00036     namespace sound {
00037         class EmbedSound;
00038         class InputStream;
00039     }
00040 }
00041 
00042 namespace gnash {
00043 namespace sound {
00044 
00046 class SDL_sound_handler : public sound_handler
00047 {
00048 private:
00049 
00051     SDL_AudioSpec audioSpec;
00052 
00054     void initAudio();
00055 
00056     void openAudio();
00057 
00058     void closeAudio();
00059 
00060     bool _audioOpened;
00061     
00063     boost::mutex _mutex;
00064 
00066     mutable boost::mutex _mutedMutex;
00067 
00069     //
00072     std::ofstream file_stream;
00073 
00074     // write a .WAV file header
00075     void write_wave_header(std::ofstream& outfile);
00076 
00077     // See dox in sound_handler.h
00078     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
00079                 unsigned int nSamples, float volume);
00080 
00081 
00083     //
00098     static void sdl_audio_callback (void *udata, Uint8 *stream, int buffer_length_in);
00099 
00100 public:
00101 
00102     SDL_sound_handler(media::MediaHandler* m);
00103 
00104     SDL_sound_handler(media::MediaHandler* m, const std::string& wave_file);
00105 
00106     ~SDL_sound_handler();
00107 
00108     // See dox in sound_handler.h
00109     virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
00110 
00111     // See dox in sound_handler.h
00112     // overridden to serialize access to the data buffer slot
00113     virtual StreamBlockId addSoundBlock(unsigned char* data,
00114                                        unsigned int data_bytes,
00115                                        unsigned int sample_count,
00116                                        int streamId);
00117 
00118     // See dox in sound_handler.h
00119     virtual void    stop_sound(int sound_handle);
00120 
00121     // See dox in sound_handler.h
00122     virtual void    delete_sound(int sound_handle);
00123 
00124     // See dox in sound_handler.h
00125     virtual void reset();
00126 
00127     // See dox in sound_handler.h
00128     virtual void    stop_all_sounds();
00129 
00130     // See dox in sound_handler.h
00131     virtual int get_volume(int sound_handle);
00132 
00133     // See dox in sound_handler.h
00134     virtual void    set_volume(int sound_handle, int volume);
00135         
00136     // See dox in sound_handler.h
00137     virtual media::SoundInfo* get_sound_info(int soundHandle);
00138 
00139     // See dox in sound_handler.h
00140     // overridden to serialize access to the _muted member
00141     virtual void mute();
00142 
00143     // See dox in sound_handler.h
00144     // overridden to serialize access to the _muted member
00145     virtual void unmute();
00146 
00147     // See dox in sound_handler.h
00148     // overridden to serialize access to the _muted member
00149     virtual bool is_muted() const;
00150 
00151     // See dox in sound_handler.h
00152     // overridden to close audio card
00153     virtual void pause();
00154 
00155     // See dox in sound_handler.h
00156     // overridden to open audio card
00157     virtual void unpause();
00158 
00159     // See dox in sound_handler.h
00160     virtual unsigned int get_duration(int sound_handle);
00161 
00162     // See dox in sound_handler.h
00163     virtual unsigned int tell(int sound_handle);
00164     
00165     // See dox in sound_handler.h
00166     // Overridden to unpause SDL audio
00167     void plugInputStream(std::auto_ptr<InputStream> in);
00168 
00169     // See dox in sound_handler.h
00170     void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00171 };
00172 
00173 } // gnash.sound namespace 
00174 } // namespace gnash
00175 
00176 #endif // SOUND_HANDLER_SDL_H

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