SponcAudio

Version 2 (Richy, 03/06/2014 19:58)

1 1 admin
{{>toc}}
2 1 admin
3 2 Richy
Sponc, a multi-touch aware GPL game which can be retrieved on libavg's git repository "mtc-sponc":https://github.com/libavg/mtc-sponc , can now handle audio.
4 1 admin
5 1 admin
Audio on Sponc relies on Supercollider 3 ( http://supercollider.sf.net ), using Pkaudio ( http://trac2.assembla.com/pkaudio ) as a convenient gateway interface.
6 1 admin
7 1 admin
h1. Installation
8 1 admin
9 1 admin
Installation is straightforward but is not like a "click&install package":
10 1 admin
11 1 admin
h2. pkaudio
12 1 admin
13 1 admin
Pkaudio is a bundle of interfaces that makes easy to get music-oriented environment working seamlessly. We are mainly interested in supercollider part.
14 1 admin
15 1 admin
*Brief todo:*
16 1 admin
17 1 admin
* Checkout the svn version of pkaudio
18 1 admin
* Install needed portions of the package 
19 1 admin
20 1 admin
h2. Checkout and install
21 1 admin
22 1 admin
<pre><code class="shell">
23 1 admin
 $ svn co http://svn2.assembla.com/svn/pkaudio
24 1 admin
 $ cd pkaudio
25 1 admin
 $ sudo python setup_scosc.py install
26 1 admin
</code></pre>
27 1 admin
28 1 admin
> (!) *Note:* (!) 
29 1 admin
> This guide has been tested against revision 3 of pkaudio
30 1 admin
31 1 admin
h2. Supercollider
32 1 admin
33 1 admin
[[SponcSupercollider|Supercollider]] is one of the most advanced rt and non-rt synthesis framework. It's divided into two parts:
34 1 admin
35 1 admin
* _sclang_ or the interpreter (a 'friendly' smalltalkish interface)
36 1 admin
* _scsynth_ or the audio worker (which speaks in OSC, Open Sound Control) 
37 1 admin
38 1 admin
Basically we need only the latter to be run (some glitches with linux due to sound library compatibility, very simple on OSX)
39 1 admin
40 1 admin
*Brief todo:*
41 1 admin
42 1 admin
* Download (and eventually install) Supercollider
43 1 admin
* Start the scsynth server by hand or prepare an automated script for that purpose 
44 1 admin
45 1 admin
h2. Download and install
46 1 admin
47 1 admin
The full procedure for linux setup can be found here: Supercollider_On_Linux, additional help can be found here this hint: http://swiki.hfbk-hamburg.de:8888/MusicTechnology/847
48 1 admin
49 1 admin
MacOSX package is ready after a simple extraction from the installation DMG, which can be retrieved here:  http://sourceforge.net/project/showfiles.php?group_id=54622&package_id=51508&release_id=577995
50 1 admin
51 1 admin
Sources can be retrieved here:  http://sourceforge.net/project/showfiles.php?group_id=54622&package_id=246937&release_id=577996
52 1 admin
53 1 admin
h2. Run scsynth
54 1 admin
55 1 admin
MacOSX: Just start supercollider.app and click on 'Boot' button on the 'localhost' server. If you want to to that by console, try this:
56 1 admin
57 1 admin
<pre><code class="shell">
58 1 admin
 $ cd /path/to/SC3
59 1 admin
 $ ./scsynth -u 57110 -b 1026
60 1 admin
</code></pre>
61 1 admin
62 1 admin
Linux: a good intro can be found here http://wiki.eeeuser.com/howto:installingsupercollider
63 1 admin
64 1 admin
If you experience problems with Jackd on Ubuntu, try to use portaudio (compiling sc from source)
65 1 admin
66 1 admin
h1. Running
67 1 admin
68 1 admin
Whenever you have completed those tasks, you can simply fire up the application: it will catch the availability of the framework and use it.
69 1 admin
70 1 admin
h2. Troubleshooting
71 1 admin
72 1 admin
<pre>
73 1 admin
AUDIO: Audio subsystem not available
74 1 admin
</pre>
75 1 admin
76 1 admin
This means that something is wrong with pkaudio, check if the installer placed scosc and scsynth on a PYTHON_PATH directory
77 1 admin
78 1 admin
<pre>
79 1 admin
AUDIO: Audio subsystem available but server is not responding. Disabling audio
80 1 admin
</pre>
81 1 admin
82 1 admin
This time the audio subsystem cannot send commands to Supercollider which is expected to be found on localhost at port 57110/UDP. Double check if scsynth is running.
83 1 admin
84 1 admin
h1. SC SynthDefs
85 1 admin
86 1 admin
Whoever would take care of getting SynthDefs? running by hand or tweak them, here come the sources:
87 1 admin
88 1 admin
<pre><code class="python">
89 1 admin
 (
90 1 admin
 SynthDef("simpleAnalog", {
91 1 admin
 	arg gate = 0, lfoFreq = 2, lfoAmt = 0, baseFreq = 139, osc2Shift = 1, aAttack = 0.001, aDecay = 0.5, aSustain = 0.1, aRelease = 2, fAttack = 0.001, fDecay = 0.5, fSustain = 0.1, fRelease = 0.1, fEnvAmt = 0, fCutoff = 300, fReso = 0.1, fKTrack = 1, xpos = 0, ypos = 0;
92 1 admin
 	var oscFreqAdd, vco1, vco2, aEnv, aAmp, oscStage, filterStage, ampStage, outStage, fEnv, fFreqEnv;
93 1 admin
94 1 admin
95 1 admin
 	// LFO/FM
96 1 admin
 	oscFreqAdd = LFTri.kr(lfoFreq, 0, lfoAmt);
97 1 admin
 	
98 1 admin
 	// OSC STAGE
99 1 admin
 	vco1 = Pulse.ar(baseFreq + oscFreqAdd, 0.3);
100 1 admin
 	vco2 = Pulse.ar(baseFreq + osc2Shift + oscFreqAdd, 0.3, 0.8);
101 1 admin
 	oscStage = vco1+vco2;
102 1 admin
 	
103 1 admin
 	// FILTER STAGE
104 1 admin
 	//fCutoff = MouseX.kr(0,1000);
105 1 admin
 	//fReso = MouseY.kr(0.01, 1);
106 1 admin
 	fEnv = Env.adsr(fAttack, fDecay, fSustain, fRelease);
107 1 admin
 	fFreqEnv = EnvGen.kr(fEnv, gate, fEnvAmt);
108 1 admin
 	filterStage = Resonz.ar(oscStage, baseFreq + fCutoff, fReso);
109 1 admin
 	
110 1 admin
 	// AMPLITUDE ENVELOPE
111 1 admin
 	aEnv = Env.adsr(aAttack, aDecay, aSustain, aRelease);
112 1 admin
 	aAmp = EnvGen.kr(aEnv, gate);
113 1 admin
 	ampStage = aAmp * filterStage;
114 1 admin
 	
115 1 admin
 	// OUTPUT
116 1 admin
 	Out.ar(0, Pan4.ar(ampStage, xpos, ypos, 1 ));
117 1 admin
  }).writeDefFile;
118 1 admin
119 1 admin
120 1 admin
 s.sendSynthDef("simpleAnalog");
121 1 admin
122 1 admin
123 1 admin
 (
124 1 admin
 SynthDef("QuadraPlayer",{
125 1 admin
 	arg xpos=0,ypos=0, bufnum=0, loop=0;
126 1 admin
 	var playbuf;
127 1 admin
 	playbuf = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), 0, 0, loop);
128 1 admin
 	FreeSelfWhenDone.kr(playbuf);
129 1 admin
     Out.ar(0,
130 1 admin
                 Pan4.ar(playbuf, xpos, ypos, 0.45 )
131 1 admin
        )
132 1 admin
 }).writeDefFile;
133 1 admin
134 1 admin
135 1 admin
 s.sendSynthDef("QuadraPlayer");
136 1 admin
 )
137 1 admin
138 1 admin
139 1 admin
 (
140 1 admin
 SynthDef("StereoPlayer",{
141 1 admin
 	arg xpos=0, bufnum=0;
142 1 admin
 	var playbuf;
143 1 admin
 	playbuf = PlayBuf.ar(1,bufnum, BufRateScale.kr(bufnum));
144 1 admin
 	FreeSelfWhenDone.kr(playbuf);
145 1 admin
 	
146 1 admin
 	Out.ar(0,
147 1 admin
 		Pan2.ar(playbuf, xpos, 0.9 )
148 1 admin
 	)
149 1 admin
 }).writeDefFile;
150 1 admin
  
151 1 admin
 s.sendSynthDef("StereoPlayer");
152 1 admin
 )
153 1 admin
</code></pre>