forked from csound/csoundAPI_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetSpoutExample.cpp
More file actions
72 lines (56 loc) · 1.8 KB
/
GetSpoutExample.cpp
File metadata and controls
72 lines (56 loc) · 1.8 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
/* Example 7
This example attempts to show how one might embed Csound into an application that has its own
audio IO interface. Csound's GetSpout() and GetSpin() method let us tap directly into Csound's
IO buffers. Note this example still uses Csound to output audio, but in most cases you should run
Csound with '-n' set in the CsOptions. THis will prevent Csound from trying to open any audio IO
devices.
Typical command line to build this:
g++ example8.cpp -o test -I ../../csound/include/ -lcsound64 -lsndfile
RoryWalsh 2016
*/
#include <stdio.h>
#include "csound.hpp"
#include <iostream>
using namespace std;
#ifdef __GNUC__
#define NOT_USED(var) var __attribute__((unused))
#endif
int main()
{
MYFLT *spin, NOT_USED(*spout);
int sampleCount=0;
//For sake of simplicity we are generating a simple waveform.
//In most cases a signal will be taken directly from your sound
//card using an audio library.
MYFLT simpleRamp[44100];
for(int i=0;i<44100;i++)
{
simpleRamp[i] = (float)i/44100.f;
}
//Create an instance of Csound
Csound* csound = new Csound();
//compile instance of csound.
csound->Compile("test8.csd");
//access Csound's input/output buffer
spout = csound->GetSpout();
spin = csound->GetSpin();
//start Csound performance
csound->Start();
while(csound->PerformKsmps()==0)
{
//this is our main processing loop. External audio can be sent
//to Csound in this loop by writing directly to the spin
//buffers. Csound picks up the input signal using its audio input opcodes.
//see test8.csd.
for(int i=0;i<csound->GetKsmps();i++)
{
spin[i] = simpleRamp[sampleCount];
sampleCount=sampleCount==44100 ? 0 : sampleCount+1;
//Csound's output signal can also be accessed through spout and output to
//a soundcard using an audio library.
}
}
//free Csound object
delete csound;
return 0;
}