Discussion:
Importing data with FileReader
daniel1989
2014-10-21 05:30:33 UTC
Permalink
Hello SC Community,

I'm trying to import a very large txt file (million+ data points, single
column, tab delimited) into SuperCollider so I can sonify it. However, I
would like to only import a certain range of the data each time I run the
program.

I know the FileReader function has a startRow argument, but is there a way
to also make it stop importing at a certain point? Like say I wanted to
import data points 100,000 to 150,000 out of the million data points in my
file. How would I do this?

Thanks,

Daniel



--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Importing-data-with-FileReader-tp7614174.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Fredrik Olofsson
2014-10-21 09:29:17 UTC
Permalink
because FileReader is a stream, it's pretty easy to hijack it and read out the data step-by-step. use .next to get the data up until the next delimiter, then just keep count.
something like this...

//generates a 17mb test file with data
(
var a= File("~/ttest.txt".standardizePath, "w");
1000000.do{|i| a.write(Char.tab++(i+1.0.rand)++Char.nl)};
a.close;
)

//read some data in the beginning of the test file back into a list
(
var startLine= 400, endLine= 599;
var a= FileReader("~/ttest.txt".standardizePath, delimiter: Char.tab);
var cnt= 0;
var tmp;
var res= List(endLine-startLine);
while({tmp= a.next; tmp.notNil and:{cnt<=endLine}}, {
if(cnt>=startLine, {
tmp= tmp[1].asFloat; //here might need to modify to match your data format
res.add(tmp);
});
cnt= cnt+1;
});
a.close;
~res= res; //access handle
)


~res.postcs
~res[0].class
~res.size

(
s.waitForBoot{
Pbind(\freq, Pseq(~res), \dur, 0.02, \legato, 0.1, \amp, 0.5).play;
};
)

//don't forget to delete the big ttest.txt in your home directory afterwards.
Post by daniel1989
Hello SC Community,
I'm trying to import a very large txt file (million+ data points, single
column, tab delimited) into SuperCollider so I can sonify it. However, I
would like to only import a certain range of the data each time I run the
program.
I know the FileReader function has a startRow argument, but is there a way
to also make it stop importing at a certain point? Like say I wanted to
import data points 100,000 to 150,000 out of the million data points in my
file. How would I do this?
Thanks,
Daniel
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Importing-data-with-FileReader-tp7614174.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
#|
fredrikolofsson.com musicalfieldsforever.com
|#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Loading...