Debian Codegraph @

src/Examples/McCurdy Collection/LiveSampling/DiskRecAndPlayback.csd

raw
1 ;Written by Iain McCurdy, 2008
2
3 ; Modified for QuteCsound by René, January 2011
4 ; Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
5
6 ;Notes on modifications from original csd:
7 ; Use wav header
8 ; Pause change to avoid high cpu load
9
10
11 ;my flags on Ubuntu: -dm0 -iadc -odac -+rtaudio=jack -b16 -B4096 --expression-opt -+rtmidi=null
12 <CsoundSynthesizer>
13 <CsOptions>
14
15 </CsOptions>
16 <CsInstruments>
17 sr = 44100 ;SAMPLE RATE
18 ksmps = 256 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
20
21
22 gkrecdur init 0
23 gkplaydur init 0
24
25 instr 1 ;GUI
26 gkPause invalue "Pause"
27 kPlay invalue "Play"
28 kPlayOn trigger kPlay, 0.5, 0
29 chnset kPlayOn, "PlayOn"
30 kInstr2 active 2
31 kInstr3 active 3
32
33 if kPlayOn = 1 && kInstr2 = 0 && kInstr3 = 0 then
34 event "i", 2, 0, 3600 ;start playback for one hour maximum
35 endif
36
37 outvalue "RecDur", gkrecdur
38 outvalue "PlayDur", gkplaydur
39 endin
40
41 instr 2 ;PLAYBACK
42 if gkPause = 1 then ;IF PAUSE BUTTON IS ACTIVATED...
43 kgoto END ;GOTO 'END' LABEL
44 endif ;END OF CONDITIONAL BRANCHING
45
46 asig diskin2 "32BitRecording.wav", 1
47 outs asig, asig ;SEND AUDIO TO OUTPUTS
48
49 kPlayOn chnget "PlayOn"
50 kPlay_Led invalue "Play_Led"
51
52 gkplaydur line 0,1,1
53
54
55 if (gkplaydur >= gkrecdur) || (kPlayOn == 1 && kPlay_Led == 1) then ;IF END OF RECORDING IS REACHED...
56 outvalue "Play_Led", 0 ;...DEACTIVATE PLAY BUTTON LED &
57 turnoff ;TURN OFF THIS INSTRUMENT IMMEDIATELY.
58 else
59 outvalue "Play_Led", 1 ;...ACTIVATE PLAY BUTTON LED &
60 endif ;END OF CONDITIONAL BRANCHING
61 END:
62 endin
63
64 instr 3 ;RECORD
65 if gkPause = 1 then ;IF PAUSE BUTTON IS ACTIVATED...
66 kgoto END ;GOTO 'END' LABEL
67 endif ;END OF CONDITIONAL BRANCHING
68
69 ain inch 1 ;READ AUDIO FROM LIVE INPUT CHANNEL 1
70 fout "32BitRecording.wav", 16, ain
71 gkrecdur line 0,1,1 ;record duration
72
73 END:
74 endin
75 </CsInstruments>
76 <CsScore>
77 i 1 0 3600
78 </CsScore>
79 </CsoundSynthesizer><bsbPanel>
80 <label>Widgets</label>
81 <objectName/>
82 <x>598</x>
83 <y>247</y>
84 <width>477</width>
85 <height>379</height>
86 <visible>true</visible>
87 <uuid/>
88 <bgcolor mode="nobackground">
89 <r>202</r>
90 <g>202</g>
91 <b>202</b>
92 </bgcolor>
93 <bsbObject version="2" type="BSBLabel">
94 <objectName/>
95 <x>2</x>
96 <y>2</y>
97 <width>475</width>
98 <height>370</height>
99 <uuid>{395a9956-93f5-441f-b0ef-3828f1b2da1c}</uuid>
100 <visible>true</visible>
101 <midichan>0</midichan>
102 <midicc>0</midicc>
103 <label>Record Audio to Disk With Playback (Once)</label>
104 <alignment>center</alignment>
105 <font>Liberation Sans</font>
106 <fontsize>18</fontsize>
107 <precision>3</precision>
108 <color>
109 <r>0</r>
110 <g>0</g>
111 <b>0</b>
112 </color>
113 <bgcolor mode="background">
114 <r>181</r>
115 <g>199</g>
116 <b>255</b>
117 </bgcolor>
118 <bordermode>border</bordermode>
119 <borderradius>5</borderradius>
120 <borderwidth>2</borderwidth>
121 </bsbObject>
122 <bsbObject version="2" type="BSBLabel">
123 <objectName/>
124 <x>4</x>
125 <y>140</y>
126 <width>471</width>
127 <height>239</height>
128 <uuid>{63943056-81b7-4daa-acef-5ee3932bad61}</uuid>
129 <visible>true</visible>
130 <midichan>0</midichan>
131 <midicc>0</midicc>
132 <label>-------------------------------------------------------------------------------------------------------------------
133 When it is required to record long sections of audio for playback or for storage for later retrieval, then recording to function tables will not be sufficient.
134 In this situation it is necessary to record audio to the computers hard disk (function table are merely stored temporarily in RAM).
135 In this example recording audio to disk is implemented using the fout opcode. Playback is implemented using the diskin2 opcode.
136 Playback will play the entire recording back once (unless playback is deactivated).
137 The recording will be stored as '32BitRecording.wav' in the default location for file output storage.
138 In this example file format is 32 bit floats at 44100. Care always needs to be taken that file storage format and playback format correspond.</label>
139 <alignment>left</alignment>
140 <font>Liberation Sans</font>
141 <fontsize>14</fontsize>
142 <precision>3</precision>
143 <color>
144 <r>0</r>
145 <g>0</g>
146 <b>0</b>
147 </color>
148 <bgcolor mode="nobackground">
149 <r>255</r>
150 <g>255</g>
151 <b>255</b>
152 </bgcolor>
153 <bordermode>noborder</bordermode>
154 <borderradius>1</borderradius>
155 <borderwidth>1</borderwidth>
156 </bsbObject>
157 <bsbObject version="2" type="BSBButton">
158 <objectName/>
159 <x>62</x>
160 <y>44</y>
161 <width>100</width>
162 <height>30</height>
163 <uuid>{0a44e1b8-fab4-40c8-8fa1-f1d1d743c45c}</uuid>
164 <visible>true</visible>
165 <midichan>0</midichan>
166 <midicc>0</midicc>
167 <type>event</type>
168 <pressedValue>1.00000000</pressedValue>
169 <stringvalue/>
170 <text> Record </text>
171 <image>/</image>
172 <eventLine>i 3 0 -1</eventLine>
173 <latch>true</latch>
174 <latched>false</latched>
175 </bsbObject>
176 <bsbObject version="2" type="BSBButton">
177 <objectName>Pause</objectName>
178 <x>182</x>
179 <y>44</y>
180 <width>100</width>
181 <height>30</height>
182 <uuid>{d25d9765-65f0-40fa-87b8-30ba88ad9bd2}</uuid>
183 <visible>true</visible>
184 <midichan>0</midichan>
185 <midicc>0</midicc>
186 <type>value</type>
187 <pressedValue>1.00000000</pressedValue>
188 <stringvalue/>
189 <text> Pause </text>
190 <image>/</image>
191 <eventLine/>
192 <latch>true</latch>
193 <latched>false</latched>
194 </bsbObject>
195 <bsbObject version="2" type="BSBButton">
196 <objectName>Play</objectName>
197 <x>302</x>
198 <y>44</y>
199 <width>100</width>
200 <height>30</height>
201 <uuid>{7924627d-9546-4acd-91a0-41c8282cf300}</uuid>
202 <visible>true</visible>
203 <midichan>0</midichan>
204 <midicc>0</midicc>
205 <type>value</type>
206 <pressedValue>1.00000000</pressedValue>
207 <stringvalue/>
208 <text> Play </text>
209 <image>/</image>
210 <eventLine/>
211 <latch>false</latch>
212 <latched>false</latched>
213 </bsbObject>
214 <bsbObject version="2" type="BSBController">
215 <objectName/>
216 <x>312</x>
217 <y>54</y>
218 <width>10</width>
219 <height>10</height>
220 <uuid>{2c1634b2-9b4f-4c8e-a392-f4bcdc4aa4eb}</uuid>
221 <visible>true</visible>
222 <midichan>0</midichan>
223 <midicc>0</midicc>
224 <objectName2>Play_Led</objectName2>
225 <xMin>0.00000000</xMin>
226 <xMax>1.00000000</xMax>
227 <yMin>0.00000000</yMin>
228 <yMax>1.00000000</yMax>
229 <xValue>0.00000000</xValue>
230 <yValue>0.00000000</yValue>
231 <type>fill</type>
232 <pointsize>1</pointsize>
233 <fadeSpeed>0.00000000</fadeSpeed>
234 <mouseControl act="press">jump</mouseControl>
235 <color>
236 <r>0</r>
237 <g>234</g>
238 <b>0</b>
239 </color>
240 <randomizable mode="both" group="0">false</randomizable>
241 <bgcolor>
242 <r>0</r>
243 <g>0</g>
244 <b>0</b>
245 </bgcolor>
246 </bsbObject>
247 <bsbObject version="2" type="BSBDisplay">
248 <objectName>RecDur</objectName>
249 <x>221</x>
250 <y>94</y>
251 <width>60</width>
252 <height>25</height>
253 <uuid>{f4a5dac8-b31b-4480-bd5c-73d3e5228c38}</uuid>
254 <visible>true</visible>
255 <midichan>0</midichan>
256 <midicc>0</midicc>
257 <label>8.516</label>
258 <alignment>left</alignment>
259 <font>Liberation Sans</font>
260 <fontsize>12</fontsize>
261 <precision>3</precision>
262 <color>
263 <r>0</r>
264 <g>0</g>
265 <b>0</b>
266 </color>
267 <bgcolor mode="background">
268 <r>255</r>
269 <g>255</g>
270 <b>255</b>
271 </bgcolor>
272 <bordermode>border</bordermode>
273 <borderradius>1</borderradius>
274 <borderwidth>1</borderwidth>
275 </bsbObject>
276 <bsbObject version="2" type="BSBLabel">
277 <objectName/>
278 <x>86</x>
279 <y>94</y>
280 <width>135</width>
281 <height>25</height>
282 <uuid>{c3e4f957-74ef-427b-8d53-37abaf75a236}</uuid>
283 <visible>true</visible>
284 <midichan>0</midichan>
285 <midicc>0</midicc>
286 <label>Record Duration (sec)</label>
287 <alignment>right</alignment>
288 <font>Liberation Sans</font>
289 <fontsize>10</fontsize>
290 <precision>3</precision>
291 <color>
292 <r>0</r>
293 <g>0</g>
294 <b>0</b>
295 </color>
296 <bgcolor mode="nobackground">
297 <r>255</r>
298 <g>255</g>
299 <b>255</b>
300 </bgcolor>
301 <bordermode>noborder</bordermode>
302 <borderradius>1</borderradius>
303 <borderwidth>1</borderwidth>
304 </bsbObject>
305 <bsbObject version="2" type="BSBDisplay">
306 <objectName>PlayDur</objectName>
307 <x>221</x>
308 <y>120</y>
309 <width>60</width>
310 <height>25</height>
311 <uuid>{4cf51312-2ac5-4893-8f13-48eb831ca14f}</uuid>
312 <visible>true</visible>
313 <midichan>0</midichan>
314 <midicc>0</midicc>
315 <label>8.516</label>
316 <alignment>left</alignment>
317 <font>Liberation Sans</font>
318 <fontsize>12</fontsize>
319 <precision>3</precision>
320 <color>
321 <r>0</r>
322 <g>0</g>
323 <b>0</b>
324 </color>
325 <bgcolor mode="background">
326 <r>255</r>
327 <g>255</g>
328 <b>255</b>
329 </bgcolor>
330 <bordermode>border</bordermode>
331 <borderradius>1</borderradius>
332 <borderwidth>1</borderwidth>
333 </bsbObject>
334 <bsbObject version="2" type="BSBLabel">
335 <objectName/>
336 <x>86</x>
337 <y>120</y>
338 <width>135</width>
339 <height>25</height>
340 <uuid>{99de1d28-1025-42ff-9d47-de31d15793ac}</uuid>
341 <visible>true</visible>
342 <midichan>0</midichan>
343 <midicc>0</midicc>
344 <label>Play Duration (sec)</label>
345 <alignment>right</alignment>
346 <font>Liberation Sans</font>
347 <fontsize>10</fontsize>
348 <precision>3</precision>
349 <color>
350 <r>0</r>
351 <g>0</g>
352 <b>0</b>
353 </color>
354 <bgcolor mode="nobackground">
355 <r>255</r>
356 <g>255</g>
357 <b>255</b>
358 </bgcolor>
359 <bordermode>noborder</bordermode>
360 <borderradius>1</borderradius>
361 <borderwidth>1</borderwidth>
362 </bsbObject>
363 </bsbPanel>
364 <bsbPresets>
365 </bsbPresets>