-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayer.h
52 lines (40 loc) · 1.21 KB
/
player.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
#ifndef PLAYER_H_
#define PLAYER_H_
#ifdef WIN32
#define __WINDOWS_DS__
#endif
#include <RtAudio.h>
#include <samplerate.h>
#define DEFAULT_SAMPLE_RATE 44100
#define DEFAULT_HW_SAMPLE_RATE 44100
#define BUFFER_SAMPLES 800 // in samples
#define BYTES_PER_SAMPLE (sizeof(short)*2) // stereo
class Player
{
public:
Player();
~Player();
bool Initialize(void (FillBuffers)(void*, int), void* param, int samplerate=DEFAULT_SAMPLE_RATE, int hw_samplerate=DEFAULT_HW_SAMPLE_RATE);
float* StereoBuffer() { return m_pStereoBuffer; }
int BufferSizeBytes() { return m_nBufferLengthBytes; }
int BufferSizeSamples() { return m_nBufferLengthBytes / BYTES_PER_SAMPLE; }
bool ReadyForData();
void Mix(float *outputBuffer, unsigned long framesPerBuffer, int outTimeSample=0);
void Play();
void Stop();
int GetPlayPositionSamples();
bool IsPlaying() { return m_bPlaying; }
static int m_nSampleRate;
protected:
RtAudio *m_pRtAudio;
int m_nBufferLengthBytes;
float *m_pStereoBuffer;
bool m_bPlaying;
int m_nSide; // side of buffer to write next (1 or 2)
int m_nHwSampleRate;
SRC_STATE* m_pSRC;
SRC_DATA m_SRC_data;
void (*m_pFillBuffers)(void* param, int outTimeSample);
void* m_Param;
};
#endif