|
Synthesizer.Basic.Wave | Portability | requires multi-parameter type classes | Stability | provisional | Maintainer | synthesizer@henning-thielemann.de |
|
|
|
|
|
Description |
Basic waveforms
If you want to use parametrized waves with two parameters
then zip your parameter signals and apply uncurry to the wave function.
|
|
Synopsis |
|
newtype T t y = Cons {} | | fromFunction :: (t -> y) -> T t y | | raise :: C y => y -> T t y -> T t y | | amplify :: C y => y -> T t y -> T t y | | distort :: (y -> z) -> T t y -> T t z | | overtone :: (C t, C n) => n -> T t y -> T t y | | apply :: T t y -> T t -> y | | phaseOffset :: C a => T a b -> a -> T a b | | sine :: C a => T a a | | cosine :: C a => T a a | | helix :: C a => T a (T a) | | fastSine2 :: (Ord a, C a) => T a a | | fastSine4 :: (Ord a, C a) => T a a | | saw :: C a => T a a | | sawCos :: (C a, C a) => T a a | | sawComplex :: (Power a, C a) => T a (T a) | | square :: (Ord a, C a) => T a a | | squareCos :: (C a, C a) => T a a | | squareComplex :: (Power a, C a) => T a (T a) | | triangle :: (Ord a, C a) => T a a | | truncOddCosine :: C a => Int -> T a a | | truncOddTriangle :: C a => Int -> T a a | | truncCosine :: C a => a -> T a a | | truncTriangle :: C a => a -> T a a | | powerNormed :: (C a, C a) => a -> T a a | | power01Normed :: (C a, C a) => a -> a -> a | | powerSigned :: (C a, C a) => a -> a -> a | | logitSaw :: C a => a -> T a a | | logitSine :: C a => a -> T a a | | sineSquare :: (C a, C a) => a -> T a a | | piecewiseParabolaSaw :: (C a, Ord a) => a -> T a a | | piecewiseSineSaw :: (C a, Ord a) => a -> T a a | | sineSawSmooth :: C a => a -> T a a | | sineSawSharp :: C a => a -> T a a | | affineComb :: C a => a -> (a, a) -> a | | sawPike :: (Ord a, C a) => a -> T a a | | trianglePike :: (C a, C a) => a -> T a a | | trianglePikeShift :: (C a, C a) => a -> a -> T a a | | squarePike :: C a => a -> T a a | | squarePikeShift :: C a => a -> a -> T a a | | squareAsymmetric :: (Ord a, C a) => a -> T a a | | squareBalanced :: (Ord a, C a) => a -> T a a | | triangleAsymmetric :: (Ord a, C a) => a -> T a a | | trapezoid :: (C a, C a) => a -> T a a | | trapezoidAsymmetric :: (C a, C a) => a -> a -> T a a | | trapezoidBalanced :: (C a, C a) => a -> a -> T a a | | trapezoidSkew :: (Ord a, C a) => a -> T a a | | data Harmonic a = Harmonic {} | | harmonic :: T a -> a -> Harmonic a | | composedHarmonics :: C a => [Harmonic a] -> T a a |
|
|
|
Definition and construction
|
|
|
Constructors | | Instances | C a y => C a (T t y) | C y => C (T t y) |
|
|
|
fromFunction :: (t -> y) -> T t y | Source |
|
|
Operations on waves
|
|
|
|
|
|
distort :: (y -> z) -> T t y -> T t z | Source |
|
|
overtone :: (C t, C n) => n -> T t y -> T t y | Source |
|
|
|
|
phaseOffset :: C a => T a b -> a -> T a b | Source |
|
Turn an unparametrized waveform into a parametrized one,
where the parameter is a phase offset.
This way you express a phase modulated oscillator
using a shape modulated oscillator.
|
|
Examples
|
|
unparameterized
|
|
|
map a phase to value of a sine wave
|
|
|
|
|
|
|
Approximation of sine by parabolas.
Surprisingly not really faster than sine.
|
|
|
Approximation of sine by fourth order polynomials.
|
|
|
saw tooth,
it's a ramp down in order to have a positive coefficient for the first partial sine
|
|
|
This wave has the same absolute Fourier coefficients as saw
but the partial waves are shifted by 90 degree.
That is, it is the Hilbert transform of the saw wave.
The formula is derived from sawComplex.
|
|
|
sawCos + i*saw This is an analytic function and thus it may be used for frequency shifting.
The formula can be derived from the power series of the logarithm function.
|
|
|
square
|
|
|
This wave has the same absolute Fourier coefficients as square
but the partial waves are shifted by 90 degree.
That is, it is the Hilbert transform of the saw wave.
|
|
|
squareCos + i*square This is an analytic function and thus it may be used for frequency shifting.
The formula can be derived from the power series of the area tangens function.
|
|
|
triangle
|
|
discretely parameterized
|
|
|
A truncated cosine. This has rich overtones.
|
|
|
For parameter zero this is saw.
|
|
continuously parameterized
|
|
|
A truncated cosine plus a ramp that guarantees a bump of high 2 at the boundaries.
It is truncCosine (2 * fromIntegral n + 0.5) == truncOddCosine (2*n)
|
|
truncTriangle :: C a => a -> T a a | Source |
|
|
powerNormed :: (C a, C a) => a -> T a a | Source |
|
Power function.
Roughly the map x p -> x**p
but retains the sign of x and
normalizes the mapping over [-1,1] to L2 norm of 1.
|
|
power01Normed :: (C a, C a) => a -> a -> a | Source |
|
auxiliary
|
|
powerSigned :: (C a, C a) => a -> a -> a | Source |
|
auxiliary
|
|
|
Tangens hyperbolicus allows interpolation
between some kind of saw tooth and square wave.
In principle it is not necessary
because you can distort a saw tooth oscillation by map tanh.
|
|
|
Tangens hyperbolicus of a sine allows interpolation
between some kind of sine and square wave.
In principle it is not necessary
because you can distort a square oscillation by map tanh.
|
|
|
|
|
|
:: (C a, Ord a) | | => a | 0 for fastSine2, 1 for saw
| -> T a a | | Interpolation between fastSine2 and saw.
We just shrink the parabola towards the borders
and insert a linear curve such that its slope matches the one of the parabola.
|
|
|
|
:: (C a, Ord a) | | => a | 0 for sine, 1 for saw
| -> T a a | | Interpolation between sine and saw.
We just shrink the sine towards the borders
and insert a linear curve such that its slope matches the one of the sine.
|
|
|
|
:: C a | | => a | 0 for sine, 1 for saw
| -> T a a | | Interpolation between sine and saw
with smooth intermediate shapes but no perfect saw.
|
|
|
|
:: C a | | => a | 0 for sine, 1 for saw
| -> T a a | | Interpolation between sine and saw
with perfect saw, but sharp intermediate shapes.
|
|
|
affineComb :: C a => a -> (a, a) -> a | Source |
|
|
|
:: (Ord a, C a) | | => a | pike width ranging from 0 to 1, 1 yields saw
| -> T a a | | saw with space
|
|
|
|
:: (C a, C a) | | => a | pike width ranging from 0 to 1, 1 yields triangle
| -> T a a | | triangle with space
|
|
|
|
:: (C a, C a) | | => a | pike width ranging from 0 to 1
| -> a | shift ranges from -1 to 1; 0 yields trianglePike
| -> T a a | | triangle with space and shift
|
|
|
|
:: C a | | => a | pike width ranging from 0 to 1, 1 yields square
| -> T a a | | square with space,
can also be generated by mixing square waves with different phases
|
|
|
|
:: C a | | => a | pike width ranging from 0 to 1
| -> a | shift ranges from -1 to 1; 0 yields squarePike
| -> T a a | | square with space and shift
|
|
|
|
:: (Ord a, C a) | | => a | value between -1 and 1 controlling the ratio of high and low time:
-1 turns the high time to zero,
1 makes the low time zero,
0 yields square
| -> T a a | | square with different times for high and low
|
|
|
|
Like squareAsymmetric but with zero average.
It could be simulated by adding two saw oscillations
with 180 degree phase difference and opposite sign.
|
|
|
:: (Ord a, C a) | | => a | asymmetry parameter ranging from -1 to 1:
For 0 you obtain the usual triangle.
For -1 you obtain a falling saw tooth starting with its maximum.
For 1 you obtain a rising saw tooth starting with a zero.
| -> T a a | | triangle
|
|
|
|
|
|
|
:: (C a, C a) | | => a | sum of the plateau widths ranging from 0 to 1:
0 yields triangleAsymmetric,
1 yields squareAsymmetric
| -> a | asymmetry of the plateau widths ranging from -1 to 1
| -> T a a | | Trapezoid with distinct high and low time.
That is the high and low trapezoids are symmetric itself,
but the whole waveform is not symmetric.
|
|
|
trapezoidBalanced :: (C a, C a) => a -> a -> T a a | Source |
|
trapezoid with distinct high and low time and zero direct current offset
|
|
|
:: (Ord a, C a) | | => a | width of the ramp,
that is 1 yields a downwards saw ramp
and 0 yields a square wave.
| -> T a a | | parametrized trapezoid that can range from a saw ramp to a square waveform.
|
|
|
|
This is similar to Polar coordinates,
but the range of the phase is from 0 to 1, 0 to 2*pi.
| Constructors | Harmonic | | harmonicPhase :: T a | | harmonicAmplitude :: a | |
|
|
|
|
|
|
|
Specify the wave by its harmonics.
The function is implemented quite efficiently
by applying the Horner scheme to a polynomial with complex coefficients
(the harmonic parameters)
using a complex exponential as argument.
|
|
Produced by Haddock version 2.4.2 |