[sdiy] Random Timbre Synth

Scott Gravenhorst music.maker at gte.net
Sat Aug 20 20:40:46 CEST 2011


Tom Wiltshire <tom at electricdruid.net> wrote:
>
>On 20 Aug 2011, at 17:24, Scott Gravenhorst wrote:
>
>> Joel B <onephatcat at earthlink.net> wrote:
>>> Hi Scott, 
>>> 
>>> Question about your Spline function:
>>> 
>>> y = ( x - 1 ) * x * ( x + 1 ) 
>>> 
>>> How does this get you the points in between known point x1,y1 and 
>>> known point x2,y2? I've been trying to figure out some things 
>>> like this for both a game I am working on (computing curved 
>>> attack vectors) and for a simple synthesis program I'm working on 
>>> (figuring out how to draw & scale smooth waveforms on the screen) 
>>> 
>>> How are you getting from the starting y position to the 
>>> destination y position, since that formula doesn't seem to take 
>>> into account either, but just generates a y based on an x value, 
>>> but you are somehow using this formula to connect two points on 
>>> the y axis over time (or distance) 
>> 
>> Hopefully, I won't mumble-bumble this explanation...
>> 
>> First, I restrict the cubic function's operation to go from one peak to
>> the other.  This means x is restricted to -0.58 <= x <= 0.58.  This and
>> the peak Y values are scaled so that the spline output is -1.0 < y < 1.0.
>> 
>> The x difference for the two points, (x1,y1) and (x2,y2) is calculated.
>> The x span for a full spline is 1.16, this value is divided by the x
>> difference to give an x increment value used in the point generation
>> process.
>> 
>> The original y1 and y2 values are used to calculate a y offset and a
>> sign value.  Since the Y values are pre-adjusted to be forced
>> symmetrical about the x axis, the offset is used to restore their
>> original positions.  The sign value is used to flip the spline.
>
>Ok, so can I check that I understand this?
>
>You're using a cubic function that starts bottom-left, comes up, 
>passes through x=-1, curves back down through x=y=0, and then 
>(symmetrically) curves back up through x=1 before heading off to 
>the top-right (I checked it in a graphing program). But you're 
>only using the section between X=-0.58 and x=0.58, which looks 
>pretty much like the downhill right hand side of a raised cosine 
>curve. Mathematically not very similar, but visually it's close, 
>and it'd serve the same purpose. Presumably it has the same 
>property as the cosine that the slope is zero at the given 
>points. This is good because it hides the joins! 

Yes, that's correct.  The ends of the splines connect with pretty much no "corners" due to the fact
that at -0.58 and +0.58 (approximately), the slope is zero.  And because the first and last points
are forced to y=0, the waveform wraps without a transient.

>So what you're doing between the random point is basically an alternative cosine interp?

Yes.  Offset and flipped when necessary to preserve the original random points' y values.

>Or does it involve more than just two points?

Only 2 points are used to generate each spline.  Each pair of points is connected with a cubic
spline.  So if there are 5 randomly generated points, there are 4 splines computed to connect them.

I had thought about using a sine function mapped into a RAM as a lookup table, but I wanted to
preserve as much RAM as possible for a delay effect.  The cubic function takes only 4 clocks to
compute and uses an already instantiated multiplier.  As you wrote, it looks very similar to the
sine from -pi/2 to +pi/2.

-- ScottG
________________________________________________________________________
-- Scott Gravenhorst
-- FPGA MIDI Synthesizer Information: 
   jovianpyx.dyndns.org:8080/public/FPGA_synth/
-- FatMan: 
   jovianpyx.dyndns.org:8080/public/fatman/
-- NonFatMan: 
   jovianpyx.dyndns.org:8080/public/electronics/
-- When the going gets tough, the tough use the command line.




More information about the Synth-diy mailing list