forked from cntools/cnfa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNFA.h
125 lines (98 loc) · 3.92 KB
/
CNFA.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//Copyright <>< 2010-2020 Charles Lohr (And other authors as cited)
//CNFA is licensed under the MIT/x11, ColorChord or NewBSD Licenses. You choose.
//
// CN's Platform-agnostic, foundational sound driver subsystem.
// Easily output and input sound on a variety of platforms.
//
// Options:
// * #define CNFA_IMPLEMENTATION before this header and it will build all
// definitions in.
//
#ifndef _CNFA_H
#define _CNFA_H
//this #define is per-platform. For instance on Linux, you have ALSA, Pulse and null
#define MAX_CNFA_DRIVERS 4
struct CNFADriver;
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BUILD_DLL
#ifdef WINDOWS
#define DllExport __declspec( dllexport )
#else
#define DllExport extern
#endif
#else
#define DllExport
#endif
//NOTE: Some drivers have synchronous duplex mode, other drivers will use two different callbacks. If ether is unavailable, it will be NULL.
//I.e. if `out` is null, only use in to read. If in is null, only place samples in out.
typedef void(*CNFACBType)( struct CNFADriver * sd, short * out, short * in, int framesp, int framesr );
typedef void*(CNFAInitFn)( CNFACBType cb, const char * your_name, int reqSPSPlay, int reqSPSRec, int reqChannelsPlay, int reqChannelsRec, int sugBufferSize, const char * outputSelect, const char * inputSelect, void * opaque );
struct CNFADriver
{
void (*CloseFn)( void * object );
int (*StateFn)( void * object );
CNFACBType callback;
short channelsPlay;
short channelsRec;
int spsPlay;
int spsRec;
void * opaque;
//More fields may exist on a per-sound-driver basis
};
//Accepts:
//If DriverName = 0 or empty, will try to find best driver.
//
// our_source_name is an optional argument, but on some platforms controls the name of your endpoint.
// reqSPSPlay = 44100 is guaranteed on many platforms.
// reqSPSRec = 44100 is guaranteed on many platforms.
// NOTE: Some platforms do not allow SPS play and REC to deviate from each other.
// reqChannelsRec = 1 or 2 guaranteed on many platforms.
// reqChannelsPlay = 1 or 2 guaranteedon many platforms. NOTE: Some systems require ChannelsPlay == ChannelsRec!
// sugBufferSize = No promises.
// outputSelect = No standardization, NULL is OK for default.
// inputSelect = No standardization, NULL is OK for default.
DllExport struct CNFADriver * CNFAInit( const char * driver_name, const char * your_name, CNFACBType cb, int reqSPSPlay, int reqSPSRec, int reqChannelsPlay,
int reqChannelsRec, int sugBufferSize, const char * outputSelect, const char * inputSelect, void * opaque );
DllExport int CNFAState( struct CNFADriver * cnfaobject ); //returns bitmask. 1 if mic recording, 2 if play back running, 3 if both running.
DllExport void CNFAClose( struct CNFADriver * cnfaobject );
//Called by various sound drivers. Notice priority must be greater than 0. Priority of 0 or less will not register.
//This is an internal function. Applications shouldnot call it.
void RegCNFADriver( int priority, const char * name, CNFAInitFn * fn );
#if defined(_MSC_VER) && !defined(__clang__)
#define REGISTER_CNFA( cnfadriver, priority, name, function ) \
void REGISTER##cnfadriver() { RegCNFADriver( priority, name, function ); }
#else
#define REGISTER_CNFA( cnfadriver, priority, name, function ) \
void __attribute__((constructor)) REGISTER##cnfadriver() { RegCNFADriver( priority, name, function ); }
#endif
#ifdef __TINYC__
#ifndef TCC
#define TCC
#endif
#endif
#ifdef CNFA_IMPLEMENTATION
#include "CNFA.c"
#include "CNFA_null.c"
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64)
#include "CNFA_winmm.c"
#include <ntverp.h> // This probably won't work on pre-NT systems
#if VER_PRODUCTBUILD >= 7601
#include "CNFA_wasapi.c"
#endif
#elif defined( ANDROID ) || defined( __android__ )
#include "CNFA_android.c"
#elif defined(__NetBSD__) || defined(__sun)
#include "CNFA_sun.c"
#elif defined(__linux__)
#include "CNFA_alsa.c"
#if defined(PULSEAUDIO)
#include "CNFA_pulse.c"
#endif
#endif
#endif
#ifdef __cplusplus
};
#endif
#endif