Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ABSTRACT 0 (a)
Level [dB]
One of the building blocks of virtual analog synthesizers is −50
Level [dB]
would result from a trivial modulo-counter based imple-
−50
mentation is reduced. Until now, the computationally most
efficient oscillator algorithm with reduced aliasing was the −100
0 0.5 1 1.5 2 2.5
Polynomial Transition Regions (PTR) method. This paper Frequency [kHz] x 10
4
pmax
AT p[n]=p0 AT
pmax
p[n-0.5] AT p[n-0.5]
p[n-1]
p[n+1] p[n-1]
y[n]
p[n+0.5] p[n+0.5]
pmin
p[n] pmin
Figure 4. Correction of the sawtooth signal. During the
derivation the half-sample delayed signal (light dots) is
used instead of the trivial signal (dark dots). p[n] is cor- Figure 5. EPTR algorithm of the sawtooth signal.
rected to the desired value (dashed dot).
4.2.2 The EPTR sawtooth wave algorithm
1. The sample is before the discontinuity (p0 > pmax − The PTR algorithm assumes that the trivial sawtooth signal
AT ), as in Fig. 4 is given, that is, the trivial signal generation and correct-
According to Section 4.1 the calculation must be applied ing the samples in the transition region are handled sepa-
using the adjacent samples at half sample distance from the rately [11]. If we were doing the same, then two branch op-
output sample. The trivial sample has a value of p[n] = p0 , erations would be required: one for detecting the jump of
as seen in Fig. 4. The previous sample p[n − 0.5] = p0 − the trivial signal and one for finding the transition region.
AT , the next sample would be p0 +AT but it is higher than However, a computationally simpler algorithm can be re-
the maximum value, so p[n + 0.5] = p0 + AT − (pmax − alized by merging the trivial signal generation and sample
pmin ). Applying the DPW algorithm leads to the desired correction.
output: A further advantage of this choice is that since the triv-
ial signal is generated by us, we are able to run the trivial
counter even over pmax without forcing it to jump and ap-
(p[n + 0.5])2 − (p[n − 0.5])2
yA [n] = = ply the correction using that value. Indeed, substituting
4AT
p + 2 into (6) leads to (4). Therefore, there is no need
(p0 + AT + pmin − pmax )2 − (p0 − AT )2
= . to check whether the sample to be corrected is before or
4AT after the discontinuity and the two cases can be handled
(3)
in the same way. When the transition region is detected,
For a sawtooth ranging from −1 to 1, we have A = 1, the corrected output sample is computed, and then the triv-
pmax = 1, and pmin = −1. In this special case the calcu- ial signal jumps, while the relative position of the sample
lations lead to compared to the transition is irrelevant. This is shown in
Fig. 5.
p0 1 The next source code shows how the algorithm can be
y[n] = p0 − + − 1. (4) programmed to generate a sawtooth signal ranging from -1
T T
to 1.
2. The sample is after the discontinuity (p0 < pmin +AT )
The next sample is p[n + 0.5] = p0 + AT . The previous p = p + 2∗T ;
sample can be found before the discontinuity (since p0 − if p > 1 − T
AT < pmin ), so it has a value of p[n − 0.5] = p0 − AT + y = correct (p );
(pmax − pmin ). p = p − 2;
else
y = p;
(p[n + 0.5])2 − (p[n − 0.5])2
yB [n] = The function correct(p) is responsible for correcting the
4AT
(p0 + AT )2 − (p0 − AT + pmax − pmin )2 sample in the transition region. For the usual ±1 sawtooth
= . waveform we simply use (4):
4AT
(5) p 1
correct(p) = p − + − 1. (7)
For the usual sawtooth signal A = 1, pmax = 1 and T T
pmin = −1. In this special case the calculations lead to For the general case, see Table 1.
Note that the result would be the same if the trivial sig-
p0 1 nal first jumped, then (6) was applied for correction. The
y[n] = p0 − − + 1. (6)
T T resulting waveform is equivalent to the signal generated
region A, pmax , pmin (general case) A = 1, pmax = 1, pmin = −1
linear region p p
pmin −pmax pmin −pmax (pmin −pmax )2 p 1
correct(p) p+ 2AT p + 2 + 4AT p− T + T −1
1 transition region
(a)
0
AT
−1 pmax
10 20 30
Sample Number
40 50 AT
−11
x 10
1 (b)
−1 BT
10 20 30 40 50 pmin
Sample Number
BT
Level [dB]
0 (c)
0 (d)
which are at half sample distance from the output sample.
−50 When the sample to be corrected is before the maximum
−100 peak (p0 > pmax − AT ), the two adjacent values used are
0 0.5 1 1.5 2 2.5 p[n − 0.5] = p0 − AT and p[n + 0.5] = pmax + BT −
Frequency [kHz] 4 (pmax − p0 ) · B/A. The differentiation and scaling gives
x 10
((p[n + 0.5])2 − p2max )/B − ((p[n − 0.5])2 − p2max )/A
Figure 6. The DPW and EPTR sawtooth waveforms (a) =
4T
and their difference (b), and the spectrum of the signal gen-
erated with the DPW (c) and EPTR (d) algorithms. = a2 p20 + a1 p0 + a0 (8)
Level [dB]
correctMax(p) a2 p2 + a1 p + a0
−50
correctMin(p) b2 p2 + b1 p + b0
−100
0 0.5 1 1.5 2 2.5
Frequency [kHz] x 10
4
Level [dB]
4(A−1)T
AT (A+B)+pmax (A−B) 2AT −4T +2
a1 2A2 T 4(A−1)T −50
(B−A)(AT −pmax )2 −(AT −1)2
a0 4A2 T 4T (A−1) −100
A−B −1 0 0.5 1 1.5 2 2.5
b2 4B 2 T 4(B+1)T Frequency [kHz] x 10
4
Level [dB]
(A−B)(BT −pmin )2 −(BT +1)2
b0 4B 2 T 4T (B+1) −50
−1 y = correctMin (p ) ;
10 20 30 40 50
Sample Number p = −1 + ( p + 1 ) ∗A / B ;
dir = 1;
Figure 8. The PTR (gray) and the EPTR (black) asymmet- else / / linear region
ric triangle waveforms. y = p;
The correcting functions can be found in Table 2. First
the counting direction must be determined, then the value
1/T = fs /f0 . This is not equivalent to the sawtooth signal
of p is checked. When p is in the transition region, the
in which the gradient is infinite, thus this case should be
corrected output sample is computed, the trivial counter is
handled separately. When the trivial signal has a value of
updated, and finally the counting direction is changed. If it
p[n] = p0 before the maximum peak, after it the value is
is not in the transition region, the output simply equals the
p[n + 1] = p0 + pmin (1 − A/B) − pmax (1 − A/B). Since
trivial counter y = p. The generated signal is equivalent to
both of the adjacent samples are on linear sections with the
the DPW and PTR versions (see Fig. 8 and 9).
same gradient, the calculation can be performed similarly
to the sawtooth waveform. The previous code assumed that the values of |A| and |B|
are not higher than fs /f0 , so there is no region that fits be-
4.3.2 The EPTR asymmetric triangle wave algorithm tween two samples. Although it is also possible to imple-
ment triangle waveforms with high gradient as discussed at
Figure 7 explains the algorithm for generating an asym-
the end of Sec. 4.3.1, it would result in a significantly more
metric triangle signal. Similarly to the sawtooth signal, the
complicated algorithm. The allowed highest gradient case
trivial waveform generation and the corrections are merged,
is close enough to the sawtooth waveform, therefore imple-
thus checking whether the trivial generator is in the transi-
menting the extra operations is not rewarding. Figure 10
tion region is sufficient. The next code segment shows the
shows the spectrum of a sawtooth with an infinitely sharp
implementation of the algorithm for a triangle waveform
transition (a) and with a transition that lasts one sampling
ranging from -1 to 1, with variable symmetry.
instant (b). The only drawback of limiting the gradient is
i f d i r == 1 / / c o u n t i n g up ? a slight attenuation at high frequencies, on the other hand,
p = p + 2∗A∗T ; the aliasing is reduced, since now we are correcting two
i f p > 1 − A∗T samples around the transition. So the asymmetric triangle
/ / t r a n s i t i o n region ? with a one sample-time transition can be safely used in-
y = correctMax ( p ) ; stead of the sawtooth signal. However, if there is still a
p = 1 + ( p − 1 ) ∗B / A ; need for the special case, the algorithm can be developed
d i r = −1; according to Sec. 4.3.1.
else / / linear region
y = p;
5. COMPARISON
else / / c o u n t i n g down
p = p + 2∗B∗T ; The advantage of the EPTR method over PTR is the re-
i f p < −1 − B∗T duced computational load. For providing a fair comparison
/ / t r a n s i t i o n region ? we merged the trivial signal generation and the correction
0 (a) mentation was also presented, allowing continuous tran-
Level [dB] sition between symmetric triangle and sawtooth signals.
−50
Future research includes the extension of the algorithm to
−100
higher orders, and to arbitrary waveforms composed of line
0 0.5 1 1.5 2 2.5 segments (e.g., trapezoidal waves).
Frequency [kHz] x 10
4
0 (b) Acknowledgments
Level [dB]
−50 The work of Balázs Bank has been supported by the Bolyai
Scholarship of the Hungarian Academy of Sciences.
−100
0 0.5 1 1.5 2 2.5 The authors are thankful to Prof. Vesa Välimäki for his
Frequency [kHz] x 10
4
valuable comments.
also for the PTR algorithm, although [11] and the adher- [4] T. Stilson and J. Smith, “Alias-free digital synthesis
ent source codes [13] were handling them separately. Ta- of classic analog waveforms,” in in Proc. Interna-
ble 3 compares the two algorithms in operations per sample tional Computer Music Conference, Hong Kong, Au-
while generating sawtooth and asymmetric triangle wave- gust 1996, pp. 332–335.
forms.
[5] S. Tassart, “Band-limited impulse train generation us-
The PTR algorithm uses an addition operation to incre-
ing sampled infinite impulse responses of analog fil-
ment the trivial counter. Then with a branch operation it
ters,” IEEE Transactions on Audio, Speech, and Lan-
decides whether the current sample is in the linear or the
guage Processing, vol. 21, no. 3, pp. 488–497, March
transition region. Finally, in the linear region an addition
2013.
for the offset is applied and in the transition region a mul-
tiplication and an addition is necessary. When producing [6] E. Brandt, “Hard sync without aliasing,” in Proc. Inter-
a sawtooth waveform with the EPTR algorithm, using the national Computer Music Conference, Havana, Cuba,
shifted trivial signal eliminates the addition operation in September 2001, pp. 365–368.
the linear region. Similarly, only the addition operation of
the trivial counter is needed in the linear region during the [7] V. Välimäki, J. Pekonen, and J. Nam, “Perceptually in-
asymmetric triangle signal generation. formed synthesis of bandlimited classical waveforms
The resulting waveforms generated with the two algo- using integrated polynomial interpolation,” Journal of
rithms have the same spectrum, as we have seen in Sec. 4. the Acoustical Society of America, vol. 131, no. 1, pp.
974–986, January 2012.
6. CONCLUSIONS [8] J. Lane, D. Hoory, E. Martinez, and P. Wang, “Mod-
eling analog synthesis with DSPs,” Computer Music
This paper has proposed a new version of the PTR algo-
Journal, vol. 21, no. 4, pp. 23–41, Winter 1997.
rithm. The Efficient Polynomial Transition Regions Al-
gorithm requires around 30% lower number of operations [9] V. Välimäki, “Discrete-time synthesis of the sawtooth
compared to the PTR algorithm, while results in exactly waveform with reduced aliasing,” IEEE Signal Pro-
the same waveform as that of the DPW and PTR algo- cessing Letters, vol. 12, no. 3, pp. 214–217, March
rithms. Thus, it is the most efficient alias-reduced algo- 2005.
rithm up to date, making it an ideal choice for systems with
low computational power requirements. In addition, the [10] V. Välimäki, J. Nam, J. O. Smith, and J. S. Abel,
paper has extended the DPW algorithm for generating tri- “Alias-suppressed oscillators based on differentiated
angle waves with variable symmetry, and its EPTR imple- polynomial waveforms,” IEEE Transactions on Audio,
Speech, and Language Processing, vol. 18, no. 4, pp.
786–798, May 2010.
[11] J. Kleimola and V. Välimäki, “Reducing aliasing from
synthetic audio signals using polynomial transition re-
gions,” IEEE Signal Processing Letters, vol. 19, no. 2,
pp. 67–70, February 2012.
[12] “Moog Slim Phatty user’s manual,” Moog Music,
Inc., 2010, URL: http://www.moogmusic.com/sites/
default/files/slim phatty users manual.pdf.
[13] J. Kleimola and V. Välimäki, “Polynomial Tran-
sition Regions [Online],” November 2011, URL:
http://www.acoustics.hut.fi/go/spl-ptr.