synthesizer-core- Audio signal processing coded in Haskell: Low level part

Portabilityrequires multi-parameter type classes






Envelope application

amplify :: C a => a -> T a -> T aSource

amplifyVector :: C a v => a -> T v -> T vSource



:: C a 
=> T a

the envelope

-> T a

the signal to be enveloped

-> T a 



:: C a v 
=> T a

the envelope

-> T v

the signal to be enveloped

-> T v 

fadeInOut :: C a => Int -> Int -> Int -> T a -> T aSource


generic :: C a v => T a -> T v -> T vSource

Unmodulated non-recursive filter

binomial :: (C a, C a, C a v) => a -> a -> T v -> T vSource

ratioFreqToVariance :: C a => a -> a -> aSource

Compute the variance of the Gaussian such that its Fourier transform has value ratio at frequency freq.

binomial1 :: C v => T v -> T vSource

sums :: C v => Int -> T v -> T vSource

Moving (uniformly weighted) average in the most trivial form. This is very slow and needs about n * length x operations.

inverseFrequencyModulationFloor :: (Ord t, C t) => T t -> T v -> T vSource

This is inverse to frequency modulation. If all control values in ctrl are above one, then it holds: frequencyModulation ctrl (inverseFrequencyModulationFloor ctrl xs) == xs . Otherwise inverseFrequencyModulationFloor is lossy. For the precise property we refer to Test.Sound.Synthesizer.Plain.Interpolation. The modulation uses constant interpolation. Other interpolation types are tricky to implement, since they would need interpolation on non-equidistant grids. Ok, at least linear interpolation could be supported with acceptable effort, but perfect reconstruction would be hard to get. The process is not causal in any of its inputs, however control and input are aligned.

If you use interpolation for resampling or frequency modulation, you may want to smooth the signal before resampling according to the local resampling factor. However you cannot simply use the resampling control to also control the smoothing, because of the subsequent distortion by resampling. Instead you have to stretch the control inversely to the resampling factor. This is the task of this function. It may be applied like:

 frequencyModulation ctrl (smooth (inverseFrequencyModulationFloor ctrl ctrl) xs)

inverseFrequencyModulationGen :: (Ord t, C t) => (t -> Bool) -> T t -> T v -> T vSource

Filter operators from calculus

differentiate :: C v => T v -> T vSource

Forward difference quotient. Shortens the signal by one. Inverts in the sense that differentiate (zero : integrate x) == x. The signal is shifted by a half time unit.

differentiateCenter :: C v => T v -> T vSource

Central difference quotient. Shortens the signal by two elements, and shifts the signal by one element. (Which can be fixed by prepending an appropriate value.) For linear functions this will yield essentially the same result as differentiate. You obtain the result of differentiateCenter if you smooth the one of differentiate by averaging pairs of adjacent values.

ToDo: Vector variant

differentiate2 :: C v => T v -> T vSource

Second derivative. It is differentiate2 == differentiate . differentiate but differentiate2 should be faster.