Phaseshaping Oscillator Algorithms for Musical Sound Synthesis
Total Page:16
File Type:pdf, Size:1020Kb
PHASESHAPING OSCILLATOR ALGORITHMS FOR MUSICAL SOUND SYNTHESIS Jari Kleimola 1, Victor Lazzarini 2, Joseph Timoney 2, and Vesa Välimäki 1 1 Department of Signal Processing and Acoustics, Aalto University, Espoo, Finland 2 Sound and Digital Music Technology Group, National University of Ireland, Maynooth, Ireland [email protected],[email protected],[email protected],[email protected] ABSTRACT where f[.] is an arbitrary nonlinear function called a wa- veshaper . The well-known classic FM synthesis equation, This paper focuses on phaseshaping techniques and their for instance, can be rewritten as a waveshaping expres- relation to classical abstract synthesis methods. Elemen- sion tary polynomial and geometric phaseshapers, such as those based on the modulo operation and linear transfor- cos [ω n + xI (n)] = c (3) ω [][]− ω mations, are investigated. They are then applied to the cos( c n)cos xI (n) sin( c n)sin xI (n) , generation of classic and novel oscillator effects by using ω nested phaseshaping compositions. New oscillator algo- where c is the carrier frequency and the waveshapers rithms introduced in this paper include single-oscillator cos(.) and sin(.) act on the sinusoidal modulation signal hard sync, triangle modulation, efficient supersaw simu- x(n) of Equation 1. lation, and sinusoidal waveshape modulation effects. The Similarly, it is possible to describe PD as a form of digital waveforms produced with phaseshaping tech- waveshaping. This is demonstrated by starting with the following expression defining a sinusoidal oscillator: niques are generally discontinuous, which leads to alias- = [ πφ ] ing artifacts. Aliasing can be effectively reduced by mod- y(n) cos 2 (n .) (4) ifying samples around each discontinuity using the pre- viously proposed polynomial bandlimited step function The function φ(n) is the normalized phase defined by (polyBLEP) method. φ(n) = [φ(n − )1 + f / f ] mod ,1 (5) 0 s 1. INTRODUCTION where f0 is the fundamental frequency, fs is the sampling rate, and x mod 1 = x – x, and x is the floor function The generation of complex musical timbres has been denoting the largest integer that is not greater than x. To approached from various angles in sound computing. One implement a PD oscillator, the phase is then applied to a elegant solution, which has provided a wide scope for nonlinear function g(x): research and implementation, has been that of distortion = { π [φ ]} (6) techniques. Within this area, various techniques have y(n) cos 2 g (n) . been put forward, such as frequency modulation (FM) [3], phase distortion (PD) [5,9], nonlinear waveshaping A linear g(x) would result in a sinusoid whose frequency [1,10,14,16], and discrete summation formulae (DSF) is transposed. However, with nonlinear g(x), the shape of [11]. These are in many cases equivalent and can be used the output waveform is modified. as alternative ways to describe and implement a given From a waveshaping perspective, Equation 4 can be algorithm, as discussed in [7]. described as a sinusoidal waveshaper acting on a complex In particular, the waveshaping method provides a input waveform s(n) = 2 πφ(n): computationally simple means to produce potentially rich = [ ] (7) spectra. Its principle is quite straightforward, starting y(n) f s(n .) with a discrete-time sinusoidal signal, This transforms the phase signal s(n) into the output signal y(n) by means of a waveshaper f(x) = cos( x). The x(n) = sin( ωn ,) (1) waveshaper can be implemented as a function or as a where ω is the angular frequency and n is the discrete lookup table that acts on the normalized value of the sample index, a complex (i.e., non-sinusoidal) spectrum phase signal. The typical phase generator producing s(n) can be obtained via a mapping such as is the unipolar modulo counter φ(n) of Equation 5, which y(n) = f [x(n ],) (2) is also a unipolar geometric non-bandlimited sawtooth wave. In this vein, Equation 6 can be seen as based on a Copyright: © 2010 Kleimola, Lazzarini, Timoney, and Välimäki. This is form of double waveshaping, where two functions, g(x) an open-access article distributed under the terms of the Creative and cos( x), are applied to an input sawtooth wave φ(n). Commons Attribution License 3.0 Unported , which permits unrestricted This is perfectly equivalent to the principle of distorting use, distribution, and reproduction in any medium, provided the orig i- the phase function φ(n) of a sinusoidal oscillator. nal authors and source are credited. In this paper, the term ‘phaseshaping’ [7] is used to [] = + (10) describe the generalization of the phase function distor- glin x(n), a 0,1 a1x(n) a0 , tion g[φ(n)]. The aim here is to investigate elementary polynomial and geometrical phaseshapers, and then dis- where a1 and a0 are the scaling and shifting factors, re- cuss their application in classic and novel oscillator algo- spectively. Assuming that x(n) is given by φ(n) – which is rithms. restricted to values between 0 and 1 – one notices that the output of glin is no longer constrained to the range [0,1], 2. ELEMENTARY PHASESHAPERS which is the expected normalized phase range of most waveshaper terminals of the shaper chain. The investigation is began by proposing two fundamental The output of glin should therefore be normalized. One phaseshaping concepts, entitled nested phaseshaping and way of doing this is to apply the mod 1 phaseshaper entity phaseshaper entities. Nested phaseshaping is related to to obtain function composition, in which the result of the inner function serves as the input to the outer function. Equa- = [] (11) y(n) mod 1o glin x(n), a 0,1 . tion 8 shows an example of nesting at three levels, ex- pressed in the basic form in Equation 8a and its equiva- The effect of this normalization is seen in Figure 2, lent shorthand notation in Equation 8b. which plots the output of Equation 11 using parameter values a = 1.5 and a = 0. The sampling rate f = 44.1 y(n) = f {g [h(x)]}, (8a) 1 0 s kHz is used in all examples of this paper. In this example, = y(n) f o g o h (x .) (8b) the modulo operation is activated first within the context For the purposes of this paper, x is assumed to be a of mod 1 (producing the full-height phase cycle) and then within the context of glin (producing the fractional phase signal which flows from the inner function towards the 1 outer ones, transforming at each step into the final shape cycle) . Parameter a1 thus controls the length of the phase given by the outmost function. The graphical representa- period (when a1 > 1) or the slope of the phase signal tion of this composition is thus a signal block diagram, (when a1 < 1). The shifting term a0 contributes to the DC similar to the one shown in Figure 1. offset of the produced phase signal. Figure 1. Graphical representation of Equation 8. It is further assumed that the source of the chain is the unipolar modulo counter φ(n) of Equation 5, and that the rightmost block is the waveshaper producing the final Figure 2. Ramp-like phase signal with a fractional phase output signal. The blocks or functions between these two period (a1 = 1.5 and a0 = 0). The fundamental frequency extremes are called phaseshapers, because they act on the is f0 = 441 Hz, as in all plots of this section. phase signal φ(n) and because the input of the final wave- 2.2 Triangular Fractional Period Phase Signals shaper is essentially a phase signal as well. Having said φ this, note that in some cases the output of the chain is the The unipolar modulo counter signal (n) can be trans- phase signal itself instead of the product of the wavesha- formed into a bipolar sawtooth waveform by applying the per. gb phaseshaper entity of Equation 9c. Then, by feeding Phaseshaper entities are frequently used phaseshapers this sawtooth waveform through the absolute value func- that have fixed predefined semantics. These include tion, a unipolar triangular signal [20] is obtained, which can be further shaped by glin and mod 1 to get phaseshaper [ ] = (9a) mod 1 x(n) x(n) mod 1 [] = {}[] (12) [ ] = (9b) g tri x(n), a 0,1 mod 1 o glin o abs gb x(n) . mod m x(n), m x(n) mod m [ ] = − (9c) Alternatively the abs{.} term of Equation 12 can be re- g b x(n) 2x(n) 1 placed with the piecewise linear triangular waveform g [x(n)] = 5.0 x(n) + ,5.0 (9d) u definition where mod 1 is the modulo-1 operation, mod m is the real- 2x, when 0 ≤ x < ,5.0 = ∈ stri (x) (13) valued modulo-m operation ( m R), gb is the bipolar 2 − 2x, when 5.0 ≤ x ≤ .1 transformation converting a unipolar signal into its bipo- lar form, and gu its opposite unipolar transformation. The fractional period phase signal produced by gtri is depicted in Figure 3, which shows that because the slope 2.1 Ramp-like Fractional Period Phase Signals of the triangle wave is two times steeper than that of a Phaseshaper entities gb and gu are linear transformations, whose general expression is given by the phaseshaper 1 Here the term phase cycle is adapted to describe the segment that takes the phase value from 0 to 1, and the term phase period to describe the total period of the modulo counter signal φ(n). sawtooth, the frequency of the phase cycle is doubled. 2.4 Tilted Triangular Fractional Period Phase Signals The phase period of gtri therefore contains two complete periods of Equation 11 and, as expected, the latter period Instead of subtracting two sawtooth waveforms from each other, subtracting two out-of-phase parabolic wave- is reversed in time.