-n -m0 ; Don't write audio file to disk and don't write messages
sr = 44100
ksmps = 1
nchnls = 1
0dbfs = 1
gihandle init 0
; By Andres Cabrera 2009
instr 1
; Receive the name from the text boxes
Sfilename invalue "_Browse1"
Sfilename2 invalue "_Browse2"
; Check duration and sample rate
ilen filelen Sfilename
; Load the audio file to f-table 50
ftfree 50, 0
Sline sprintf {{f 50 0 0 1 "%s" 0 0 1}}, Sfilename
scoreline_i Sline
;outvalue "fb", "Loading file..."
;receive decimation value
kdec invalue "decimation"
; Turn on instrument that clears progress bar
event_i "i", 97, 0, 1
; Turn on processing instrument for approprate time
event_i "i", 98, 5, ilen / i(kdec)
prints Sfilename2
gihandle fiopen Sfilename2, 0 ; open text file for writing
; When finished, quit
event_i "i", 100, (ilen/ i(kdec)) + 6, 1
endin
instr 97 ;clear progress bar
outvalue "fb", 0
endin
instr 98 ;traverse the file
kdec invalue "decimation"
kstart invalue "start"
kend invalue "end"
ktype invalue "type"
kindex init 0
kaccum init 0
ilen = nsamp(50)
; Convert time in ms to number of audio samples
kstart = kstart * sr /1000
kend = kend * sr /1000
loopstart:
kindex = kindex + 1
if ((kindex + kstart >= ilen) || (kindex + kstart > kend)) then
turnoff
endif
kvalue tab kindex + kstart, 50
if (ktype == 0) then ; if peak
if (kaccum < abs(kvalue)) then
kaccum = abs(kvalue)
endif
elseif (ktype == 1) then ; if average
kaccum = kaccum + kvalue
endif
; Check if kindex is a multiple of kdec
krem = kindex%kdec
if krem != 0 kgoto loopstart ; do loop
if (ktype == 1) then ; if average divide by number of elements
kaccum = kaccum / kdec
endif
event "i", 99, 0, 1, kaccum
kaccum = 0
outvalue "fb", kindex/(kend-kstart)
endin
instr 99 ;write one value
fouti gihandle, 0, 0, p4
turnoff
endin
instr 100 ;print end message
ficlose gihandle
exitnow
endin
f 50 0 2 2 0
i 1 0 6
577
195
585
492
true
138
157
162
decimation
95
316
80
25
{5985ba7b-3a4f-42f8-b0bd-1396aeef44ef}
true
0
-3
left
Lucida Grande
10
0
0
0
255
255
255
1.00000000
-1e+12
1e+12
false
1000
_Browse1
11
227
445
26
{8ccac1d4-3d0f-4b78-ac22-54a0e0737f9e}
true
0
-3
left
Lucida Grande
10
3
0
0
0
230
221
213
nobackground
_Browse1
458
225
100
30
{d2185fce-b4fa-4050-ab3f-423836a05f50}
true
0
-3
value
1.00000000
/home/andres/Downloads/ahh.wav
Browse
/
false
false
_Play
188
354
375
61
{a1dc4742-c982-44ec-835e-f768af82eaf7}
true
0
-3
value
1.00000000
Run
/
false
false
10
198
80
25
{3528a3f8-9966-435b-b433-fc9954eeebfa}
true
0
-3
left
DejaVu Sans
12
3
0
0
0
255
255
255
noborder
1
1
12
316
80
25
{8dce1321-3b31-448a-a9d7-d297b8bfd079}
true
0
-3
left
DejaVu Sans
10
3
0
0
0
255
255
255
noborder
1
1
start
95
350
80
25
{7e459bdb-9dbc-480d-bbe5-b01b7fbd0098}
true
0
-3
left
Lucida Grande
10
0
0
0
255
255
255
1.00000000
-1e+12
1e+12
false
0
12
350
86
27
{31fab7b1-bca8-4c5c-ae61-99d3d49c68c3}
true
0
-3
left
DejaVu Sans
10
3
0
0
0
255
255
255
noborder
1
1
end
95
387
80
25
{34f55718-74e5-468a-b2b4-166af109c4fc}
true
0
-3
left
Lucida Grande
10
0
0
0
255
255
255
1.00000000
-1e+12
1e+12
false
1000
12
387
86
25
{7c13cdf3-8d2e-4a7f-a3ca-a40e9b94a71f}
true
0
-3
left
DejaVu Sans
10
3
0
0
0
255
255
255
noborder
1
1
type
186
318
122
30
{6ce4ec10-ce8a-42d4-8af3-9afda3c83a2a}
true
0
-3
peak
0
average
1
1
false
fb
316
323
245
22
{e5b1e9a9-dccd-48fc-9aed-b507661a9285}
true
0
-3
vert12
0.00000000
1.00000000
0.00000000
1.00000000
0.00000000
0.68181800
fill
1
0.00000000
jump
0
234
0
false
0
0
0
10
0
554
192
{459873e4-6315-4d0e-b3ec-c11a4eeb684d}
true
0
-3
center
DejaVu Sans
14
3
255
170
0
17
16
15
border
1
1
_Browse2
460
283
100
30
{74549d53-e04d-4ded-a29b-44c94f9a4b98}
true
0
-3
value
1.00000000
/home/andres/Downloads/ahh.wav
Browse
/
false
false
12
256
80
25
{ea8af674-e3ae-4137-9e01-57526b64613f}
true
0
-3
left
DejaVu Sans
12
3
0
0
0
255
255
255
noborder
1
1
_Browse2
13
285
445
26
{39827a32-cd39-4b5a-8da5-ef292e89d626}
true
0
-3
left
DejaVu Sans
10
3
0
0
0
230
221
213
nobackground
577
195
585
492
true
Version: 3
Render: Real
Ask: Yes
Functions: ioObject
Listing: Window
WindowBounds: 577 195 585 492
CurrentView: io
IOViewEdit: On
Options: -b128 -A -s -m167 -R
ioView background {35466, 40349, 41634}
ioText {95, 316} {80, 25} editnum 1000.000000 1.000000 "decimation" left "" 0 {0, 0, 0} {58880, 56576, 54528} nobackground noborder 1000.000000
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
ioButton {458, 225} {100, 30} value 1.000000 "_Browse1" "Browse" "/"
ioButton {188, 354} {375, 61} value 1.000000 "_Play" "Run" "/"
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
ioText {12, 316} {80, 25} label 0.000000 0.00100 "" left "DejaVu Sans" 10 {0, 0, 0} {58880, 56576, 54528} nobackground noborder Decimation
ioText {95, 350} {80, 25} editnum 0.000000 1.000000 "start" left "" 0 {0, 0, 0} {58880, 56576, 54528} nobackground noborder 0.000000
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)
ioText {95, 387} {80, 25} editnum 1000.000000 1.000000 "end" left "" 0 {0, 0, 0} {58880, 56576, 54528} nobackground noborder 1000.000000
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)
ioMenu {186, 318} {122, 30} 1 303 "peak,average" type
ioMeter {316, 323} {245, 22} {0, 59904, 0} "fb" 0.000000 "vert12" 0.681818 fill 1 0 mouse
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.
ioButton {460, 283} {100, 30} value 1.000000 "_Browse2" "Browse" "/"
ioText {12, 256} {80, 25} label 0.000000 0.00100 "" left "DejaVu Sans" 12 {0, 0, 0} {58880, 56576, 54528} nobackground noborder Destination file
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