Play~ Individual Control of Sample Length & Pitch

Jan 16, 2006 at 9:44pm

Play~ Individual Control of Sample Length & Pitch

I have been trying to use play~ to control samples used in a drum machine
patch. The advantage I have with play is the ability to change the start,
length and read speed of the sample in the buffer. The problem I have is
that I need control of the length of sample at every pitch range. The way
play alters the pitch is by shortening or lengthening the the read in which
the buffer is read. Thus if I have set the pitch and then shorten the length
of the sample it changes its pitch again.

Is there away to make them mutally exclusive ? Or would using another file
playing object (groove~,sfplay~) be a better option?

Will

#23947
Jan 31, 2006 at 5:07pm

Can anyone help me with this? I really dont see how I get the two parameters to operate individually.

#68472
Jan 31, 2006 at 5:07pm

#68473
Jan 31, 2006 at 6:08pm

You can try a granular solution. I have the [gran.play.file~]
abstraction as part of my granular toolkit. URL below.

—–
Nathan Wolek
nw@nathanwolek.com

http://www.nathanwolek.com

#68474
Feb 1, 2006 at 5:09pm

Thanks for the suggestion but I am trying to build this without using externals.

When I am trying to do is be able to control the pitch of the sample and length, regardless of one another which to me seems nearly impossible with play~ unless theres a formula which maintains the pitch when the length is changed.

I am starting to edge towards using a different sound object. I tried it with groove and a waveform viewer, but in order to change the length the sample has to be looped and thats no good for a drum machine.

Are there any other sound playing objects which would enable me to manipulate the buffer in this way?

#68475
Feb 1, 2006 at 11:19pm

Here’s one way to do it. I wouldn’t recommend this setup for
controlling a drum machine, since it’s relying on the scheduler/queue
to do triggering, but hopefully it’ll give a point for jumping off…

Also – You should check out [wave~] and all of the MSP tutorials as
well. I think the sampling sections could be particularly helpful to
you.

max v2;
#N vpatcher 10 59 350 571;
#P origin -10 0;
#P window setfont “Sans Serif” 9.;
#P newex 25 280 53 196617 route rim;
#P newex 25 258 85 196617 pack rim 0. 0. 0.;
#P button 25 235 15 0;
#P user ezdac~ 25 419 69 452 0;
#P newex 25 309 51 196617 zl slice 2;
#P newex 25 342 32 196617 line~;
#P message 24 457 43 196617 replace;
#P newex 24 477 66 196617 buffer~ rant;
#P newex 25 364 57 196617 play~ rant;
#P comment 90 128 58 196617 loop length;
#P comment 98 180 55 196617 ramp time;
#P flonum 53 179 44 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 53 157 27 196617 / 1.;
#P flonum 53 128 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 53 107 23 196617 abs;
#P newex 53 87 27 196617 -;
#P flonum 184 37 35 9 0.001 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 111 37 56 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 112 23 21 196617 end;
#P flonum 53 37 56 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 54 23 30 196617 start;
#P comment 186 23 129 196617 pitch (1= no transposition);
#P newex 184 62 29 196617 t b f;
#P newex 111 62 29 196617 t b f;
#P comment 4 219 38 196617 play it;
#P connect 18 0 17 0;
#P connect 22 0 23 0;
#P connect 23 0 24 0;
#P connect 24 0 20 0;
#P connect 20 1 19 0;
#P connect 20 0 19 0;
#P connect 19 0 16 0;
#P connect 16 0 21 0;
#P fasten 7 0 23 1 116 58 31 58 31 210 55 210;
#P lcolor 2;
#P connect 5 0 9 0;
#P fasten 1 0 9 0 116 81 58 81;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P connect 11 0 12 0;
#P fasten 2 0 12 0 189 149 58 149;
#P connect 12 0 13 0;
#P connect 16 0 21 1;
#P fasten 1 1 9 1 135 83 75 83;
#P fasten 2 1 12 1 208 153 75 153;
#P connect 13 0 23 2;
#P fasten 5 0 23 3 58 55 27 55 27 213 105 213;
#P connect 7 0 1 0;
#P connect 8 0 2 0;
#P pop;

#68476
Feb 2, 2006 at 9:25pm

On Feb 1, 2006, at 9:09 AM, Will Pickersgill wrote:

>
> Thanks for the suggestion but I am trying to build this without
> using externals.

> When I am trying to do is be able to control the pitch of the sample
> and length, regardless of one another which to me seems nearly
> impossible with play~ unless theres a formula which maintains the
> pitch when the length is changed.

Dude. That’s what we call a non-trivial problem. There is no formula
for this. This is one of the classic signal theory problems.

The main crux of the problem is that you have to either lose or
fabricate information to change pitch without changing speed. This is
because you’re trying to affect the frequency domain in the time
domain, these two domains are not orthogonal… frequency depends on
time. The solution to the problem will most likely also be non-
trivial (especially to solve the problem with a minimum of audible/
unwanted artifacts) and it definitely can’t be perfect because of the
change in information. That’s why people here use externals to do it.

Sorry, I don’t mean to rant but I’m sure that you could have gleaned
the difficulty of your task from the previous replies and from your
experiments. You’re smart: if it’s not simple to you then it’s
probably not simple.

I think other people have mentioned using gizmo~. I believe that’s
not a bad way to change the pitch without changing the speed, so just
take into account the pitch change you induced with play~ and you’re
golden.

I think gizmo~ uses FFT. I have written a few patches that use
granular techniques towards the same end. The real tough part is to
get rid of the artifacts, and at some point your input to output
information ratio will just be too skewed to effectively do so.

> I am starting to edge towards using a different sound object. I
> tried it with groove and a waveform viewer, but in order to change
> the length the sample has to be looped and thats no good for a drum
> machine.
>
> Are there any other sound playing objects which would enable me to
> manipulate the buffer in this way?

Programming is a compromise, just like Art.

_Mark

#68477
Feb 3, 2006 at 7:55pm

Thanks for your help. I have managed to rig something up with everyones advice.

I am now trying to get a jsui dial to update itself with the length of the sample loaded into the buffer. I want to take the sample length time from info~ and feed into the jsui dial so that its max range is that of the sample length.

The only way I can see to do it is by passing it a message which would update the java script of the dial, namely the variable “val”.

Any suggestions?

Will

#68478
Feb 3, 2006 at 9:54pm

I’d be curious to see what you came up with, if you’re willing to
share. – David

#68479
Feb 6, 2006 at 12:15pm

Well to be honest its not all that different from the help thats been given. I havent implemented gizmo~ or anything like that. Davids method of transposing as been used and I have added a velocity dial.

It works quite efficiently in my drum machine. For the velocity I am using a matrixctrl in dial mode with 3 different settings (hard, medium, soft velocity). When hard is selected 1′s appear in the pattrstorage, when medium 2′s etc. I want to be able to extract from the pattrstorage the cells value and correspond it to a velocity value. Would the best way to do this be to filter the output of the pattrstorage and use if statements to trigger a set velocity value?

I hope that is clear?

Will

max v2;
#N vpatcher 59 42 1034 681;
#P window setfont “Sans Serif” 9.;
#P comment 230 85 42 9109513 Velocity;
#P newex 138 542 27 9109513 *~;
#P user dial 233 105 40 40 128 1 0 0 159 270 1 1. 170 170 170 221 221 221 120 120 120 225 225 225 0 0 0 0 0 0;
#P newex 261 491 120 9109513 rampsmooth~ 44100 44100;
#P newex 261 398 37 9109513 line~;
#P message 261 370 30 9109513 $1 20;
#P newex 261 339 31 9109513 / 127.;
#P comment 149 84 29 9109513 Pitch;
#P number 74 152 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user dial 74 106 40 40 2308 1 0 0 159 270 1 1. 170 170 170 221 221 221 120 120 120 225 225 225 0 0 0 0 0 0;
#P message 471 125 37 9109513 size $1;
#P flonum 143 350 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 143 324 27 9109513 / 1.;
#P flonum 204 303 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 204 277 38 9109513 * 0.001;
#P user dial 149 106 40 40 2000 1 0 0 159 270 1 1. 170 170 170 221 221 221 120 120 120 225 225 225 0 0 0 0 0 0;
#P number 143 301 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 44 420 52 9109513 pack 0 0 0;
#P newex 143 276 27 9109513 !- 0;
#P number 8 154 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user dial 8 106 40 40 300 1 0 0 159 270 1 1. 170 170 170 221 221 221 120 120 120 225 225 225 0 0 0 0 0 0;
#P newex 44 239 27 9109513 int;
#P user ezdac~ 132 573 176 606 0;
#P button 318 202 19 0;
#P message 331 42 43 9109513 replace;
#P newex 331 65 72 9109513 buffer~ sample;
#P newex 44 472 31 9109513 line~;
#P message 44 446 47 9109513 $1 , $2 $3;
#P newex 105 239 27 9109513 int;
#P newex 393 90 105 9109513 info~ sample;
#P newex 44 496 64 9109513 play~ sample;
#P comment 13 83 28 9109513 Start;
#P comment 75 83 36 9109513 Length;
#P comment 298 183 70 9109513 Trigger Sample;
#P connect 13 0 14 0;
#P fasten 10 0 12 0 323 225 49 225;
#P connect 12 0 16 0;
#P connect 16 0 6 0;
#P connect 6 0 7 0;
#P fasten 7 0 3 0 49 491 49 491;
#P fasten 13 0 12 1 13 151 66 151;
#P fasten 5 0 16 1 110 288 70 288;
#P fasten 23 0 24 0 476 155 120 155 120 103 79 103;
#P connect 24 0 25 0;
#P fasten 22 0 16 2 148 373 91 373;
#P fasten 10 0 5 0 323 233 110 233;
#P fasten 25 0 5 1 79 203 127 203;
#P fasten 32 0 11 0 143 567 137 567;
#P fasten 3 0 32 0 49 528 143 528;
#P fasten 12 0 15 0 49 270 148 270;
#P fasten 15 0 17 0 148 304 148 304;
#P connect 17 0 21 0;
#P connect 21 0 22 0;
#P fasten 30 0 32 1 266 526 160 526;
#P fasten 5 0 15 1 110 267 165 267;
#P fasten 20 0 21 1 209 320 165 320;
#P fasten 32 0 11 1 143 567 171 567;
#P fasten 18 0 19 0 154 168 209 168;
#P connect 19 0 20 0;
#P fasten 31 0 27 0 238 155 266 155;
#P connect 27 0 28 0;
#P connect 28 0 29 0;
#P fasten 29 0 30 0 266 454 266 454;
#P connect 9 0 8 0;
#P connect 8 1 4 0;
#P fasten 4 6 23 0 476 116 476 116;
#P pop;

#68480
Feb 16, 2006 at 3:58pm

Hi there

I’m creating a drum machine too, I can’t figure out why the info~ object doesn’t seem to return any info of any of my samples. I only want the buffer size (in ms) returned so I can have variable decay lengths for each step, without using a fixed maximum.

Can you help?

#68481
Feb 16, 2006 at 4:42pm

I also found that info wasnt giving me the right info for the sample loaded in the buffer so I used sfinfo~ immediately from the open file dialog to get the total length of the sample.

Hope that helps.

#68482
Feb 16, 2006 at 4:52pm

Sweet! Cheers for that it works perfectly.

Another couple of questions if you have a mo, since you’re working on a drum machine too.

Having trouble getting sample-accurate timing – I know there’s a way using the phasor object. Any experience with that?

Also, how to prevent midi feedback loops – I want to have control information coming into and going out of my control surface (Behringer motorized faders) but obviously there needs to be some sort of barrier to stop the midi signal from looping. Just in case you know of anything off the top of your head, no problem if not.

Cheers!

#68483
Feb 16, 2006 at 10:16pm

No problem.

I havent used phasor~ either to trigger my samples. The drum machine I am making is part of a bigger project which has a dj player with 2 decks, drum machine and hopefully a granular synth with step sequencer.
I hope to get them all synchronised together and am attempting to do this using Tristan Jehan’s beat~ object.
The bpm info from beat~ is sent to the tempo object which defines the drum machine tempo. This sends out triggers to a matrixcrtl and the corresponding drum play~ object.
The timing of the matrixctrl and the actual playback seems to be a bit off even though there are both trigger by the tempo~ object which is odd and I am still trying to figure out why.

About midi feedback loops, I havent really looked into making my drum machine midi controllable as other parts of my project use it so cant really help you on that one, sorry.

Hope some of the info was useful.

#68484
Feb 16, 2006 at 10:32pm

For sample-accuracy you really want peek~ and poke~. Those will let
you get at the individual samples.

_Mark

#68485

You must be logged in to reply to this topic.