-+max_str_len=10000 -n
/***Envelope Extractor***/
;example for CsoundQt
;joachim heintz mar 2011
sr = 44100
ksmps = 1 ;use ksmps=1 for avoiding roundoff inaccuracies
nchnls = 1
0dbfs = 1
opcode StrayGetEl, ii, Sijj
;returns the startindex and the endindex (= the first space after the element) for ielindex in String. if startindex returns -1, the element has not been found
Stray, ielindx, isepA, isepB xin
;;DEFINE THE SEPARATORS
isep1 = (isepA == -1 ? 32 : isepA)
isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB))
Sep1 sprintf "%c", isep1
Sep2 sprintf "%c", isep2
;;INITIALIZE SOME PARAMETERS
ilen strlen Stray
istartsel = -1; startindex for searched element
iendsel = -1; endindex for searched element
iel = 0; actual number of element while searching
iwarleer = 1
indx = 0
if ilen == 0 igoto end ;don't go into the loop if Stray is empty
loop:
Snext strsub Stray, indx, indx+1; next sign
isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1
isep2p strcmp Snext, Sep2; 0 if Snext is sep2
;;NEXT SIGN IS NOT SEP1 NOR SEP2
if isep1p != 0 && isep2p != 0 then
if iwarleer == 1 then; first character after a separator
if iel == ielindx then; if searched element index
istartsel = indx; set it
iwarleer = 0
else ;if not searched element index
iel = iel+1; increase it
iwarleer = 0; log that it's not a separator
endif
endif
;;NEXT SIGN IS SEP1 OR SEP2
else
if istartsel > -1 then; if this is first selector after searched element
iendsel = indx; set iendsel
igoto end ;break
else
iwarleer = 1
endif
endif
loop_lt indx, 1, ilen, loop
end: xout istartsel, iendsel
endop
opcode StrayLen, i, Sjj
;returns the number of elements in Stray. elements are defined by two separators as ASCII coded characters: isep1 defaults to 32 (= space), isep2 defaults to 9 (= tab). if just one separator is used, isep2 equals isep1
Stray, isepA, isepB xin
;;DEFINE THE SEPARATORS
isep1 = (isepA == -1 ? 32 : isepA)
isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB))
Sep1 sprintf "%c", isep1
Sep2 sprintf "%c", isep2
;;INITIALIZE SOME PARAMETERS
ilen strlen Stray
icount = 0; number of elements
iwarsep = 1
indx = 0
if ilen == 0 igoto end ;don't go into the loop if String is empty
loop:
Snext strsub Stray, indx, indx+1; next sign
isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1
isep2p strcmp Snext, Sep2; 0 if Snext is sep2
if isep1p == 0 || isep2p == 0 then; if sep1 or sep2
iwarsep = 1; tell the log so
else ; if not
if iwarsep == 1 then ; and has been sep1 or sep2 before
icount = icount + 1; increase counter
iwarsep = 0; and tell you are ot sep1 nor sep2
endif
endif
loop_lt indx, 1, ilen, loop
end: xout icount
endop
opcode StrayGetNum, i, Sijj
;returns the startindex and the endindex (= the first space after the element) for ielindex in String. if startindex returns -1, the element has not been found
Stray, ielindx, isepA, isepB xin
;;DEFINE THE SEPARATORS
isep1 = (isepA == -1 ? 32 : isepA)
isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB))
Sep1 sprintf "%c", isep1
Sep2 sprintf "%c", isep2
;;INITIALIZE SOME PARAMETERS
ilen strlen Stray
istartsel = -1; startindex for searched element
iendsel = -1; endindex for searched element
iel = 0; actual number of element while searching
iwarleer = 1
indx = 0
if ilen == 0 igoto end ;don't go into the loop if Stray is empty
loop:
Snext strsub Stray, indx, indx+1; next sign
isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1
isep2p strcmp Snext, Sep2; 0 if Snext is sep2
;;NEXT SIGN IS NOT SEP1 NOR SEP2
if isep1p != 0 && isep2p != 0 then
if iwarleer == 1 then; first character after a separator
if iel == ielindx then; if searched element index
istartsel = indx; set it
iwarleer = 0
else ;if not searched element index
iel = iel+1; increase it
iwarleer = 0; log that it's not a separator
endif
endif
;;NEXT SIGN IS SEP1 OR SEP2
else
if istartsel > -1 then; if this is first selector after searched element
iendsel = indx; set iendsel
igoto end ;break
else
iwarleer = 1
endif
endif
loop_lt indx, 1, ilen, loop
end:
Snum strsub Stray, istartsel, iendsel
inum strtod Snum
xout inum
endop
opcode FilePlay1, a, Skoo
;gives mono output regardless your soundfile is mono or stereo
;(if stereo, just the first channel is used)
Sfil, kspeed, iskip, iloop xin
ichn filenchnls Sfil
if ichn == 1 then
aout diskin2 Sfil, kspeed, iskip, iloop
else
aout, ano diskin2 Sfil, kspeed, iskip, iloop
endif
xout aout
endop
instr 1 ;distribute values and calls instr 2
Sfiles invalue "_MBrowse"
Snpoints invalue "npoints"
Sftnums invalue "ftnums"
gSoutfil invalue "_Browse"
inumfils StrayLen Sfiles, 124
p3 = inumfils/10 + 0.1
inumpnts StrayLen Snpoints
inumftns StrayLen Sftnums
indx = 0
loop:
ist, ien StrayGetEl Sfiles, indx, 124
Sfile strsub Sfiles, ist, ien
if inumpnts == 1 then
inpoints StrayGetNum Snpoints, 0
else
inpoints StrayGetNum Snpoints, indx
endif
if inumftns == 1 then
iftnum StrayGetNum Sftnums, 0
else
iftnum StrayGetNum Sftnums, indx
endif
Scall sprintf {{i 2 %f .1 "%s" %d %d}}, indx/10, Sfile, inpoints, iftnum
scoreline_i Scall
loop_lt indx, 1, inumfils, loop
endin
instr 2 ;performs analysis and calls instr 3
Sfile strget p4
inpoints = p5
iftnum = p6
ilslash strrindex Sfile, "/"
Snamsuf strsub Sfile, ilslash+1
ilsuf strrindex Snamsuf, "."
Sname strsub Snamsuf, 0, ilsuf
Sformat sprintf "gi_%s ftgen %d, 0, -%d, -2", Sname, iftnum, inpoints
;fprints gSoutfil, Sformat
ifilen filelen Sfile
ifilkcyc = ifilen*sr/ksmps ;number of k-cycles
kcount init 0
loop:
idt = ifilen / inpoints
asig FilePlay1 Sfile, 1
aenv follow asig, idt
kenv downsamp aenv
if kcount % round(ifilkcyc/inpoints) == 0 then
Snew sprintfk "%s, %f", Sformat, kenv
Sformat strcpyk Snew
endif
loop_lt kcount, 1, ifilkcyc, loop
gSwrite strcatk Sformat, "\n"
event "i", 3, 0, .1
turnoff
endin
instr 3 ;writes resulting tables to file
fprints gSoutfil, gSwrite
printf_i "Values written to file '%s'\n", 1, gSoutfil
endin
i 1 0 1
00788466true170170127_MBrowse27426134329{fe1e66fe-4105-4aed-9c04-e06ef3c95aa2}true00right
DejaVu Sans
143000206206206nobackground_MBrowse62126010030{7e9d3773-29f5-4906-91f7-3e35e562dfa6}true00value1.00000000/home/jh/Joachim/Materialien/SamplesKlangbearbeitung/BratscheMonoOneCycle.wav|/home/jh/Joachim/Materialien/SamplesKlangbearbeitung/EineWelleMono.aiff|/home/jh/Joachim/Materialien/SamplesKlangbearbeitung/Glocke_Ganze1.aiff|/home/jh/Joachim/Materialien/SamplesKlangbearbeitung/Kontrabass.aifSelect Files/falsefalsenpoints27433234329{56ac7a23-6421-41d3-bede-c48a63166f2f}true00left
Arial
143000206206206nobackground8526018830{c0c2d141-f138-41bc-8c76-f59252e79007}true00right
Arial
143000255255255noborder113432623943{59338b2d-457d-4151-9067-70221d3660d1}true00right
Arial
143000255255255noborder11ftnums27437534329{efef5429-8ce4-477c-b240-24a2627c6e99}true00left
Arial
143000206206206nobackground3337124041{25982a05-2dd6-489a-9fbc-cc5d94250b4a}true00right
Arial
143000255255255noborder11_Browse27429534329{37827e7b-547c-44ee-9ed7-91da451a1bc6}true00right
Arial
143000206206206nobackground_Browse62129410030{9a15fa00-1fac-478d-9857-be9b89935695}true00value1.00000000/home/jh/env_out.txtSelect File/falsefalse3229524129{5b54c68d-0de1-4915-9029-101af74e6f8d}true00right
Arial
143000255255255noborder1121769956{0fe8443c-9a6f-4f4a-9ea3-296c28ad4fb7}true00center
Arial
403000255255255noborder112069700187{f02e3ae5-27d7-4d40-b5c2-242497d54eba}true00left
Arial
163000255255255noborder11_Render62133110074{fa20b460-4974-43cd-9729-9bde68d583db}true00value1.00000000/home/linux/Desktop/test2.txtAnalyse
and write
to textfile!/falsetrue