-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpa.h
102 lines (82 loc) · 2.94 KB
/
pa.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef PA_H
#define PA_H
#if __cplusplus > 199711L
#define CPP11
#endif
#include <stdio.h>
#include "portaudio.h"
#ifdef CPP11
#include <memory>
#endif
class Pa{
public:
enum RunMode {dontTerminate, wait, sleep, waitForKey};
private:
RunMode mode = RunMode::dontTerminate;
typedef int(*mainCallBack)(const void*, void*, unsigned long, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void*);
mainCallBack PaCallBack = nullptr;
typedef void (*miniCallBack)(const float*, float*, long, void*);
static miniCallBack miniCb;
void (*streamFinished)(void*) = nullptr;
void* userDataType = NULL;
PaStream *stream;
PaSampleFormat sampleFormat = paFloat32;
unsigned long sleepTime = 10000;
unsigned int inchannels = 0;
unsigned int outchannels = 1;
unsigned int framesperbuffer = 0;
unsigned int samplerate = 44100;
int inputdevice = -1;
int outputdevice = -1;
bool runloop = false;
bool init = false;
#ifdef CPP11
std::shared_ptr<void> s_ptr;
#endif
// private functions:
void startStream(Pa::RunMode mode);
void restart(Pa::RunMode mode);
void intialize();
const char* apiName(unsigned int index);
static PaError paCb(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void* udata);
public:
// constructors:
// full callback, void* data
Pa(mainCallBack func, void* data);
// full callback, inchannels, outchannels, sampling rate, frames per buffer, void* data
Pa(mainCallBack func, unsigned int inch, unsigned int outch, unsigned int samp, unsigned int frames, void *data);
// mini callback, void* data
Pa(miniCallBack func, void* data);
// mini callback, inchannels, outchannels, sampling rate, frames per buffer, void* data
Pa(miniCallBack func, unsigned int inch, unsigned int outch, unsigned int samp, unsigned int frames, void *data);
#ifdef CPP11
// full callback, shared_ptr data
Pa(mainCallBack func, std::shared_ptr<void> data);
// full callback, params, shared_ptr data
Pa(mainCallBack func, unsigned int inch, unsigned int outch, unsigned int samp, unsigned int frames, std::shared_ptr<void> data);
// mini callback, shared_ptr data
Pa(miniCallBack func, std::shared_ptr<void> data);
// mini callback, params, shared_ptr data
Pa(miniCallBack func, unsigned int inch, unsigned int outch, unsigned int samp, unsigned int frames, std::shared_ptr<void> data);
#endif
~Pa();
// public functions:
void start();
void start(RunMode mode);
void start(unsigned long sleeptime);
void stop();
void stop(bool close);
void terminate();
void setSleepTime(unsigned long time);
void setSampleFormat(PaSampleFormat format);
void setFinishedCallBack(void(*func)(void* data));
void listDevices();
void getDeviceInfo(unsigned int index);
void setInputDevice(unsigned int index);
void setOutputDevice(unsigned int index);
};
#endif /* PA_H */