## Trying to play a random sample from a selection of 8+

Nov 20, 2011 at 3:58pm

# Trying to play a random sample from a selection of 8+

So I’m working on a sampler where each button on a Wii Remote accesses a different bank of eight samples (32 in total). I’m trying to have it so that if I press Up, say, then it’ll play a random sample from the eight that it can access. The problem is, I can’t really work out how to do this. I’ve got a simple (and unimpressive) patch, but I’m almost certain I’m going about it the wrong way. Do I need to have 32 different buffers? Or is there a more efficient way I can do this? I’ve got a list of what I want the patch to do:

Bank of samples e.g. four groups of eight (1-32). Assigned to D-Pad on remote.

Bank A: Up. Plays random sample from 1-8
Bank B: Right. Plays random sample from 9-16
Bank C: Down. Plays random sample from 17-24
Bank D: Left. Plays random sample from 25-32

Best way to do this? Series of buffer~/groove~ objects into random selector?

A Button: Play/Pause
B Button: Reverse/Forwards?

Pitch: Pitch shift.
Roll: Sample Rate 0-1 -1-0

Second remote – Live sampling. Record live instruments into buffer(s). Store samples, have some kind of system of scrolling through them, playing and selecting what part of sample to play. Adjustable sample rate + fx?

And here’s the patch I have so far:

– Pasted Max Patch, click to expand. –

Can anyone help? Been stuck on this for a fair while.

#60124
Nov 20, 2011 at 4:47pm

you need [polybuffer~] and [poly~]
inside the [poly~] use a [groove~] or [play~]
mastering these objects now will seriously seriously pay off in the future
if you are into this sort of thing

#216450
Nov 20, 2011 at 5:07pm

Thanks pid. Going to have a bash with poly~, but I’m guessing polybuffer~ is only in Max 6?

#216451
Nov 20, 2011 at 5:33pm

The polybuffer~ method is the most versatile, but you could also do it with four sfplay~ objects and one sflist~ object that’s preloaded with 32 different cues.

#216452
Nov 20, 2011 at 5:42pm

I’ve tried that quickly with one sfplay~ and eight cues, although some of the files won’t play. The Max window says “sfplay~ no open file”. Why does it do that for some of the files and not others? Here’s that specific part:

– Pasted Max Patch, click to expand. –

I’m thinking though that poly~ or polybuffer~ (is it a Max 6 object or an external?) will probably be better in the long run in terms of changing the sample rates etc. as the samples are playing?

#216453
Nov 20, 2011 at 7:21pm

There are a couple bugs in your patch.
1) Your “open test1.wav” message is connected to the wrong object. That’s the cause of the “no open file” errors. When you give the sfplay~ a “1″ message, it finds no open file.
2) You should add 2 to the random numbers, not 1. As it is, you’re never playing cue 9, and you’re playing “test1.wav” with both cues 1 and 2 (or would be if you opened the file correctly).
3) You don’t really need the prepend object, because the sfplay~ is already associated with the sflist test because of its argument.
So, assuming your soundfiles all exist and are findable by Max, this should work:

– Pasted Max Patch, click to expand. –
#216454
Nov 20, 2011 at 7:28pm

That works like a charm, thanks Christopher! I have a couple of questions though.

On the patch, why are test2.wav and test8.wav both ‘preload 3′? Also, I don’t quite understand why I need to add 2 instead of 1.

#216455
Nov 20, 2011 at 9:21pm

Hi
I’m unable to view your patch as I’m not on my Max machine at the moment but..
take a look at the [sfplay~] helpfile; I believe this is because you are both opening and preloading files, so your ‘second’ file is preload or cue #2; there is no such thing as preload #1.

?

Brendan

ps keen to see your finished patch :)

#216456
Nov 20, 2011 at 11:28pm

@PhilSMaguire: Sorry, that’s just a typo on my part. The last “preload 3″ should be “preload 9″. Doh!

n00b_meister is correct in pointing out that the ‘open’ message assigns a soundfile to cue 1, and the ‘preload’ message is only for cues 2 and greater. In my example, I chose just to ignore cue 1, and assign all 8 files to cues 2 through 9 the way you had done, so there’s no need to use cue 1. Thus, by adding 2 to all your random numbers, you’ll get numbers 2 through 9 which can be used directly as the cue numbers.

#216457
Nov 21, 2011 at 8:26am

Ah, I see! Awesome :) Got part of it working close to how I want now. Hopefully have a rough version finished this week! Thanks for the help guys, I’ll shout if I get stuck again.

Phil.

#216458
Nov 21, 2011 at 8:37pm

So all I did just now was change the files in the ‘preload’ message boxes, and I’m getting error messages. The first I get is that “test” on the sflist~ test object is already taken, and the second is that sflist~ test3 has ‘no cue’. I don’t understand what that means, or how I did it in the first place? Nothing is playing on sflist~ test, and only a few files are playing on sflist~ test3. All of the sound files are in the search path of the patch. The old ones are where they always have been, and the new ones are also in that folder.

– Pasted Max Patch, click to expand. –
#216459

You must be logged in to reply to this topic.