first very unfinished and unpolished version of the intro
[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   void set_looping(bool looping)
28   {
29     this->looping = looping;
30   }
31   bool get_looping() const
32   {
33     return looping;
34   }
35   
36 private:
37   static const size_t STREAMBUFFERSIZE = 1024 * 500;
38   static const size_t STREAMFRAGMENTS = 5;
39   static const size_t STREAMFRAGMENTSIZE 
40     = STREAMBUFFERSIZE / STREAMFRAGMENTS;
41
42   bool fillBufferAndQueue(ALuint buffer);
43   SoundFile* file;
44   ALuint buffers[STREAMFRAGMENTS];
45
46   FadeState fade_state;
47   Uint32 fade_start_ticks;
48   float fade_time;
49   bool looping;
50 };
51
52 #endif
53