dbf-halloween2015
view src/audio/stream.h @ 3:c37fe5d8a4ed
windows port
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 06:04:28 +0200 |
parents | |
children |
line source
1 #ifndef STREAM_H_
2 #define STREAM_H_
4 #include <pthread.h>
6 #define AUDIO_FFT_BINS 16
7 #define AUDIO_FFT_DOWNSAMPLE 1
9 #define AUDIO_NUM_BUFFERS 8
10 #define AUDIO_BUFFER_MSEC 32
11 // TODO should the sampling rate be hardcoded?
12 #define AUDIO_BUFFER_SAMPLES (AUDIO_BUFFER_MSEC * 44100 / 1000)
13 // TODO unhardcode the channels number
14 #define AUDIO_BUFFER_BYTES (AUDIO_BUFFER_SAMPLES * 2 * 2)
16 #define AUDIO_FFT_SAMPLES (AUDIO_BUFFER_SAMPLES / AUDIO_FFT_DOWNSAMPLE)
18 enum AUDIO_PLAYMODE
19 {
20 AUDIO_PLAYMODE_ONCE,
21 AUDIO_PLAYMODE_LOOP
22 };
24 struct AudioStreamBuffer {
25 char samples[AUDIO_BUFFER_BYTES];
27 int num_samples;
28 int channels;
29 int sample_rate;
30 };
32 class AudioStream {
33 private:
34 pthread_t play_thread;
35 pthread_mutex_t mutex;
37 float volume, pitch;
38 bool done, loop;
39 unsigned int poll_interval;
40 unsigned int alsrc;
42 virtual bool more_samples(AudioStreamBuffer *buf) = 0;
44 public:
45 void poll_loop();
47 AudioStream();
48 virtual ~AudioStream();
50 virtual bool open(const char *fname);
51 virtual void close();
53 virtual void set_volume(float vol);
54 virtual float get_volume() const;
56 virtual void set_pitch(float p);
57 virtual float get_pitch() const;
59 virtual void play(AUDIO_PLAYMODE mode);
60 virtual void stop();
62 virtual void rewind() = 0;
63 };
65 #endif // AUDIO_STREAM_H_