support for fading music
[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(SoundFile* file);
14   virtual ~StreamSoundSource();
15
16   enum FadeState { NoFading, FadingOn, FadingOff };
17
18   void setFading(FadeState state, float fadetime);
19   void update();
20   
21 private:
22   static const size_t STREAMBUFFERSIZE = 1024 * 500;
23   static const size_t STREAMFRAGMENTS = 5;
24   static const size_t STREAMFRAGMENTSIZE 
25     = STREAMBUFFERSIZE / STREAMFRAGMENTS;
26
27   void fillBufferAndQueue(ALuint buffer);
28   SoundFile* file;
29   ALuint buffers[STREAMFRAGMENTS];
30   ALenum format;
31
32   FadeState fade_state;
33   Uint32 fade_start_ticks;
34   float fade_time;
35 };
36
37 #endif
38