-
Notifications
You must be signed in to change notification settings - Fork 5
/
MoyaiALSound.h
67 lines (60 loc) · 1.58 KB
/
MoyaiALSound.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _ALSOUND_H_
#define _ALSOUND_H_
#ifdef WIN32
#include "al.h"
#include "alc.h"
#else
#include "OpenAL/al.h"
#include "OpenAL/alc.h"
#endif
#include "AL/alut.h"
class MoyaiALSound {
public:
typedef enum {
STOPPED=0,
PLAYING=1,
} STATE;
float *samples;
int posFrame; // 1 for samples[2] when numchannel==2
int numFrames; // total frame num
int numChannels;
int sampleRate;
float volume;
STATE state;
bool loop;
MoyaiALSound() : samples(nullptr), posFrame(0), numFrames(0), numChannels(0), sampleRate(0), volume(1), state(STOPPED), loop(false) {}
bool isPlaying() {
return state == PLAYING;
}
float getVolume() {
return volume;
}
void play() {
posFrame=0;
state=PLAYING;
}
void stop() {
state=STOPPED;
}
void setVolume( float v) {
volume = v;
}
void setPosition(float sec) {
posFrame = (sec * sampleRate);
}
float getPosition() {
float sec = (float)(posFrame) / (float)sampleRate;
return sec;
}
void setLooping(bool flag) {
loop=flag;
}
void resample();
void normalize();
static MoyaiALSound *create( const char *cpath ) ;
static MoyaiALSound *create( int sampleRate, int numChannels, int numFrames, bool loop, float *samples );
};
void startMoyaiAL();
void setMoyaiALOnMixDone( void (*cb)( int16_t *samples, int numFrames, int numChannels, int freq ) ) ;
void setMoyaiALOnBeforeMix( void (*cb)( int16_t *samples, int numFrames, int numChannels, int freq ) ) ;
#endif