-+max_str_len=10000 -n
/****SOUNDFILE SPLITTER****
joachim heintz june 2010**/
0dbfs = 1
ksmps = 128; if you want to avoid that some samples without sound are added at the end of the soundfile, use ksmps=1. but this will be slow for large files
nchnls = 1
instr 1
gSfile invalue "_Browse1"
ilen filelen gSfile
;as time resolution in csound is bound to ksmps, one control period must be added to avoid omitting samples
p3 = (ksmps == 1 ? ilen : ilen + ksmps/sr)
inchnls filenchnls gSfile
if inchnls == 2 then
event_i "i", 12, 0, p3
elseif inchnls == 4 then
event_i "i", 14, 0, p3
elseif inchnls == 8 then
event_i "i", 18, 0, p3
else
event_i "i", 20, 0, .1, inchnls, p3
endif
endin
instr 12; split stereo file
a1, a2 soundin gSfile
ibit filebit gSfile
ibitform = (ibit == 24 ? 8 : (ibit == 32 ? 6 : 4))
iposp strrindex gSfile, "."
Spath strsub gSfile, 0, iposp; path without suffix
Suff strsub gSfile, iposp; suffix
S1 sprintf "%s_1%s", Spath, Suff
S2 sprintf "%s_2%s", Spath, Suff
fout S1, ibitform, a1
fout S2, ibitform, a2
endin
instr 14; split quadro file
a1, a2, a3, a4 soundin gSfile
ibit filebit gSfile
ibitform = (ibit == 24 ? 8 : (ibit == 32 ? 6 : 4))
iposp strrindex gSfile, "."
Spath strsub gSfile, 0, iposp; path without suffix
Suff strsub gSfile, iposp; suffix
S1 sprintf "%s_1%s", Spath, Suff
S2 sprintf "%s_2%s", Spath, Suff
S3 sprintf "%s_3%s", Spath, Suff
S4 sprintf "%s_4%s", Spath, Suff
fout S1, ibitform, a1
fout S2, ibitform, a2
fout S3, ibitform, a3
fout S4, ibitform, a4
endin
instr 18; split octo file
a1, a2, a3, a4, a5, a6, a7, a8 soundin gSfile
ibit filebit gSfile
ibitform = (ibit == 24 ? 8 : (ibit == 32 ? 6 : 4))
iposp strrindex gSfile, "."
Spath strsub gSfile, 0, iposp; path without suffix
Suff strsub gSfile, iposp; suffix
S1 sprintf "%s_1%s", Spath, Suff
S2 sprintf "%s_2%s", Spath, Suff
S3 sprintf "%s_3%s", Spath, Suff
S4 sprintf "%s_4%s", Spath, Suff
S5 sprintf "%s_5%s", Spath, Suff
S6 sprintf "%s_6%s", Spath, Suff
S7 sprintf "%s_7%s", Spath, Suff
S8 sprintf "%s_8%s", Spath, Suff
fout S1, ibitform, a1
fout S2, ibitform, a2
fout S3, ibitform, a3
fout S4, ibitform, a4
fout S5, ibitform, a5
fout S6, ibitform, a6
fout S7, ibitform, a7
fout S8, ibitform, a8
endin
instr 20; splits any type of multichannel file. depends on ths system opcode, so it might only work on linux and osx
Sfil = gSfile
inchnls = p4
ilen = p5
ibit filebit Sfil
ibitform = (ibit == 24 ? 8 : (ibit == 32 ? 6 : 4))
;format a .csd file
Scsd1 sprintf {{
-+max_str_len=10000 -n -i%s
0dbfs = 1
ksmps = %d
nchnls = %d
opcode SF_Split, 0, Siii
Sfile, inchnls, ichn, ibitform xin
ain inch ichn
iposp strrindex Sfile, "."
Spath strsub Sfile, 0, iposp
Suff strsub Sfile, iposp
Soutnam sprintf "%s", Spath, ichn, Suff
fout Soutnam, ibitform, ain
if ichn < inchnls then
SF_Split Sfile, inchnls, ichn+1, ibitform
endif
endop
instr 1
SF_Split "%s", %d, 1, %d
endin
%s
i 1 0 %d
e
}}, Sfil, ksmps, inchnls, "%s_%d%s", Sfil, inchnls, ibitform, "", ilen
;write the file and execute it
Stask sprintf {{cat<>/tmp/tmp.csd\n%s\nEOF
/usr/local/bin/csound /tmp/tmp.csd
rm /tmp/tmp.csd}}, Scsd1
ires system_i 1, Stask, 1
endin
i 1 0 1
e
0
0
524
263
true
170
170
127
_Browse1
364
69
100
30
{6d6f3649-5d94-4759-afc8-887cc1872c39}
true
0
-3
value
1.00000000
Select File
/
false
false
_Browse1
17
72
345
24
{dcd7f769-c32b-4cc8-bc82-9848d5b36937}
true
0
-3
left
Lucida Grande
12
3
0
0
0
206
206
206
nobackground
_Render
163
107
151
31
{a9b11523-b4f3-419f-8637-88da098e53f3}
true
0
-3
value
1.00000000
Split!
/
i1 0 10
false
true
85
16
335
39
{46df577d-4fc5-4d07-a9cb-08d73733ad30}
true
0
-3
center
Arial
24
3
0
0
0
255
255
255
noborder
1
1
19
147
446
81
{e54e17da-3808-49a3-84a6-608f476c3200}
true
0
0
center
Arial
14
3
0
0
0
255
255
255
noborder
1
1