I’m using this strategy to iterate over a bunch of directories and shove them into appropriately named dictionaries:
First, I wrote an extension to the SoundFile class in order to load only one channel from a file:
+ SoundFile {
*collectIntoBuffersMono { | path = "sounds/*", server |
server = server ?? { Server.default };
if (server.serverRunning) {
^this.collect(path)
.collect { | sf |
Buffer(server, sf.numFrames, 1)
.allocReadChannel(sf.path, channels: [0])
.sampleRate_(sf.sampleRate);
}
} {
"the server must be running to collect soundfiles into buffers".error
}
}
}
Edit: just a bit of background for using SoundFile: when working with a large number of files (more than 700 or so) I found loading with other methods a bit hit and miss. SoundFile has worked consistently for me for a long time now, without ever missing any files, having to insert s.sync into the mix, or having to split the loading process into several batches.