[Haskell-cafe] Requesting For Comments for a new simple-dsp library

Henning Thielemann lemming at henning-thielemann.de
Thu Mar 21 18:04:22 UTC 2024


On Thu, 21 Mar 2024, Tristan Cacqueray wrote:

> I'd like to propose a new package named simple-dsp. I couldn't figure
> out how to use the existing dsp library, so I made my own version
> featuring a little GUI to try the code in realtime.
>
> I'd be happy to contribute this work directly to dsp.

The 'dsp' package is pretty old, predating any Vector data type or refined 
numeric type class hierarchies. I decided to leave it as it is, for 
educational reasons, since it contains many literal translations of signal 
processing algorithms from various text books. I have not used most of the 
contained functions myself.

> My goal is to be able to extract sensible discrete values from a sound 
> input at 60 Hz for video production. I implemented low/band/high pass 
> filters to compute 3 RMS volumes, but the values I'm getting are not 
> sharp enough, e.g. the band pass picks the low end. Ideally I would 
> extract the transient events of the percusive sound and the note pitch 
> of the melodic elements.

For a filter that computes lowpass, highpass and bandpass in one go, I use 
the "universal filter", also known as "state variable filter":
   https://hackage.haskell.org/package/synthesizer-core-0.8.3/docs/Synthesizer-Plain-Filter-Recursive-Universal.html

You can see running examples here:
   https://hackage.haskell.org/package/synthesizer-core-0.8.3/docs/src/Synthesizer.Plain.Filter.Recursive.Test.html#universalTest

Frequencies are specified as ratio with respect to the sampling rate, e.g. 
440 Hz resonance frequency at 44100 Hz sampling rate translates to 
440/44100. For working on storable vectors you would instead use 
Universal.causal and apply this to Data.StorableVector.Lazy. For very fast 
processing I have the synthesizer-llvm package, which however depends on 
the LLVM package in a compatible version. (LLVM-16 currently preferred.)


Unfortunately I do not understand your application well, thus I do not 
know whether the state variable filter is the right choice for your 
application.


More information about the Haskell-Cafe mailing list