-
Notifications
You must be signed in to change notification settings - Fork 16
/
example.c
70 lines (55 loc) · 1.64 KB
/
example.c
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
#include <stdio.h>
#include <math.h>
#ifdef CNFA_WINDOWS
#include <windows.h>
#define sleep(time_s) Sleep((time_s) * 1000)
#else
#include <unistd.h>
#endif
// If using the shared library, don't define CNFA_IMPLEMENTATION
// (it's already in the library).
#ifndef USE_SHARED
#define CNFA_IMPLEMENTATION
#endif
#include "CNFA.h"
#define RUNTIME 5
double omega = 0;
int totalframesr = 0;
int totalframesp = 0;
void Callback( struct CNFADriver * sd, short * out, short * in, int framesp, int framesr )
{
int i;
totalframesr += framesr;
totalframesp += framesp;
int channels = sd->channelsPlay;
for( i = 0; i < framesp; i++ )
{
// Shift phase, so we run at 440 Hz (A4)
omega += ( 3.14159 * 2 * 440. ) / sd->spsPlay;
// Make the 440 Hz tone at 10% volume and convert to short.
short value = sin( omega ) * 0.1 * 32767;
int c;
for( c = 0; c < channels; c++ )
{
*(out++) = value;
}
}
}
struct CNFADriver * cnfa;
int main( int argc, char ** argv )
{
cnfa = CNFAInit(
NULL, //You can select a plaback driver, or use NULL for default.
"cnfa_example", Callback,
48000, //Requested samplerate for playback
48000, //Requested samplerate for recording
2, //Number of playback channels.
2, //Number of record channels.
1024, //Buffer size in frames.
0, //Could be a string, for the selected input device - but 0 means default.
0, //Could be a string, for the selected output device - but 0 means default.
0 // 'opaque' value if the driver wanted it.
);
sleep( RUNTIME );
printf( "Received %d (%d per sec) frames\nSent %d (%d per sec) frames\n", totalframesr, totalframesr/RUNTIME, totalframesp, totalframesp/RUNTIME );
}