-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCNFA_sf.h
More file actions
3623 lines (2945 loc) · 113 KB
/
CNFA_sf.h
File metadata and controls
3623 lines (2945 loc) · 113 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//This file was automatically generated by Makefile at https://github.com/cnlohr/cnfa
//Generated from files git hash da3569ad3b7ce480747db039037d7495b87bc18a on Wed Dec 31 05:07:19 PM EST 2025 (This is not the git hash of this file)
//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
#if defined(WINDOWS) || defined(__WINDOWS__) || defined(_WINDOWS) \
|| defined(_WIN32) || defined(_WIN64) \
|| defined(WIN32) || defined(WIN64) \
|| defined(__WIN32__) || defined(__CYGWIN__) \
|| defined(__MINGW32__) || defined(__MINGW64__) \
|| defined(__TOS_WIN__)
#define CNFA_WINDOWS 1
#elif defined( ANDROID ) || defined( __android__ ) || defined(ANDROID)
#define CNFA_ANDROID 1
#elif defined(__NetBSD__) || defined(__NetBSD) || defined(__sun) || defined(sun)
#define CNFA_SUN 1
#elif defined(__linux) || defined(__linux__) || defined(linux) || defined(__LINUX__)
#define CNFA_LINUX 1
#define CNFA_PULSE 1
#endif
#if defined(PULSEAUDIO)
#define CNFA_PULSE 1
#endif
#ifdef __TINYC__
#ifndef TCC
#define TCC
#endif
#endif
#ifdef CNFA_IMPLEMENTATION
//Copyright <>< 2010-2020 Charles Lohr (And other authors as cited)
//CNFA is licensed under the MIT/x11, ColorChord or NewBSD Licenses. You choose.
#ifndef _CNFA_C
#define _CNFA_C
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#if defined(_MSC_VER)
#if CNFA_WINDOWS
#ifndef strdup
#define strdup _strdup
#endif
#endif
#endif
static CNFAInitFn * CNFADrivers[MAX_CNFA_DRIVERS];
static char * CNFADriverNames[MAX_CNFA_DRIVERS];
static int CNFADriverPriorities[MAX_CNFA_DRIVERS];
void RegCNFADriver( int priority, const char * name, CNFAInitFn * fn )
{
int j;
if( priority <= 0 )
{
return;
}
printf("[CNFA] Registering Driver: %s\n", name);
for( j = MAX_CNFA_DRIVERS-1; j >= 0; j-- )
{
//Cruise along, find location to insert
if( j > 0 && ( !CNFADrivers[j-1] || CNFADriverPriorities[j-1] < priority ) )
{
CNFADrivers[j] = CNFADrivers[j-1];
CNFADriverNames[j] = CNFADriverNames[j-1];
CNFADriverPriorities[j] = CNFADriverPriorities[j-1];
}
else
{
CNFADrivers[j] = fn;
CNFADriverNames[j] = strdup( name );
CNFADriverPriorities[j] = priority;
break;
}
}
}
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)
{
#if CNFA_ANDROID
//Android can't run static-time code.
void REGISTERAndroidCNFA();
REGISTERAndroidCNFA();
#endif
int i;
struct CNFADriver * ret = 0;
int minprio = 0;
CNFAInitFn * bestinit = 0;
if( driver_name == 0 || strlen( driver_name ) == 0 )
{
//Search for a driver.
for( i = 0; i < MAX_CNFA_DRIVERS; i++ )
{
if( CNFADrivers[i] == 0 )
{
break;
}
if( CNFADriverPriorities[i] > minprio )
{
minprio = CNFADriverPriorities[i];
bestinit = CNFADrivers[i];
}
}
if( bestinit )
{
ret = (struct CNFADriver *)bestinit( cb, your_name, reqSPSPlay, reqSPSRec, reqChannelsPlay, reqChannelsRec, sugBufferSize, outputSelect, inputSelect, opaque );
}
if( ret )
{
return ret;
}
}
else
{
for( i = 0; i < MAX_CNFA_DRIVERS; i++ )
{
if( CNFADrivers[i] == 0 )
{
break;
}
if( strcmp( CNFADriverNames[i], driver_name ) == 0 )
{
return (struct CNFADriver *)CNFADrivers[i]( cb, your_name, reqSPSPlay, reqSPSRec, reqChannelsPlay, reqChannelsRec, sugBufferSize, outputSelect, inputSelect, opaque );
}
}
}
printf( "CNFA Driver not found.\n" );
return 0;
}
int CNFAState( struct CNFADriver * cnfaobject )
{
if( cnfaobject )
{
return cnfaobject->StateFn( cnfaobject );
}
return -1;
}
void CNFAClose( struct CNFADriver * cnfaobject )
{
if( cnfaobject )
{
cnfaobject->CloseFn( cnfaobject );
}
}
#endif
//Copyright 2015-2020 <>< Charles Lohr under the ColorChord License.
#include "os_generic.h"
#include <stdlib.h>
struct CNFADriverNull
{
void (*CloseFn)( void * object );
int (*StateFn)( void * object );
CNFACBType callback;
short channelsPlay;
short channelsRec;
int spsPlay;
int spsRec;
void * opaque;
};
void CloseCNFANull( void * object )
{
free( object );
}
int CNFAStateNull( void * object )
{
return 0;
}
void * InitCNFANull( 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 CNFADriverNull * r = (struct CNFADriverNull *)malloc( sizeof( struct CNFADriverNull ) );
r->CloseFn = CloseCNFANull;
r->StateFn = CNFAStateNull;
r->callback = cb;
r->spsPlay = reqSPSPlay;
r->spsRec = reqSPSRec;
r->opaque = opaque;
r->channelsPlay = reqChannelsPlay;
r->channelsRec = reqChannelsRec;
return r;
}
REGISTER_CNFA( NullCNFA, 1, "NULL", InitCNFANull );
#if CNFA_WINDOWS
//Copyright 2015-2020 <>< Charles Lohr under the ColorChord License, MIT/x11 license or NewBSD Licenses.
#include <windows.h>
#include "os_generic.h"
#include <stdio.h>
#include <mmsystem.h>
#include <stdlib.h>
//Include -lwinmm, or, C:/windows/system32/winmm.dll
#if defined(_MSC_VER)
#if CNFA_WINDOWS
#ifndef strdup
#define strdup _strdup
#endif
#endif
#if defined(WIN32)
#pragma comment(lib,"winmm.lib")
#endif
#endif
#define BUFFS 3
struct CNFADriverWin
{
//Standard header - must remain.
void (*CloseFn)( void * object );
int (*StateFn)( void * object );
CNFACBType callback;
short channelsPlay;
short channelsRec;
int spsPlay;
int spsRec;
void * opaque;
char * sInputDev;
char * sOutputDev;
int buffer;
int isEnding;
int GOBUFFRec;
int GOBUFFPlay;
int recording;
int playing;
HWAVEIN hMyWaveIn;
HWAVEOUT hMyWaveOut;
WAVEHDR WavBuffIn[BUFFS];
WAVEHDR WavBuffOut[BUFFS];
};
static struct CNFADriverWin * w;
void CloseCNFAWin( void * v )
{
struct CNFADriverWin * r = (struct CNFADriverWin *)v;
int i;
if( r )
{
if( r->hMyWaveIn )
{
waveInStop(r->hMyWaveIn);
waveInReset(r->hMyWaveIn);
for ( i=0;i<BUFFS;i++)
{
waveInUnprepareHeader(r->hMyWaveIn,&(r->WavBuffIn[i]),sizeof(WAVEHDR));
free ((r->WavBuffIn[i]).lpData);
}
waveInClose(r->hMyWaveIn);
}
if( r->hMyWaveOut )
{
waveOutPause(r->hMyWaveOut);
waveOutReset(r->hMyWaveOut);
for ( i=0;i<BUFFS;i++)
{
waveInUnprepareHeader(r->hMyWaveIn,&(r->WavBuffOut[i]),sizeof(WAVEHDR));
free ((r->WavBuffOut[i]).lpData);
}
waveInClose(r->hMyWaveIn);
waveOutClose(r->hMyWaveOut);
}
free( r );
}
}
int CNFAStateWin( void * v )
{
struct CNFADriverWin * soundobject = (struct CNFADriverWin *)v;
return soundobject->recording | (soundobject->playing?2:0);
}
void CALLBACK HANDLEMIC(HWAVEIN hwi, UINT umsg, DWORD dwi, DWORD hdr, DWORD dwparm)
{
int ob;
unsigned int maxWave=0;
if (w->isEnding) return;
switch (umsg)
{
case MM_WIM_OPEN:
printf( "Mic Open.\n" );
w->recording = 1;
break;
case MM_WIM_DATA:
ob = (w->GOBUFFRec+(BUFFS))%BUFFS;
w->callback( (struct CNFADriver*)w, 0, (short*)(w->WavBuffIn[w->GOBUFFRec]).lpData, 0, w->buffer );
waveInAddBuffer(w->hMyWaveIn,&(w->WavBuffIn[w->GOBUFFRec]),sizeof(WAVEHDR));
w->GOBUFFRec = ( w->GOBUFFRec + 1 ) % BUFFS;
break;
}
}
void CALLBACK HANDLESINK(HWAVEIN hwi, UINT umsg, DWORD dwi, DWORD hdr, DWORD dwparm)
{
unsigned int maxWave=0;
if (w->isEnding) return;
switch (umsg)
{
case MM_WOM_OPEN:
printf( "Sink Open.\n" );
w->playing = 1;
break;
case MM_WOM_DONE:
w->callback( (struct CNFADriver*)w, (short*)(w->WavBuffOut[w->GOBUFFPlay]).lpData, 0, w->buffer, 0 );
waveOutWrite( w->hMyWaveOut, &(w->WavBuffOut[w->GOBUFFPlay]),sizeof(WAVEHDR) );
w->GOBUFFPlay = ( w->GOBUFFPlay + 1 ) % BUFFS;
break;
}
}
static struct CNFADriverWin * InitWinCNFA( struct CNFADriverWin * r )
{
int i;
WAVEFORMATEX wfmt;
long dwdeviceR, dwdeviceP;
memset( &wfmt, 0, sizeof(wfmt) );
printf ("WFMT Size (debugging temp for TCC): %zu\n", sizeof(wfmt) );
printf( "WFMT: %d %d %d\n", r->channelsRec, r->spsRec, r->spsRec * r->channelsRec );
w = r;
wfmt.wFormatTag = WAVE_FORMAT_PCM;
wfmt.nChannels = r->channelsRec;
wfmt.nAvgBytesPerSec = r->spsRec * r->channelsRec;
wfmt.nBlockAlign = r->channelsRec * 2;
wfmt.nSamplesPerSec = r->spsRec;
wfmt.wBitsPerSample = 16;
wfmt.cbSize = 0;
dwdeviceR = r->sInputDev?atoi(r->sInputDev):WAVE_MAPPER;
dwdeviceP = r->sOutputDev?atoi(r->sOutputDev):WAVE_MAPPER;
if( r->channelsRec )
{
int p;
printf( "In Wave Devs: %d; WAVE_MAPPER: %d; Selected Input: %ld\n", waveInGetNumDevs(), WAVE_MAPPER, dwdeviceR );
p = waveInOpen(&r->hMyWaveIn, dwdeviceR, &wfmt, (intptr_t)(&HANDLEMIC), 0, CALLBACK_FUNCTION);
if( p )
{
fprintf( stderr, "Error performing waveInOpen. Received code: %d\n", p );
}
printf( "waveInOpen: %d\n", p );
for ( i=0;i<BUFFS;i++)
{
memset( &(r->WavBuffIn[i]), 0, sizeof(r->WavBuffIn[i]) );
(r->WavBuffIn[i]).dwBufferLength = r->buffer*2*r->channelsRec;
(r->WavBuffIn[i]).dwLoops = 1;
(r->WavBuffIn[i]).lpData=(char*) malloc(r->buffer*r->channelsRec*2);
printf( "buffer gen size: %d: %p\n", r->buffer*r->channelsRec*2, (r->WavBuffIn[i]).lpData );
p = waveInPrepareHeader(r->hMyWaveIn,&(r->WavBuffIn[i]),sizeof(WAVEHDR));
printf( "WIPr: %d\n", p );
waveInAddBuffer(r->hMyWaveIn,&(r->WavBuffIn[i]),sizeof(WAVEHDR));
printf( "WIAr: %d\n", p );
}
p = waveInStart(r->hMyWaveIn);
if( p )
{
fprintf( stderr, "Error performing waveInStart. Received code %d\n", p );
}
}
wfmt.nChannels = r->channelsPlay;
wfmt.nAvgBytesPerSec = r->spsPlay * r->channelsPlay;
wfmt.nBlockAlign = r->channelsPlay * 2;
wfmt.nSamplesPerSec = r->spsPlay;
if( r->channelsPlay )
{
int p;
printf( "Out Wave Devs: %d; WAVE_MAPPER: %d; Selected Input: %ld\n", waveOutGetNumDevs(), WAVE_MAPPER, dwdeviceP );
p = waveOutOpen( &r->hMyWaveOut, dwdeviceP, &wfmt, (intptr_t)(void*)(&HANDLESINK), (intptr_t)r, CALLBACK_FUNCTION);
if( p )
{
fprintf( stderr, "Error performing waveOutOpen. Received code: %d\n", p );
}
printf( "waveOutOpen: %d\n", p );
for ( i=0;i<BUFFS;i++)
{
int size;
char * buf;
memset( &(r->WavBuffOut[i]), 0, sizeof(r->WavBuffOut[i]) );
(r->WavBuffOut[i]).dwBufferLength = r->buffer*2*r->channelsPlay;
(r->WavBuffOut[i]).dwLoops = 1;
size = r->buffer*r->channelsPlay*2;
buf = (r->WavBuffOut[i]).lpData=(char*) malloc(size);
memset( buf, 0, size );
p = waveOutPrepareHeader(r->hMyWaveOut,&(r->WavBuffOut[i]),sizeof(WAVEHDR));
waveOutWrite( r->hMyWaveOut, &(r->WavBuffOut[i]),sizeof(WAVEHDR));
}
}
return r;
}
void * InitCNFAWin( 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 CNFADriverWin * r = (struct CNFADriverWin *)malloc( sizeof( struct CNFADriverWin ) );
memset( r, 0, sizeof(*r) );
r->CloseFn = CloseCNFAWin;
r->StateFn = CNFAStateWin;
r->callback = cb;
r->opaque = opaque;
r->spsPlay = reqSPSPlay;
r->spsRec = reqSPSRec;
r->channelsPlay = reqChannelsPlay;
r->channelsRec = reqChannelsRec;
r->buffer = sugBufferSize;
r->sInputDev = inputSelect?strdup(inputSelect):0;
r->sOutputDev = outputSelect?strdup(outputSelect):0;
r->recording = 0;
r->playing = 0;
r->isEnding = 0;
r->GOBUFFPlay = 0;
r->GOBUFFRec = 0;
return InitWinCNFA(r);
}
REGISTER_CNFA( WinCNFA, 10, "WIN", InitCNFAWin );
#include <ntverp.h> // This probably won't work on pre-NT systems
#if VER_PRODUCTBUILD >= 7601
//Needed libraries: -lmmdevapi -lavrt -lole32
//Or DLLs: C:/windows/system32/avrt.dll C:/windows/system32/ole32.dll
#ifdef TCC
#define NO_WIN_HEADERS
#endif
#ifdef NO_WIN_HEADERS
#ifndef _CNFA_WASAPI_UTILS_H
#define _CNFA_WASAPI_UTILS_H
//#include "ole2.h"
#ifndef REFPROPERTYKEY
#define REFPROPERTYKEY const PROPERTYKEY * __MIDL_CONST
#endif //REFPROPERTYKEY
// Necessary definitions
#define _ANONYMOUS_STRUCT
#define BEGIN_INTERFACE
#define END_INTERFACE
#define DEVICE_STATE_ACTIVE 0x00000001
#define AUDCLNT_STREAMFLAGS_CROSSPROCESS 0x00010000
#define AUDCLNT_STREAMFLAGS_LOOPBACK 0x00020000
#define AUDCLNT_STREAMFLAGS_EVENTCALLBACK 0x00040000
#define AUDCLNT_STREAMFLAGS_NOPERSIST 0x00080000
#define AUDCLNT_STREAMFLAGS_RATEADJUST 0x00100000
#define AUDCLNT_STREAMFLAGS_PREVENT_LOOPBACK_CAPTURE 0x01000000
#define AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY 0x08000000
#define AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM 0x80000000
#define AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED 0x10000000
#define AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE 0x20000000
#define AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED 0x40000000
enum _AUDCLNT_BUFFERFLAGS
{
AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY = 0x1,
AUDCLNT_BUFFERFLAGS_SILENT = 0x2,
AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR = 0x4
} ;
#ifndef REFIID
#define REFIID const IID * __MIDL_CONST
#endif
#ifndef PropVariantInit
#define PropVariantInit(pvar) memset ( (pvar), 0, sizeof(PROPVARIANT) )
#endif
#if defined (__TINYC__)
#define _COM_Outptr_
#define _In_
#define _Out_
#define _Outptr_
#define _In_opt_
#define _Out_opt_
#define __RPC__in
#define __RPC__out
#define interface struct
#define CONST_VTBL
#define _Outptr_result_buffer_(X)
#define _Inexpressible_(X)
#define REFPROPVARIANT const PROPVARIANT * __MIDL_CONST
typedef struct tagPROPVARIANT PROPVARIANT;
typedef struct tWAVEFORMATEX WAVEFORMATEX;
typedef IID GUID;
typedef void* HANDLE;
#define CLSCTX_INPROC_SERVER 0x1
#define CLSCTX_INPROC_HANDLER 0x2
#define CLSCTX_LOCAL_SERVER 0x4
#define CLSCTX_REMOTE_SERVER 0x10
#define STGM_READ 0x00000000L
#define CLSCTX_ALL (CLSCTX_INPROC_SERVER| \
CLSCTX_INPROC_HANDLER| \
CLSCTX_LOCAL_SERVER| \
CLSCTX_REMOTE_SERVER)
typedef unsigned short VARTYPE;
typedef struct _tagpropertykey {
GUID fmtid;
DWORD pid;
} PROPERTYKEY;
#ifndef __wtypes_h__
typedef struct tagDEC {
USHORT wReserved;
BYTE scale;
BYTE sign;
ULONG Hi32;
ULONGLONG Lo64;
} DECIMAL;
// Property varient struct, used for getting the device name info
typedef BYTE PROPVAR_PAD1;
typedef BYTE PROPVAR_PAD2;
typedef ULONG PROPVAR_PAD3;
struct tagPROPVARIANT {
union {
struct tag_inner_PROPVARIANT
{
VARTYPE vt;
PROPVAR_PAD1 wReserved1;
PROPVAR_PAD2 wReserved2;
PROPVAR_PAD3 wReserved3;
union
{
double dblVal; // Filler for the largest object we need to store
LPWSTR pwszVal; // This is the only parameter we actually use
};
} ;
DECIMAL decVal;
};
};
#endif
#define _Inout_updates_(dwCount)
#define FAR
typedef interface IUnknown IUnknown;
typedef IUnknown *LPUNKNOWN;
#endif
#ifdef NO_WIN_HEADERS
#undef DEFINE_GUID
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID DECLSPEC_SELECTANY name \
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#undef DEFINE_PROPERTYKEY
#define DEFINE_PROPERTYKEY(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8,pid) \
EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY name \
= { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }, pid }
// stuff to be able to read device names
DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
#ifndef WINOLEAPI
#define WINOLEAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE
#define WINOLEAPI_(type) EXTERN_C DECLSPEC_IMPORT type STDAPICALLTYPE
#endif
// Define necessary functions
WINOLEAPI_(HANDLE)
AvSetMmThreadCharacteristicsW(LPCWSTR TaskName, LPDWORD TaskIndex);
WINOLEAPI_(BOOL)
AvRevertMmThreadCharacteristics(HANDLE AvrtHandle);
WINOLEAPI CoInitialize(LPVOID pvReserved);
WINOLEAPI_(void) CoUninitialize();
WINOLEAPI_(void) CoTaskMemFree(LPVOID pv);
WINOLEAPI CoCreateInstance(
REFCLSID rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
REFIID riid,
LPVOID FAR* ppv);
// WINOLEAPI CoCreateInstanceEx(
// REFCLSID Clsid,
// IUnknown *punkOuter,
// DWORD dwClsCtx,
// COSERVERINFO *pServerInfo,
// DWORD dwCount,
// MULTI_QI *pResults );
#endif //NO_WIN_HEADERS
// forward declarations
typedef struct IMMDevice IMMDevice;
typedef struct IMMDeviceCollection IMMDeviceCollection;
typedef struct IMMDeviceEnumerator IMMDeviceEnumerator;
typedef struct IMMNotificationClient IMMNotificationClient;
typedef struct IPropertyStore IPropertyStore;
typedef struct IAudioClient IAudioClient;
typedef struct IAudioCaptureClient IAudioCaptureClient;
// So the linker doesn't complain
extern const IID CLSID_MMDeviceEnumerator;
extern const IID IID_IMMDeviceEnumerator;
extern const IID IID_IAudioClient;
extern const IID CNFA_GUID;
extern const IID IID_IAudioCaptureClient;
typedef enum __MIDL___MIDL_itf_mmdeviceapi_0000_0000_0001
{
eRender = 0,
eCapture = ( eRender + 1 ) ,
eAll = ( eCapture + 1 ) ,
EDataFlow_enum_count = ( eAll + 1 )
} EDataFlow;
typedef enum __MIDL___MIDL_itf_mmdeviceapi_0000_0000_0002
{
eConsole = 0,
eMultimedia = ( eConsole + 1 ) ,
eCommunications = ( eMultimedia + 1 ) ,
ERole_enum_count = ( eCommunications + 1 )
} ERole;
typedef struct IMMDeviceEnumeratorVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IMMDeviceEnumerator * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IMMDeviceEnumerator * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IMMDeviceEnumerator * This);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *EnumAudioEndpoints )(
IMMDeviceEnumerator * This,
/* [annotation][in] */
_In_ EDataFlow dataFlow,
/* [annotation][in] */
_In_ DWORD dwStateMask,
/* [annotation][out] */
_Out_ IMMDeviceCollection **ppDevices);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *GetDefaultAudioEndpoint )(
IMMDeviceEnumerator * This,
/* [annotation][in] */
_In_ EDataFlow dataFlow,
/* [annotation][in] */
_In_ ERole role,
/* [annotation][out] */
_Out_ IMMDevice **ppEndpoint);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *GetDevice )(
IMMDeviceEnumerator * This,
/* [annotation][in] */
_In_ LPCWSTR pwstrId,
/* [annotation][out] */
_Out_ IMMDevice **ppDevice);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *RegisterEndpointNotificationCallback )(
IMMDeviceEnumerator * This,
/* [annotation][in] */
_In_ IMMNotificationClient *pClient);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *UnregisterEndpointNotificationCallback )(
IMMDeviceEnumerator * This,
/* [annotation][in] */
_In_ IMMNotificationClient *pClient);
END_INTERFACE
} IMMDeviceEnumeratorVtbl;
interface IMMDeviceEnumerator
{
CONST_VTBL struct IMMDeviceEnumeratorVtbl *lpVtbl;
};
typedef struct IMMDeviceCollectionVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IMMDeviceCollection * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IMMDeviceCollection * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IMMDeviceCollection * This);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *GetCount )(
IMMDeviceCollection * This,
/* [annotation][out] */
_Out_ UINT *pcDevices);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *Item )(
IMMDeviceCollection * This,
/* [annotation][in] */
_In_ UINT nDevice,
/* [annotation][out] */
_Out_ IMMDevice **ppDevice);
END_INTERFACE
} IMMDeviceCollectionVtbl;
interface IMMDeviceCollection
{
CONST_VTBL struct IMMDeviceCollectionVtbl *lpVtbl;
};
typedef struct IMMDeviceVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IMMDevice * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IMMDevice * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IMMDevice * This);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *Activate )(
IMMDevice * This,
/* [annotation][in] */
_In_ REFIID iid,
/* [annotation][in] */
_In_ DWORD dwClsCtx,
/* [annotation][unique][in] */
_In_opt_ PROPVARIANT *pActivationParams,
/* [annotation][iid_is][out] */
_Out_ void **ppInterface);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OpenPropertyStore )(
IMMDevice * This,
/* [annotation][in] */
_In_ DWORD stgmAccess,
/* [annotation][out] */
_Out_ IPropertyStore **ppProperties);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *GetId )(
IMMDevice * This,
/* [annotation][out] */
_Outptr_ LPWSTR *ppstrId);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *GetState )(
IMMDevice * This,
/* [annotation][out] */
_Out_ DWORD *pdwState);
END_INTERFACE
} IMMDeviceVtbl;
interface IMMDevice
{
CONST_VTBL struct IMMDeviceVtbl *lpVtbl;
};
typedef struct IMMNotificationClientVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IMMNotificationClient * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IMMNotificationClient * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IMMNotificationClient * This);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OnDeviceStateChanged )(
IMMNotificationClient * This,
/* [annotation][in] */
_In_ LPCWSTR pwstrDeviceId,
/* [annotation][in] */
_In_ DWORD dwNewState);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OnDeviceAdded )(
IMMNotificationClient * This,
/* [annotation][in] */
_In_ LPCWSTR pwstrDeviceId);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OnDeviceRemoved )(
IMMNotificationClient * This,
/* [annotation][in] */
_In_ LPCWSTR pwstrDeviceId);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OnDefaultDeviceChanged )(
IMMNotificationClient * This,
/* [annotation][in] */
_In_ EDataFlow flow,
/* [annotation][in] */
_In_ ERole role,
/* [annotation][in] */
_In_ LPCWSTR pwstrDefaultDeviceId);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *OnPropertyValueChanged )(
IMMNotificationClient * This,
/* [annotation][in] */
_In_ LPCWSTR pwstrDeviceId,
/* [annotation][in] */
_In_ const PROPERTYKEY key);
END_INTERFACE
} IMMNotificationClientVtbl;
interface IMMNotificationClient
{
CONST_VTBL struct IMMNotificationClientVtbl *lpVtbl;
};
typedef struct IPropertyStoreVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
__RPC__in IPropertyStore * This,
/* [in] */ __RPC__in REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
__RPC__in IPropertyStore * This);
ULONG ( STDMETHODCALLTYPE *Release )(
__RPC__in IPropertyStore * This);
HRESULT ( STDMETHODCALLTYPE *GetCount )(
__RPC__in IPropertyStore * This,
/* [out] */ __RPC__out DWORD *cProps);
HRESULT ( STDMETHODCALLTYPE *GetAt )(
__RPC__in IPropertyStore * This,
/* [in] */ DWORD iProp,
/* [out] */ __RPC__out PROPERTYKEY *pkey);
HRESULT ( STDMETHODCALLTYPE *GetValue )(
__RPC__in IPropertyStore * This,
/* [in] */ __RPC__in REFPROPERTYKEY key,
/* [out] */ __RPC__out PROPVARIANT *pv);
HRESULT ( STDMETHODCALLTYPE *SetValue )(
__RPC__in IPropertyStore * This,
/* [in] */ __RPC__in REFPROPERTYKEY key,
/* [in] */ __RPC__in REFPROPVARIANT propvar);
HRESULT ( STDMETHODCALLTYPE *Commit )(
__RPC__in IPropertyStore * This);