How to upload different sound files into different buffers?

Hi. I’m starting learning SuperCollider, which is really fun.

I’m trying to upload 5 different soundfiles into 5 different variables, but it seems I can only use the b for some reason?

Can you post the code you are using? I think an answer will mean more if we can show where the problem in your code is stemming from. An initial guess is you are reassigning to the same environment variable.

1 Like

You can use any single lower case alphabet except s, and environment variables (~a, ~buffer, ~buffer1, piano_a4_f, ~b1, etc).

However, instead of creating independent variables, I would use an array or identity dictionary where buffers can be accessed. The following is the simplest way I know:

(
var
folderPath =  Platform.resourceDir +/+ "sounds",
soundFiles = SoundFile.collect(folderPath +/+ "*"),
paths_soundFiles = soundFiles.collect{ |soundFile| soundFile.path };

~buffers = paths_soundFiles.collect { |path| Buffer.read(s, path) };
)

~buffers[0].play
~buffers[1].play
~buffers[2].play

If you want access buffers with the file names:

(
var
folderPath =  Platform.resourceDir +/+ "sounds",
soundFiles = SoundFile.collect(folderPath +/+ "*"),
paths_soundFiles = soundFiles.collect{ |soundFile| soundFile.path };

~bufDicIDs = Dictionary[];  // just to compare
~bufDicNames = Dictionary[];
paths_soundFiles.do { |path, index|
    ~bufDicIDs.put(index, Buffer.read(s, path)); // just to compare
    ~bufDicNames.put(path.basename.splitext[0].asSymbol, Buffer.read(s, path));
}
)

~bufDicIDs.class // just to compare
~bufDicIDs.keys // just to compare
~bufDicIDs[0].play // just to compare
~bufDicIDs[1].play // just to compare
~bufDicIDs[2].play // just to compare

~bufDicNames.class
~bufDicNames.keys
~bufDicNames[\a11wlk01].play
~bufDicNames[\SinedPink].play
~bufDicNames['a11wlk01-44_1'].play

These snippets should only change the folderPath where the sound files are stored (wav, aif, aiff and flac are recommended). When using buffers and bufDicIDs the index in [] should be from 0 to the number of sound files - 1.

However, my code snippets may not be ideal for you. It would be nice to share your code snippet as @josh mentioned.

2 Likes