Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SOUND_HANDLER_SDL_H
00022 #define SOUND_HANDLER_SDL_H
00023
00024
00025 #include "sound_handler.h"
00026
00027 #include <string>
00028 #include <set>
00029 #include <fstream>
00030 #include <SDL_audio.h>
00031 #include <boost/thread/mutex.hpp>
00032
00033
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
00075 void write_wave_header(std::ofstream& outfile);
00076
00077
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
00109 virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
00110
00111
00112
00113 virtual StreamBlockId addSoundBlock(unsigned char* data,
00114 unsigned int data_bytes,
00115 unsigned int sample_count,
00116 int streamId);
00117
00118
00119 virtual void stop_sound(int sound_handle);
00120
00121
00122 virtual void delete_sound(int sound_handle);
00123
00124
00125 virtual void reset();
00126
00127
00128 virtual void stop_all_sounds();
00129
00130
00131 virtual int get_volume(int sound_handle);
00132
00133
00134 virtual void set_volume(int sound_handle, int volume);
00135
00136
00137 virtual media::SoundInfo* get_sound_info(int soundHandle);
00138
00139
00140
00141 virtual void mute();
00142
00143
00144
00145 virtual void unmute();
00146
00147
00148
00149 virtual bool is_muted() const;
00150
00151
00152
00153 virtual void pause();
00154
00155
00156
00157 virtual void unpause();
00158
00159
00160 virtual unsigned int get_duration(int sound_handle);
00161
00162
00163 virtual unsigned int tell(int sound_handle);
00164
00165
00166
00167 void plugInputStream(std::auto_ptr<InputStream> in);
00168
00169
00170 void fetchSamples(boost::int16_t* to, unsigned int nSamples);
00171 };
00172
00173 }
00174 }
00175
00176 #endif // SOUND_HANDLER_SDL_H