# Calculation Methods for Score Contours

### Segments

Each contour is implemented as a collection of contiguous segments, of which segment i has four properties:

• starting time: ai
• ending time: bi
• starting value (origin): αi
• ending value (goal): βi

By contiguous I mean that the segments are listed in relative-time order so that bi coincides with ai+1. The starting time and ending time are both measured in whole notes rather than seconds. The mathematical formulae that follow will employ the variable r to indicate relative time, as distinguished from t, which indicates absolute time.

Alan Ashton's linear music code provided a model of economy for generating contours. This model makes use of the fact that the score-generating engine keeps internal track of (relative) time. Two scenarios are addressed:

• When creating a steady-state segment, all one needs to specify is the origin value. The contour existing up to the current time is truncated. One new segment is created. The segment starts at the current relative time and goes on forever. The goal value of the new segment is the same as the origin value.
• When creating a transition, one needs to specify the goal value and the transition duration, that is the period of relative time over which the transition unfolds. The existing contour value as of the current relative time is taken as the origin, and the existing contour is again truncated. Two new segments are created. The first segment effects the transition from origin to goal. The second segment holds the goal value as a steady state. It starts at (current time) + (transition period) and goes on forever.

The value vi(r) of segment i at time r may be calculated using one of three interpolation methods: discrete, linear, and exponential.

### Discrete Contours

Discrete contours are made up of segments within which the value at any time during the segment is equal to the segment's initial value.

When the calculation method is discrete, the interpolation formula is simply:

vi(r) = αi

### Linear Contours

Within a linear segment, values evolve in a manner which produces equal increments over equal durations. For example in a segment starting at time 0 with value 0 and ending at time 4 with value 10, then the values increment by 2.5 over each quarter note.

Linear interpolation has been available from sound-synthesis transcription utilities as early as the MOVE feature of Leland Smith's SCORE program, which I witnessed during 1976.

Contours which interface to MIDI controls should either be linear or spline.

The linear calculation method relies on an interpolation factor xi(r), which is calculated as:

 xi(r) = r − aibi − ai

The effect of this expression is to rescale the time axis so that xi(a) = 0, so that xi(b) = 1, and so that when r is mid-way between a and b, then xi(r) = 0.5

The interpolation formula is therefore:

vi(r) =  αi + xi(r) ∙ (βi − αi)

### Spline Contours Figure 1: Progress of a spline interpolation.

The technical name for a curve section which receives its initial direction from its predecessor and which passes along its final direction to its successor is a spline. For the present purposes, the both the initial and final curve direction should be horizontal. Put another way, The curve should progress as shown in Figure 1: the slope should increase from zero (flat) to an unsteep maximum at the mid point of the segment; it should taper back to zero as the segment completes.

I am not aware of spline interpolation being used either directly by any sound-synthesis engines or by any score-transcription utilities, but this does not mean it did not happen. I do vaguely remember spline-like techniques being applied in digital sound-editing software described by Andy Moorer of LucasFilm.

Contours which interface to MIDI controls should either be linear or spline.

The Wikipedia article on splines identifies the third order polynomial used for calculating spline values. Given the previous stipulation that the slope should be flat at the segment's starting and ending times, Wikipedia's polynomial simplifies to:

q(t)  =  3t2 − 2t3

Where t = xi(r) calculated as described above for the linear calculation method.

The interpolation formula is therefore:

vi(r) =  αi + q(xi(r)) ∙ (βi − αi)

### Exponential Contours

Within an exponential segment, values evolve in a manner which grows (or reduces) by equal ratios over equal durations. For example in a segment starting at time 0 with value 1 and ending at time 3 with value 8, then the values grow by a ratio of 2 over each quarter note.

Exponential interpolation has been available from sound-synthesis transcription utilities as early as the MOVX feature of Leland Smith's SCORE program, which I witnessed during 1976.

Exponential contours are useful in MUSIC-N style digital sound synthesis for controlling attributes such as amplitude and frequency. If you expect to export both to MIDI and to MUSIC-N, you should set up your contours as linear and employ the exponential conversion feature.

The exponential calculation method shares an interpolation factor xi(r) calculated as described above for the linear calculation method.

The interpolation formula depends upon the relationship between βi and αi:

• When βi = αi, the interpolation formula is:
vi(r) =  αi
• When βi > αi, the interpolation formula is:
vi(r) =  αi ∙ (βi/αi)xi(r)
• When βi < αi, the interpolation formula is:
vi(r) =  βi ∙ (αi/βi)[1−xi(r)]

Accelerations and ritards of tempo are felt to be most uniform when durations expand or contract by equal ratios. However to convert durations from relative time, expressed in quarter notes into absolute time, expressed in seconds, requires summing up areas underneath an exponential tempo mapping. This problem is further discussed in the next topic.

### Spline-X Contours

Spline-exponential contours are to spline contours as exponential contours are to linear contours.

The spline-exponential calculation method shares the interpolation factor xi(r) calculated as described above for the linear calculation method. It also shares the 3rd degree polynomial q(t) calculated as described above for the spline calculation method. The interpolation formula depends upon the relationship between βi and αi:

• When βi = αi, the interpolation formula is:
vi(r) =  αi
• When βi > αi, the interpolation formula is:
vi(r) =  αi ∙ (βi/αi)q(xi(r))
• When βi < αi, the interpolation formula is:
vi(r) =  βi ∙ (αi/βi)[1−q(xi(r))]

I am not aware of spline-exponential interpolation being used either directly by any sound-synthesis engines or by any score-transcription utilities.

Next topic: Tempo Calculations

 © Charles Ames Page created: 2013-10-16 Last updated: 2017-03-11