05342eb486b2a5c2d34d36824ebbc26bfbe83466
[supertux.git] / src / audio / stream_sound_source.hpp
1 #ifndef __STREAM_SOUND_SOURCE_H__
2 #define __STREAM_SOUND_SOURCE_H__
3
4 #include <stdio.h>
5 #include <SDL.h>
6 #include "sound_source.hpp"
7
8 class SoundFile;
9
10 class StreamSoundSource : public SoundSource
11 {
12 public:
13   StreamSoundSource();
14   virtual ~StreamSoundSource();
15
16   void set_sound_file(SoundFile* file);
17
18   enum FadeState { NoFading, FadingOn, FadingOff };
19
20   void set_fading(FadeState state, float fadetime);
21   FadeState get_fade_state() const
22   {
23       return fade_state;
24   }
25   void update();
26   
27 private:
28   static const size_t STREAMBUFFERSIZE = 1024 * 500;
29   static const size_t STREAMFRAGMENTS = 5;
30   static const size_t STREAMFRAGMENTSIZE 
31     = STREAMBUFFERSIZE / STREAMFRAGMENTS;
32
33   void fillBufferAndQueue(ALuint buffer);
34   SoundFile* file;
35   ALuint buffers[STREAMFRAGMENTS];
36
37   FadeState fade_state;
38   Uint32 fade_start_ticks;
39   float fade_time;
40 };
41
42 #endif
43