Discussion:
Dynamically loading a folder of sound files into an array of buffers
Henrik Ekeus
2011-02-13 19:58:00 UTC
Permalink
Hi Everyone!

I need to load the contents of a folder of sound files into
buffers. The folder of sounds has files named with the format
s<someNumber>nameoffile.aif .... i.e. s001AFile.aif,
s002Anotherfile.aif etc..

What I need to do is to have these sound files loaded into an
arrayOfBuffers, in the index that corresponds to the number in the
filename. So s005YetAnotherFile.aif should be stored in my
'soundFileBuffers' array at index 5.

So i'm trying to write my function 'loadSoundFileBuffers' that would
load my 'soundFileBuffers' array.. below is what I have so far..

loadSoundFileBuffers {
//Read the contents of a folder of sound files and load into the
array 'soundFileBuffer'
//use format: s001nameoffile.aif s002nameofotherfile.aif
var numberOfFiles;

//How do I get a directory listing or somesuch?

soundFileBuffers=Array.new(numberOfFiles);

//iterate through and fill the thing!

}

So i'm sure this is meant to be very easy, but it is eluding me for the
moment.. anybody out there fancy doing it in 140 characters or less? ;)

Any help is much appreciated, as always.
Cheers!
Henrik




_______________________________________________
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/
Matthias Kispert
2011-02-13 20:10:41 UTC
Permalink
Hi Henrik ;-)

The pathMatch method should be what you're looking for - from the String
helpfile:


pathMatch

Returns an Array containing all paths matching this String. Wildcards apply,
non-recursive.

Post << "Help/*".pathMatch;

Best,
Matthias :-B
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Dynamically-loading-a-folder-of-sound-files-into-an-array-of-buffers-tp6021499p6021529.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/
James Harkins
2011-02-14 01:04:46 UTC
Permalink
At Sun, 13 Feb 2011 12:10:41 -0800 (PST),
Post by Matthias Kispert
Hi Henrik ;-)
The pathMatch method should be what you're looking for - from the String
pathMatch
Returns an Array containing all paths matching this String. Wildcards apply,
non-recursive.
I found lately, even some regexp-ish things are supported:

"s[0-9]+.*.aif".pathMatch

... would match s002Anotherfile.aif but not someUnnumberedFile.aif, whereas "s*.aif" would match both.

hjh


--
James Harkins /// dewdrop world
jamshark70-***@public.gmane.org
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks

_______________________________________________
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/
Nick Inhofe
2011-02-14 01:30:02 UTC
Permalink
If you have a folder that consists of an ordered set of sound files, this
class extension should do the trick. If not, its a good start anyway.

/*
loadFolder method takes a path for a folder of sound files
returns an array of buffers with those sound files;
*/

+ Buffer {

*loadFolder {
arg
server = Server.default,
path, //path to folder
mono = false; //should we only load the first channel?

var folder, buffers;

folder = PathName(path);

buffers = folder.files.collect({
|file|
if(mono,
{ Buffer.readChannel(server, file.fullPath, channels: 0); },
{ Buffer.read(server, file.fullPath); }
);
});

^buffers;
}
}
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Dynamically-loading-a-folder-of-sound-files-into-an-array-of-buffers-tp6021499p6022140.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/
dcm
2011-02-13 20:45:39 UTC
Permalink
Here is an answer I got from a similar question.

arrayOfBuffers = "sounds/*".pathMatch.collect {|file| Buffer.read(s,
file);};
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Dynamically-loading-a-folder-of-sound-files-into-an-array-of-buffers-tp6021499p6021609.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/
nescivi
2011-02-14 09:09:54 UTC
Permalink
Post by dcm
Here is an answer I got from a similar question.
arrayOfBuffers = "sounds/*".pathMatch.collect {|file| Buffer.read(s,
file);};
And put a .sort in between, and you'll have them in the right order.
(also works for most of the other suggestions in this thread).

arrayOfBuffers = "sounds/*".pathMatch.sort.collect {|file| Buffer.read(s,
file);};


sincerely,
Marije


_______________________________________________
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...