Forums > MaxMSP

time stretching, yet again


7oi
February 18, 2008 | 12:46 pm

I know there’s been some discussion about time stretching samples and all, since I’ve searched the forum for it, but what I wanted to know was what those of you who’ve tried various ways prefer.
Which method has proven succesful for you guys? I have a stack of externals that say they do the trick, and some tips that don’t need externals, like phase-vocoding…
So what’ll it be? Which one’s good and not too processor greedy?


February 18, 2008 | 2:58 pm



7oi
February 18, 2008 | 3:33 pm

yeah, i saw a post of that somewhere. how is that working out for you? i’ve been thinking about many instances of something like that, so how does it treat the processor?


February 18, 2008 | 5:26 pm


February 18, 2008 | 6:13 pm

I use a combo of play~ and gizmo~ to do time change and pitch shift in one.

The idea is this…
I have a buffer with a sound loaded (mono in this case)
I want to play any segment of that buffer with the following specified:
final duration (the stretch)
segment start and end in buffer
transposition interval
play~ alters the duration and transposes the segment
That transposition is "remembered" by computing the ratio
between the output duration and the segment duration.
The remembered ratio is multiplied by the output transposition
ratio so one gizmo~ can correct the effect of the stretch
and transpose to the output pitch.

Here is what I put into a poly~
I’m sorry I don’t have complete example because my wrapper for this includes
a lot of my own objects that I have not yet posted.

Save this as play+gizmo~ and I’ll try to put together a help file.

#P window setfont "Sans Serif" 9.;
#P window linecount 4;
#P newex 354 229 85 196617 expr ((440. * exp(.057762265 * $f1))* 0.002273);
#P window linecount 2;
#P comment 235 119 59 196617 end sample in ms;
#P window linecount 1;
#N out~ 1;
#P newobj 63 534 39 196617 out~ 1;
#P newex 23 457 21 196617 t 0;
#P newex 63 497 35 196617 *~ 1.;
#P newex 627 178 22 196617 b 1;
#P newex 504 426 48 196617 loadbang;
#P window setfont "Fixedwidth Serif" 10.;
#P message 560 460 62 1441802 mute 1 , 0;
#P message 627 460 63 1441802 mute 0 , 1;
#P newex 560 491 65 1441802 thispoly~;
#P window setfont "Sans Serif" 9.;
#P newex 63 154 499 196617 unpack 0. 0 0 0. 0. sample;
#N in 1;
#P newobj 63 21 25 196617 in 1;
#P newex 547 246 62 196617 prepend set;
#P newex 266 416 29 196617 * 1.;
#P newex 287 222 48 196617 pack 0 0;
#P newex 63 456 135 196617 pfft~ gizmo_loadme 1024 2;
#P newex 266 377 31 196617 / 1.;
#P message 63 313 56 196617 $2 , $3 $1;
#P newex 63 284 57 196617 pack 0 0 0;
#P newex 287 272 30 196617 !-;
#P newex 63 415 82 196617 play~ $0sample;
#P newex 63 334 32 196617 line~;
#P window linecount 2;
#P comment 74 118 61 196617 play dur in ms;
#P window linecount 3;
#P comment 326 113 67 196617 transposition interval in semitones;
#P window linecount 2;
#P comment 144 119 65 196617 start sample in ms;
#P window linecount 1;
#P comment 430 128 53 196617 amplitude;
#P window linecount 2;
#P comment 542 121 42 196617 buffer name;
#P window linecount 1;
#P comment 116 219 100 196617 convert duration ms;
#P window linecount 2;
#P comment 369 194 50 196617 interval to ratio;
#P window linecount 4;
#P comment 299 297 52 196617 end-start for play sample dur;
#P window linecount 3;
#P comment 302 413 69 196617 final transposition ratio;
#P window linecount 2;
#P comment 497 458 49 196617 mute at birth;
#P fasten 10 1 28 0 90 355 28 355;
#P connect 20 0 21 0;
#P connect 21 0 13 0;
#P connect 13 0 14 0;
#P connect 14 0 10 0;
#P connect 10 0 11 0;
#P fasten 19 0 11 0 552 400 68 400;
#P connect 11 0 16 0;
#P connect 16 0 27 0;
#P connect 27 0 29 0;
#P fasten 17 0 13 1 292 260 91 260;
#P fasten 21 4 27 1 456 480 93 480;
#P fasten 28 0 27 1 28 480 93 480;
#P fasten 18 0 16 1 271 442 193 442;
#P fasten 21 0 15 0 68 244 271 244;
#P connect 15 0 18 0;
#P fasten 31 0 18 1 359 407 290 407;
#P fasten 21 1 17 0 165 210 292 210;
#P connect 17 0 12 0;
#P connect 12 0 15 1;
#P fasten 21 2 17 1 262 204 330 204;
#P fasten 21 3 31 0 359 219 359 219;
#P connect 21 5 19 0;
#P fasten 10 1 24 0 90 366 565 366;
#P connect 25 0 24 0;
#P fasten 23 0 22 0 632 484 565 484;
#P fasten 24 0 22 0 565 478 565 478;
#P fasten 20 0 26 0 68 104 632 104;
#P connect 26 0 23 0;
#P window clipboard copycount 32;

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 18, 2008 | 6:46 pm

Here’s play+gizmo~ modified to allow reverse playing along with a simple
help file.

Save this as play+gizmo~

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 287 342 23 196617 abs;
#P window linecount 4;
#P newex 354 229 85 196617 expr ((440. * exp(.057762265 * $f1))* 0.002273);
#P window linecount 2;
#P comment 235 119 59 196617 end sample in ms;
#P window linecount 1;
#N out~ 1;
#P newobj 63 534 39 196617 out~ 1;
#P newex 23 457 21 196617 t 0;
#P newex 63 497 35 196617 *~ 1.;
#P newex 627 178 22 196617 b 1;
#P newex 504 426 48 196617 loadbang;
#P window setfont "Fixedwidth Serif" 10.;
#P message 560 460 62 1441802 mute 1 , 0;
#P message 627 460 63 1441802 mute 0 , 1;
#P newex 560 491 65 1441802 thispoly~;
#P window setfont "Sans Serif" 9.;
#P newex 63 154 499 196617 unpack 0. 0 0 0. 0. sample;
#N in 1;
#P newobj 63 21 25 196617 in 1;
#P newex 547 246 62 196617 prepend set;
#P newex 266 416 29 196617 * 1.;
#P newex 287 222 48 196617 pack 0 0;
#P newex 63 456 135 196617 pfft~ gizmo_loadme 1024 2;
#P newex 266 377 31 196617 / 1.;
#P message 63 313 56 196617 $2 , $3 $1;
#P newex 63 284 57 196617 pack 0 0 0;
#P newex 287 261 30 196617 !-;
#P newex 63 415 82 196617 play~ $0sample;
#P newex 63 334 32 196617 line~;
#P window linecount 2;
#P comment 74 118 61 196617 play dur in ms;
#P window linecount 3;
#P comment 326 113 67 196617 transposition interval in semitones;
#P window linecount 2;
#P comment 144 119 65 196617 start sample in ms;
#P window linecount 1;
#P comment 430 128 53 196617 amplitude;
#P window linecount 2;
#P comment 542 121 42 196617 buffer name;
#P window linecount 1;
#P comment 116 219 100 196617 convert duration ms;
#P window linecount 2;
#P comment 369 194 50 196617 interval to ratio;
#P window linecount 4;
#P comment 299 286 52 196617 end-start for play sample dur;
#P window linecount 3;
#P comment 302 413 69 196617 final transposition ratio;
#P window linecount 2;
#P comment 497 458 49 196617 mute at birth;
#P connect 26 0 23 0;
#P connect 20 0 21 0;
#P fasten 20 0 26 0 68 104 632 104;
#P fasten 23 0 22 0 632 484 565 484;
#P fasten 24 0 22 0 565 478 565 478;
#P fasten 10 1 28 0 90 355 28 355;
#P fasten 10 1 24 0 90 366 565 366;
#P connect 25 0 24 0;
#P connect 21 5 19 0;
#P fasten 21 3 31 0 359 219 359 219;
#P fasten 21 2 17 1 262 204 330 204;
#P connect 32 0 15 1;
#P connect 12 0 32 0;
#P fasten 17 0 13 1 292 250 91 250;
#P connect 17 0 12 0;
#P fasten 21 1 17 0 165 210 292 210;
#P fasten 31 0 18 1 359 407 290 407;
#P connect 15 0 18 0;
#P connect 21 0 13 0;
#P fasten 21 0 15 0 68 244 271 244;
#P fasten 18 0 16 1 271 442 193 442;
#P fasten 21 4 27 1 456 480 93 480;
#P fasten 28 0 27 1 28 480 93 480;
#P connect 27 0 29 0;
#P connect 16 0 27 0;
#P connect 11 0 16 0;
#P connect 10 0 11 0;
#P fasten 19 0 11 0 552 400 68 400;
#P connect 14 0 10 0;
#P connect 13 0 14 0;
#P window clipboard copycount 33;

And this as play+gizmo.help in the same folder.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 67 140 27 196617 * 6;
#P newex 93 89 38 196617 * 500;
#P newex 66 117 37 196617 pipe 0;
#P message 65 167 103 196617 2000 0 2000 $1 0.1;
#P button 36 41 15 0;
#P newex 36 65 41 196617 uzi 3 0;
#P message 256 237 106 196617 2000 0 2000 2.5 0.1;
#P window linecount 2;
#P comment 256 210 109 196617 forward + 2.53 semitones;
#P window linecount 1;
#P message 256 184 114 196617 20000 0 2000 -12 0.1;
#P comment 256 163 134 196617 stretch x 5 – 12 semitones;
#P comment 256 79 61 196617 backward;
#P message 256 141 106 196617 20000 0 2000 0. 0.1;
#P message 256 98 100 196617 2000 2000 0 0. 0.1;
#P message 145 377 179 196617 note 2000 0 2000 12. 0.1 sample;
#P newex 146 351 62 196617 prepend set;
#P message 256 58 94 196617 2000 0 2000 0. 0.1;
#P newex 127 274 27 196617 t b l;
#P number 589 137 88 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user ezdac~ 122 475 166 508 0;
#P message 404 55 43 196617 replace;
#P newex 511 110 105 196617 info~ sample;
#P newex 404 82 117 196617 buffer~ sample talk.aiff;
#P newex 125 319 143 196617 pack note 0 0 0 0. 0.25 sample;
#P newex 125 414 104 196617 poly~ play+gizmo~ 8;
#P comment 256 36 61 196617 forward;
#P comment 256 120 100 196617 stretch x 5;
#P window linecount 2;
#P comment 91 50 44 196617 Three’s a crowd;
#P connect 22 0 21 0;
#P connect 26 0 23 0;
#P connect 21 2 24 0;
#P connect 24 0 26 0;
#P connect 21 2 25 0;
#P connect 25 0 24 1;
#P connect 3 0 8 0;
#P connect 10 0 4 0;
#P connect 4 0 3 0;
#P connect 23 0 10 0;
#P connect 20 0 10 0;
#P connect 18 0 10 0;
#P connect 15 0 10 0;
#P connect 14 0 10 0;
#P connect 11 0 10 0;
#P connect 12 0 13 0;
#P connect 4 0 12 0;
#P connect 10 1 4 1;
#P connect 3 0 8 1;
#P connect 7 0 5 0;
#P connect 5 1 6 0;
#P connect 6 6 9 0;
#P window clipboard copycount 27;

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 18, 2008 | 9:33 pm

Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 19:13
—————————————————-
> I use a combo of play~ and gizmo~ to do time change and pitch shift in one.
>

But you shouldn’t forget to mention that this solution always has an inherent latency, depending on the window size. If you make the window size small, the shifting/stretching quality is less, if you make the window size big, the latency is larger.

Mattijs


February 18, 2008 | 9:45 pm

Yes, latency is an issue. I love to hear about alternate methods of
accomplishing this.

On 2/18/08 4:33 PM, "Mattijs Kneppers" wrote:

>
> Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 19:13
> —————————————————-
>> I use a combo of play~ and gizmo~ to do time change and pitch shift in one.
>>
>
> But you shouldn’t forget to mention that this solution always has an inherent
> latency, depending on the window size. If you make the window size small, the
> shifting/stretching quality is less, if you make the window size big, the
> latency is larger.
>
> Mattijs

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 18, 2008 | 9:56 pm

Just did a comparison. I changed gizmo parameters from 1024 2 to 4096 4.
The quality increased significantly but I am confused about latency. In my
application it would be an issue if there was a delay in the start of a
sound relative to the time I activate it. I don’t hear a delay with either
setting. CPU load seems to double with 4096 4. I was expecting a factor of
4-8.

On 2/18/08 4:33 PM, "Mattijs Kneppers" wrote:

>
> Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 19:13
> —————————————————-
>> I use a combo of play~ and gizmo~ to do time change and pitch shift in one.
>>
>
> But you shouldn’t forget to mention that this solution always has an inherent
> latency, depending on the window size. If you make the window size small, the
> shifting/stretching quality is less, if you make the window size big, the
> latency is larger.
>
> Mattijs

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 18, 2008 | 10:09 pm

Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 22:56
—————————————————-
> Just did a comparison. I changed gizmo parameters from 1024 2 to 4096 4.
> The quality increased significantly but I am confused about latency. In my
> application it would be an issue if there was a delay in the start of a
> sound relative to the time I activate it. I don’t hear a delay with either
> setting.

Did you try to route the original sound together with the gizmoed one to the output? For me that illustrates the latency best.

The only alternative I know is granular synthesis, which has no latency. But as far as I know no one succeeded to make a real-time granular synthesis patch in max that -doesn’t- have artifacts for a fair shifting/stretching range, like for example Ableton Live.

Mattijs


February 18, 2008 | 10:48 pm

For my application, I am using only the processed sound. When I do use the
original it still goes through with "do nothing" parameters – 100% time
scale and transpose interval of 0 semitones.

However, I will run your suggested test in case this does become an issue
for me at some point.

On 2/18/08 5:09 PM, "Mattijs Kneppers" wrote:

>
> Quote: Gary Lee Nelson wrote on Mon, 18 February 2008 22:56
> —————————————————-
>> Just did a comparison. I changed gizmo parameters from 1024 2 to 4096 4.
>> The quality increased significantly but I am confused about latency. In my
>> application it would be an issue if there was a delay in the start of a
>> sound relative to the time I activate it. I don’t hear a delay with either
>> setting.
>
> Did you try to route the original sound together with the gizmoed one to the
> output? For me that illustrates the latency best.
>
> The only alternative I know is granular synthesis, which has no latency. But
> as far as I know no one succeeded to make a real-time granular synthesis patch
> in max that -doesn’t- have artifacts for a fair shifting/stretching range,
> like for example Ableton Live.
>
> Mattijs

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson



7oi
February 20, 2008 | 9:50 am

Cheers for the replies! They’ve given me a bit more insight into the whole time stretching deal. I also tried out the phase vocoding. I haven’t tried it fully, but how would around 6-7 of those work with the frame size set at 1024 samples and overlap at, say, 4, like in the nice patch up on the cycling website? Am I asking for a crashing program there?


February 21, 2008 | 12:27 pm

> Am I asking for a crashing program there?

No, that should work perfectly well..

Mattijs


Viewing 13 posts - 1 through 13 (of 13 total)