Debian Codegraph @

src/Examples/CsoundQt/Useful/File_to_Text.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 -n -m0 ; Don't write audio file to disk and don't write messages
4 </CsOptions>
5 <CsInstruments>
6
7 sr = 44100
8 ksmps = 1
9 nchnls = 1
10 0dbfs = 1
11
12 gihandle init 0
13
14 ; By Andres Cabrera 2009
15
16 instr 1
17 ; Receive the name from the text boxes
18 Sfilename invalue "_Browse1"
19 Sfilename2 invalue "_Browse2"
20 ; Check duration and sample rate
21 ilen filelen Sfilename
22
23 ; Load the audio file to f-table 50
24 ftfree 50, 0
25 Sline sprintf {{f 50 0 0 1 "%s" 0 0 1}}, Sfilename
26 scoreline_i Sline
27 ;outvalue "fb", "Loading file..."
28
29 ;receive decimation value
30 kdec invalue "decimation"
31 ; Turn on instrument that clears progress bar
32 event_i "i", 97, 0, 1
33 ; Turn on processing instrument for approprate time
34 event_i "i", 98, 5, ilen / i(kdec)
35 prints Sfilename2
36 gihandle fiopen Sfilename2, 0 ; open text file for writing
37 ; When finished, quit
38 event_i "i", 100, (ilen/ i(kdec)) + 6, 1
39 endin
40
41 instr 97 ;clear progress bar
42 outvalue "fb", 0
43 endin
44
45 instr 98 ;traverse the file
46 kdec invalue "decimation"
47 kstart invalue "start"
48 kend invalue "end"
49 ktype invalue "type"
50 kindex init 0
51 kaccum init 0
52 ilen = nsamp(50)
53
54 ; Convert time in ms to number of audio samples
55 kstart = kstart * sr /1000
56 kend = kend * sr /1000
57
58 loopstart:
59 kindex = kindex + 1
60 if ((kindex + kstart >= ilen) || (kindex + kstart > kend)) then
61 turnoff
62 endif
63 kvalue tab kindex + kstart, 50
64 if (ktype == 0) then ; if peak
65 if (kaccum < abs(kvalue)) then
66 kaccum = abs(kvalue)
67 endif
68 elseif (ktype == 1) then ; if average
69 kaccum = kaccum + kvalue
70 endif
71
72 ; Check if kindex is a multiple of kdec
73 krem = kindex%kdec
74 if krem != 0 kgoto loopstart ; do loop
75
76 if (ktype == 1) then ; if average divide by number of elements
77 kaccum = kaccum / kdec
78 endif
79
80 event "i", 99, 0, 1, kaccum
81 kaccum = 0
82
83 outvalue "fb", kindex/(kend-kstart)
84 endin
85
86 instr 99 ;write one value
87 fouti gihandle, 0, 0, p4
88 turnoff
89 endin
90
91 instr 100 ;print end message
92 ficlose gihandle
93 exitnow
94 endin
95
96
97 </CsInstruments>
98 <CsScore>
99 f 50 0 2 2 0
100 i 1 0 6
101
102 </CsScore>
103 </CsoundSynthesizer>
104 <bsbPanel>
105 <label>Widgets</label>
106 <objectName/>
107 <x>577</x>
108 <y>195</y>
109 <width>585</width>
110 <height>492</height>
111 <visible>true</visible>
112 <uuid/>
113 <bgcolor mode="background" >
114 <r>138</r>
115 <g>157</g>
116 <b>162</b>
117 </bgcolor>
118 <bsbObject version="2" type="BSBSpinBox" >
119 <objectName>decimation</objectName>
120 <x>95</x>
121 <y>316</y>
122 <width>80</width>
123 <height>25</height>
124 <uuid>{5985ba7b-3a4f-42f8-b0bd-1396aeef44ef}</uuid>
125 <visible>true</visible>
126 <midichan>0</midichan>
127 <midicc>-3</midicc>
128 <alignment>left</alignment>
129 <font>Lucida Grande</font>
130 <fontsize>10</fontsize>
131 <color>
132 <r>0</r>
133 <g>0</g>
134 <b>0</b>
135 </color>
136 <bgcolor mode="nobackground" >
137 <r>255</r>
138 <g>255</g>
139 <b>255</b>
140 </bgcolor>
141 <resolution>1.00000000</resolution>
142 <minimum>-1e+12</minimum>
143 <maximum>1e+12</maximum>
144 <randomizable group="0" >false</randomizable>
145 <value>1000</value>
146 </bsbObject>
147 <bsbObject version="2" type="BSBLineEdit" >
148 <objectName>_Browse1</objectName>
149 <x>11</x>
150 <y>227</y>
151 <width>445</width>
152 <height>26</height>
153 <uuid>{8ccac1d4-3d0f-4b78-ac22-54a0e0737f9e}</uuid>
154 <visible>true</visible>
155 <midichan>0</midichan>
156 <midicc>-3</midicc>
157 <label>/home/andres/Downloads/ahh.wav</label>
158 <alignment>left</alignment>
159 <font>Lucida Grande</font>
160 <fontsize>10</fontsize>
161 <precision>3</precision>
162 <color>
163 <r>0</r>
164 <g>0</g>
165 <b>0</b>
166 </color>
167 <bgcolor mode="nobackground" >
168 <r>230</r>
169 <g>221</g>
170 <b>213</b>
171 </bgcolor>
172 <background>nobackground</background>
173 </bsbObject>
174 <bsbObject version="2" type="BSBButton" >
175 <objectName>_Browse1</objectName>
176 <x>458</x>
177 <y>225</y>
178 <width>100</width>
179 <height>30</height>
180 <uuid>{d2185fce-b4fa-4050-ab3f-423836a05f50}</uuid>
181 <visible>true</visible>
182 <midichan>0</midichan>
183 <midicc>-3</midicc>
184 <type>value</type>
185 <pressedValue>1.00000000</pressedValue>
186 <stringvalue>/home/andres/Downloads/ahh.wav</stringvalue>
187 <text>Browse</text>
188 <image>/</image>
189 <eventLine/>
190 <latch>false</latch>
191 <latched>false</latched>
192 </bsbObject>
193 <bsbObject version="2" type="BSBButton" >
194 <objectName>_Play</objectName>
195 <x>188</x>
196 <y>354</y>
197 <width>375</width>
198 <height>61</height>
199 <uuid>{a1dc4742-c982-44ec-835e-f768af82eaf7}</uuid>
200 <visible>true</visible>
201 <midichan>0</midichan>
202 <midicc>-3</midicc>
203 <type>value</type>
204 <pressedValue>1.00000000</pressedValue>
205 <stringvalue/>
206 <text>Run</text>
207 <image>/</image>
208 <eventLine/>
209 <latch>false</latch>
210 <latched>false</latched>
211 </bsbObject>
212 <bsbObject version="2" type="BSBLabel" >
213 <objectName/>
214 <x>10</x>
215 <y>198</y>
216 <width>80</width>
217 <height>25</height>
218 <uuid>{3528a3f8-9966-435b-b433-fc9954eeebfa}</uuid>
219 <visible>true</visible>
220 <midichan>0</midichan>
221 <midicc>-3</midicc>
222 <label>File to load</label>
223 <alignment>left</alignment>
224 <font>DejaVu Sans</font>
225 <fontsize>12</fontsize>
226 <precision>3</precision>
227 <color>
228 <r>0</r>
229 <g>0</g>
230 <b>0</b>
231 </color>
232 <bgcolor mode="nobackground" >
233 <r>255</r>
234 <g>255</g>
235 <b>255</b>
236 </bgcolor>
237 <bordermode>noborder</bordermode>
238 <borderradius>1</borderradius>
239 <borderwidth>1</borderwidth>
240 </bsbObject>
241 <bsbObject version="2" type="BSBLabel" >
242 <objectName/>
243 <x>12</x>
244 <y>316</y>
245 <width>80</width>
246 <height>25</height>
247 <uuid>{8dce1321-3b31-448a-a9d7-d297b8bfd079}</uuid>
248 <visible>true</visible>
249 <midichan>0</midichan>
250 <midicc>-3</midicc>
251 <label>Decimation</label>
252 <alignment>left</alignment>
253 <font>DejaVu Sans</font>
254 <fontsize>10</fontsize>
255 <precision>3</precision>
256 <color>
257 <r>0</r>
258 <g>0</g>
259 <b>0</b>
260 </color>
261 <bgcolor mode="nobackground" >
262 <r>255</r>
263 <g>255</g>
264 <b>255</b>
265 </bgcolor>
266 <bordermode>noborder</bordermode>
267 <borderradius>1</borderradius>
268 <borderwidth>1</borderwidth>
269 </bsbObject>
270 <bsbObject version="2" type="BSBSpinBox" >
271 <objectName>start</objectName>
272 <x>95</x>
273 <y>350</y>
274 <width>80</width>
275 <height>25</height>
276 <uuid>{7e459bdb-9dbc-480d-bbe5-b01b7fbd0098}</uuid>
277 <visible>true</visible>
278 <midichan>0</midichan>
279 <midicc>-3</midicc>
280 <alignment>left</alignment>
281 <font>Lucida Grande</font>
282 <fontsize>10</fontsize>
283 <color>
284 <r>0</r>
285 <g>0</g>
286 <b>0</b>
287 </color>
288 <bgcolor mode="nobackground" >
289 <r>255</r>
290 <g>255</g>
291 <b>255</b>
292 </bgcolor>
293 <resolution>1.00000000</resolution>
294 <minimum>-1e+12</minimum>
295 <maximum>1e+12</maximum>
296 <randomizable group="0" >false</randomizable>
297 <value>0</value>
298 </bsbObject>
299 <bsbObject version="2" type="BSBLabel" >
300 <objectName/>
301 <x>12</x>
302 <y>350</y>
303 <width>86</width>
304 <height>27</height>
305 <uuid>{31fab7b1-bca8-4c5c-ae61-99d3d49c68c3}</uuid>
306 <visible>true</visible>
307 <midichan>0</midichan>
308 <midicc>-3</midicc>
309 <label>Start time (ms)</label>
310 <alignment>left</alignment>
311 <font>DejaVu Sans</font>
312 <fontsize>10</fontsize>
313 <precision>3</precision>
314 <color>
315 <r>0</r>
316 <g>0</g>
317 <b>0</b>
318 </color>
319 <bgcolor mode="nobackground" >
320 <r>255</r>
321 <g>255</g>
322 <b>255</b>
323 </bgcolor>
324 <bordermode>noborder</bordermode>
325 <borderradius>1</borderradius>
326 <borderwidth>1</borderwidth>
327 </bsbObject>
328 <bsbObject version="2" type="BSBSpinBox" >
329 <objectName>end</objectName>
330 <x>95</x>
331 <y>387</y>
332 <width>80</width>
333 <height>25</height>
334 <uuid>{34f55718-74e5-468a-b2b4-166af109c4fc}</uuid>
335 <visible>true</visible>
336 <midichan>0</midichan>
337 <midicc>-3</midicc>
338 <alignment>left</alignment>
339 <font>Lucida Grande</font>
340 <fontsize>10</fontsize>
341 <color>
342 <r>0</r>
343 <g>0</g>
344 <b>0</b>
345 </color>
346 <bgcolor mode="nobackground" >
347 <r>255</r>
348 <g>255</g>
349 <b>255</b>
350 </bgcolor>
351 <resolution>1.00000000</resolution>
352 <minimum>-1e+12</minimum>
353 <maximum>1e+12</maximum>
354 <randomizable group="0" >false</randomizable>
355 <value>1000</value>
356 </bsbObject>
357 <bsbObject version="2" type="BSBLabel" >
358 <objectName/>
359 <x>12</x>
360 <y>387</y>
361 <width>86</width>
362 <height>25</height>
363 <uuid>{7c13cdf3-8d2e-4a7f-a3ca-a40e9b94a71f}</uuid>
364 <visible>true</visible>
365 <midichan>0</midichan>
366 <midicc>-3</midicc>
367 <label>End time (ms)</label>
368 <alignment>left</alignment>
369 <font>DejaVu Sans</font>
370 <fontsize>10</fontsize>
371 <precision>3</precision>
372 <color>
373 <r>0</r>
374 <g>0</g>
375 <b>0</b>
376 </color>
377 <bgcolor mode="nobackground" >
378 <r>255</r>
379 <g>255</g>
380 <b>255</b>
381 </bgcolor>
382 <bordermode>noborder</bordermode>
383 <borderradius>1</borderradius>
384 <borderwidth>1</borderwidth>
385 </bsbObject>
386 <bsbObject version="2" type="BSBDropdown" >
387 <objectName>type</objectName>
388 <x>186</x>
389 <y>318</y>
390 <width>122</width>
391 <height>30</height>
392 <uuid>{6ce4ec10-ce8a-42d4-8af3-9afda3c83a2a}</uuid>
393 <visible>true</visible>
394 <midichan>0</midichan>
395 <midicc>-3</midicc>
396 <bsbDropdownItemList>
397 <bsbDropdownItem>
398 <name>peak</name>
399 <value>0</value>
400 <stringvalue/>
401 </bsbDropdownItem>
402 <bsbDropdownItem>
403 <name>average</name>
404 <value>1</value>
405 <stringvalue/>
406 </bsbDropdownItem>
407 </bsbDropdownItemList>
408 <selectedIndex>1</selectedIndex>
409 <randomizable group="0" >false</randomizable>
410 </bsbObject>
411 <bsbObject version="2" type="BSBController" >
412 <objectName>fb</objectName>
413 <x>316</x>
414 <y>323</y>
415 <width>245</width>
416 <height>22</height>
417 <uuid>{e5b1e9a9-dccd-48fc-9aed-b507661a9285}</uuid>
418 <visible>true</visible>
419 <midichan>0</midichan>
420 <midicc>-3</midicc>
421 <objectName2>vert12</objectName2>
422 <xMin>0.00000000</xMin>
423 <xMax>1.00000000</xMax>
424 <yMin>0.00000000</yMin>
425 <yMax>1.00000000</yMax>
426 <xValue>0.00000000</xValue>
427 <yValue>0.68181800</yValue>
428 <type>fill</type>
429 <pointsize>1</pointsize>
430 <fadeSpeed>0.00000000</fadeSpeed>
431 <mouseControl act="press" >jump</mouseControl>
432 <color>
433 <r>0</r>
434 <g>234</g>
435 <b>0</b>
436 </color>
437 <randomizable mode="both" group="0" >false</randomizable>
438 <bgcolor>
439 <r>0</r>
440 <g>0</g>
441 <b>0</b>
442 </bgcolor>
443 </bsbObject>
444 <bsbObject version="2" type="BSBDisplay" >
445 <objectName/>
446 <x>10</x>
447 <y>0</y>
448 <width>554</width>
449 <height>192</height>
450 <uuid>{459873e4-6315-4d0e-b3ec-c11a4eeb684d}</uuid>
451 <visible>true</visible>
452 <midichan>0</midichan>
453 <midicc>-3</midicc>
454 <label>
455 This csd file writes the values from an audio file to a text file, from the selected starting time to the selected end time, in blocks of size determined by the decimation value. If decimation is 100, this means that 100 audio samples will write a single value to the text file.
456 You can select peak to store the sample with greatest absolute value or average to store the average of the set.
457 To use, select file to process using the Browse button, then press the render button and wait for the progress bar to go completely green.</label>
458 <alignment>center</alignment>
459 <font>DejaVu Sans</font>
460 <fontsize>14</fontsize>
461 <precision>3</precision>
462 <color>
463 <r>255</r>
464 <g>170</g>
465 <b>0</b>
466 </color>
467 <bgcolor mode="background" >
468 <r>17</r>
469 <g>16</g>
470 <b>15</b>
471 </bgcolor>
472 <bordermode>border</bordermode>
473 <borderradius>1</borderradius>
474 <borderwidth>1</borderwidth>
475 </bsbObject>
476 <bsbObject version="2" type="BSBButton" >
477 <objectName>_Browse2</objectName>
478 <x>460</x>
479 <y>283</y>
480 <width>100</width>
481 <height>30</height>
482 <uuid>{74549d53-e04d-4ded-a29b-44c94f9a4b98}</uuid>
483 <visible>true</visible>
484 <midichan>0</midichan>
485 <midicc>-3</midicc>
486 <type>value</type>
487 <pressedValue>1.00000000</pressedValue>
488 <stringvalue>/home/andres/Downloads/ahh.wav</stringvalue>
489 <text>Browse</text>
490 <image>/</image>
491 <eventLine/>
492 <latch>false</latch>
493 <latched>false</latched>
494 </bsbObject>
495 <bsbObject version="2" type="BSBLabel" >
496 <objectName/>
497 <x>12</x>
498 <y>256</y>
499 <width>80</width>
500 <height>25</height>
501 <uuid>{ea8af674-e3ae-4137-9e01-57526b64613f}</uuid>
502 <visible>true</visible>
503 <midichan>0</midichan>
504 <midicc>-3</midicc>
505 <label>Destination file</label>
506 <alignment>left</alignment>
507 <font>DejaVu Sans</font>
508 <fontsize>12</fontsize>
509 <precision>3</precision>
510 <color>
511 <r>0</r>
512 <g>0</g>
513 <b>0</b>
514 </color>
515 <bgcolor mode="nobackground" >
516 <r>255</r>
517 <g>255</g>
518 <b>255</b>
519 </bgcolor>
520 <bordermode>noborder</bordermode>
521 <borderradius>1</borderradius>
522 <borderwidth>1</borderwidth>
523 </bsbObject>
524 <bsbObject version="2" type="BSBLineEdit" >
525 <objectName>_Browse2</objectName>
526 <x>13</x>
527 <y>285</y>
528 <width>445</width>
529 <height>26</height>
530 <uuid>{39827a32-cd39-4b5a-8da5-ef292e89d626}</uuid>
531 <visible>true</visible>
532 <midichan>0</midichan>
533 <midicc>-3</midicc>
534 <label>/home/andres/Downloads/ahh.txt</label>
535 <alignment>left</alignment>
536 <font>DejaVu Sans</font>
537 <fontsize>10</fontsize>
538 <precision>3</precision>
539 <color>
540 <r>0</r>
541 <g>0</g>
542 <b>0</b>
543 </color>
544 <bgcolor mode="nobackground" >
545 <r>230</r>
546 <g>221</g>
547 <b>213</b>
548 </bgcolor>
549 <background>nobackground</background>
550 </bsbObject>
551 <objectName/>
552 <x>577</x>
553 <y>195</y>
554 <width>585</width>
555 <height>492</height>
556 <visible>true</visible>
557 </bsbPanel>
558 <bsbPresets>
559 </bsbPresets>
560 <MacOptions>
561 Version: 3
562 Render: Real
563 Ask: Yes
564 Functions: ioObject
565 Listing: Window
566 WindowBounds: 577 195 585 492
567 CurrentView: io
568 IOViewEdit: On
569 Options: -b128 -A -s -m167 -R
570 </MacOptions>
571 <MacGUI>
572 ioView background {35466, 40349, 41634}
573 ioText {95, 316} {80, 25} editnum 1000.000000 1.000000 "decimation" left "" 0 {0, 0, 0} {58880, 56576, 54528} nobackground noborder 1000.000000
574 ioText {11, 227} {445, 26} edit 0.000000 0.00100 "_Browse1" "Lucida Grande" 10 {0, 0, 0} {65280, 65280, 65280} falsenoborder /home/andres/Downloads/ahh.wav
575 ioButton {458, 225} {100, 30} value 1.000000 "_Browse1" "Browse" "/"
576 ioButton {188, 354} {375, 61} value 1.000000 "_Play" "Run" "/"
577 ioText {10, 198} {80, 25} label 0.000000 0.00100 "" left "DejaVu Sans" 12 {0, 0, 0} {58880, 56576, 54528} nobackground noborder File to load
578 ioText {12, 316} {80, 25} label 0.000000 0.00100 "" left "DejaVu Sans" 10 {0, 0, 0} {58880, 56576, 54528} nobackground noborder Decimation
579 ioText {95, 350} {80, 25} editnum 0.000000 1.000000 "start" left "" 0 {0, 0, 0} {58880, 56576, 54528} nobackground noborder 0.000000
580 ioText {12, 350} {86, 27} label 0.000000 0.00100 "" left "DejaVu Sans" 10 {0, 0, 0} {58880, 56576, 54528} nobackground noborder Start time (ms)
581 ioText {95, 387} {80, 25} editnum 1000.000000 1.000000 "end" left "" 0 {0, 0, 0} {58880, 56576, 54528} nobackground noborder 1000.000000
582 ioText {12, 387} {86, 25} label 0.000000 0.00100 "" left "DejaVu Sans" 10 {0, 0, 0} {58880, 56576, 54528} nobackground noborder End time (ms)
583 ioMenu {186, 318} {122, 30} 1 303 "peak,average" type
584 ioMeter {316, 323} {245, 22} {0, 59904, 0} "fb" 0.000000 "vert12" 0.681818 fill 1 0 mouse
585 ioText {10, 0} {554, 192} display 0.000000 0.00100 "" center "DejaVu Sans" 14 {65280, 43520, 0} {4352, 4096, 3840} nobackground noborder ¬This csd file writes the values from an audio file to a text file, from the selected starting time to the selected end time, in blocks of size determined by the decimation value. If decimation is 100, this means that 100 audio samples will write a single value to the text file.¬You can select peak to store the sample with greatest absolute value or average to store the average of the set.¬To use, select file to process using the Browse button, then press the render button and wait for the progress bar to go completely green.
586 ioButton {460, 283} {100, 30} value 1.000000 "_Browse2" "Browse" "/"
587 ioText {12, 256} {80, 25} label 0.000000 0.00100 "" left "DejaVu Sans" 12 {0, 0, 0} {58880, 56576, 54528} nobackground noborder Destination file
588 ioText {13, 285} {445, 26} edit 0.000000 0.00100 "_Browse2" "DejaVu Sans" 10 {0, 0, 0} {65280, 65280, 65280} falsenoborder /home/andres/Downloads/ahh.txt
589 </MacGUI>