LambdaSound 1.0.0 - A sound synthesizing library

Hello,

I have released LambdaSound 1.0.0 on Hackage. LambdaSound is a library for synthesizing sounds purely in Haskell with various combinators. The generated sounds can be directly played or saved to a WAV audio file.

Contrary to other sound synthesis libraries, LambdaSound is more low-level and provides direct access to the generated sound samples. Therefore, this library might be interesting for people wanting to play around with raw sound samples and designing their own sounds. As a consequence, LambdaSound does not have any instruments built-in yet and only has electric sounds.

However, LambdaSound has some higher-level combinators to play sounds in sequence or in parallel, cut sounds apart or play sounds at a specific pitch.

Here’s an example of what LambdaSound can do:

import LambdaSound

main :: IO ()
main = play 44100 0.5 $
    let downwards = sequentially $ setDuration 0.25 . note
          <$> [g4, f4, e4, d4, f4, e4, d4, c4, e4, d4, c4, b3]
     in sequentially
          [ downwards,
            dropSound 0.25 (reverseSound $ dropSound 0.5 downwards),
            setDuration 0.25 (parallel $ note <$> [c4, e4]),
            setDuration 0.25 (parallel $ note <$> [c4, e4, g4]),
            setDuration 0.5 (parallel $ note <$> [c4, g4, c5])
          ]

note :: Semitone -> Sound I Pulse
note st = easeInOut 2 $ asNote sawWave st + asNote (harmonic triangleWave) st
18 Likes

I’ve been looking for a SFX synth solution for my games (Faust is what I’m currently learnging), so this has me interested!

Congrats on the release!

2 Likes

I recently found myself wanting to reimplement the Karplus-Strong algorithm to do a little synth, since the last time I implemented it was in C# at least a decade ago :slight_smile: I might use this library to give it a another go.

3 Likes

That’s really great!! How does it work in realtime with more complex code? How about latency?

The library was not designed for realtime use. You define the sound and it gets synthesized from 0% to 100%.

I am imagining you want to press buttons (or midi keys) and then synthesize a corresponding sound asap. Such a use case would be possible to implement, but I have not done any development towards this.

3 Likes

Yes, we can do that in haskell using a sound synthesis server, like supercollider, with all unit generators written in c++, and a server managing grounps and buses etc.

Maybe your code can be a proof of concept that it’s possible to write low-level dsp code in haskell while it’s running, faster than realtime.

I know there is a limitation because of the GC that interferes with a real-time scheduler, which would compromise a low-latency audio synthesis. But it seems this issue got much better now.

I believe writing dsp code in Haskell should be no problem. Latency due to the GC might become an issue, but for hobbyists it probably does not matter.
However, LambdaSound is still a ways off of being usable real time since you would need to change quite a lot. I have some ideas on how to improve the library and potentially facilitate real-time use, but it’s still in the beginning stages and there is no timeline.

1 Like