• ### Linear interpolation of inputs using \[expr\]

Hi -

what equation would one use in [expr] to interpolate between values of the inputs?

I know this can be done using tabread - boisoi kindly did this here: http://puredata.hurleur.com/sujet-2339-simple-linear-interpolation-tabread-message-audio-rates but I think it would be more elegant using an expression. Is this possible using expr?

cheers

boonier

• Posts 10 | Views 7321
• Based on boisoi's patch, it would be:

[expr \$f1*(1-\$f3)+\$f2*\$f3]

where \$f1 and \$f2 are the two numbers you interpolate between, and \$f3 is a value from 0-1 indicating where inbetween the numbers you're interpolating. It's like linear crossfading or panning.

• Ah yes, but what happens when you have more than 2 numbers?

edit- also as far as I can tell, you can't internally wrap a variable between 0 - 1 as you need to calculate the inverse of the next number....argh maths!

cheers

(01:36:25 ? go to bed man!)

boonier

• You can do a [wrap] function within [expr] by doing [expr fmod(\$f1, 1)], if that's what you mean. Could you elaborate on what you mean by using more than two values? If you're talking about indexing a list, it would probably be better to stick with [tabread], as it would be faster. And I don't think all of that could be contained within [expr]; it would have to be sorted out beforehand. But I'm not so sure that's what you mean.

By the way, I think we're actually very different time zones (though I have posted plenty of times at 1:30am here). It says you posted at 5:10:08. I mean really, what kind of musician gets up at 5 in the morning? That's sacrelige.

• HEy Maelstorm

I figured it out (after discovering fmod!) it's [expr (val[\$f1+1]*modf(\$f1)) + (val[\$f1]*(modf(\$f1)*(-1)+1))] ...then I remembered [tabread4] which basically does the above sorry for the wind-up

cheers S

boonier

• boonier,

If you're looking for linear interpolation, [tabread4] isn't the solution. It does a four-point interpolation that maps out a curve between the numbers. Look at the attached to compare yours and boisoi's.

modf is actually better for that than fmod, forgot about that one. What does val do?

• You can reference an array in [expr], in this case called val, so val[index]. SO I was on the right path with bsoisoi's? I will take a look at your patch.

I've done a audio version of mux-fade~ which just crossfades between inputs - in this case up to 8. I dunno if there's a more elegant way to do it though....probably.

cheers

boonier

• @Maelstorm said:

If you're looking for linear interpolation, [tabread4] isn't the solution.

You're totally right mate. I discovered [tabreadl] which is linear, from moonlib in pd-extended, but the [expr] version or bsoisoi version will work for pd-vanilla also.
S

boonier

• @boonier said:

You can reference an array in [expr]

Oh, nice!

Thanks!

• @boonier said:

You can reference an array in [expr],

cheers

Lovely nugget of wisdom! Didn't know that.

Use the Source.

Posts 10 | Views 7321
Internal error.

Oops! Looks like something went wrong!