dbf-halloween2015

annotate 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
rev   line source
nuclear@0 1 #ifndef STREAM_H_
nuclear@0 2 #define STREAM_H_
nuclear@0 3
nuclear@0 4 #include <pthread.h>
nuclear@0 5
nuclear@0 6 #define AUDIO_FFT_BINS 16
nuclear@0 7 #define AUDIO_FFT_DOWNSAMPLE 1
nuclear@0 8
nuclear@0 9 #define AUDIO_NUM_BUFFERS 8
nuclear@0 10 #define AUDIO_BUFFER_MSEC 32
nuclear@0 11 // TODO should the sampling rate be hardcoded?
nuclear@0 12 #define AUDIO_BUFFER_SAMPLES (AUDIO_BUFFER_MSEC * 44100 / 1000)
nuclear@0 13 // TODO unhardcode the channels number
nuclear@0 14 #define AUDIO_BUFFER_BYTES (AUDIO_BUFFER_SAMPLES * 2 * 2)
nuclear@0 15
nuclear@0 16 #define AUDIO_FFT_SAMPLES (AUDIO_BUFFER_SAMPLES / AUDIO_FFT_DOWNSAMPLE)
nuclear@0 17
nuclear@0 18 enum AUDIO_PLAYMODE
nuclear@0 19 {
nuclear@0 20 AUDIO_PLAYMODE_ONCE,
nuclear@0 21 AUDIO_PLAYMODE_LOOP
nuclear@0 22 };
nuclear@0 23
nuclear@0 24 struct AudioStreamBuffer {
nuclear@0 25 char samples[AUDIO_BUFFER_BYTES];
nuclear@0 26
nuclear@0 27 int num_samples;
nuclear@0 28 int channels;
nuclear@0 29 int sample_rate;
nuclear@0 30 };
nuclear@0 31
nuclear@0 32 class AudioStream {
nuclear@0 33 private:
nuclear@0 34 pthread_t play_thread;
nuclear@0 35 pthread_mutex_t mutex;
nuclear@0 36
nuclear@0 37 float volume, pitch;
nuclear@0 38 bool done, loop;
nuclear@0 39 unsigned int poll_interval;
nuclear@0 40 unsigned int alsrc;
nuclear@0 41
nuclear@0 42 virtual bool more_samples(AudioStreamBuffer *buf) = 0;
nuclear@0 43
nuclear@0 44 public:
nuclear@0 45 void poll_loop();
nuclear@0 46
nuclear@0 47 AudioStream();
nuclear@0 48 virtual ~AudioStream();
nuclear@0 49
nuclear@0 50 virtual bool open(const char *fname);
nuclear@0 51 virtual void close();
nuclear@0 52
nuclear@0 53 virtual void set_volume(float vol);
nuclear@0 54 virtual float get_volume() const;
nuclear@0 55
nuclear@0 56 virtual void set_pitch(float p);
nuclear@0 57 virtual float get_pitch() const;
nuclear@0 58
nuclear@0 59 virtual void play(AUDIO_PLAYMODE mode);
nuclear@0 60 virtual void stop();
nuclear@0 61
nuclear@0 62 virtual void rewind() = 0;
nuclear@0 63 };
nuclear@0 64
nuclear@0 65 #endif // AUDIO_STREAM_H_