lambdasound: A libary for generating low-level sounds with high-level combinators

[ library, mit, program, sound ] [ Propose Tags ]

lambdasound can generate all kinds of sounds, play them and save them as wav or pcm data. Sound can be manipulated in both a low and high-level way. It is possible to operate on the samples of a sound. However, there are also higher-level combinators for various tasks, e.g. to facilitate sequential and parallel playing of sounds or to change the duration of a sound.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0, 1.0.1, 1.1, 1.2.0
Change log CHANGELOG.md
Dependencies ansi-terminal (>=1.0 && <1.1), base (>=4.17.0.0 && <5), bytestring (>=0.11.4 && <0.12), bytestring-to-vector (>=0.3.0 && <0.4), deepseq (>=1.4.8 && <1.6), directory (>=1.3.7 && <1.4), dsp (>=0.2.5.2 && <0.3), filepath (>=1.4.2 && <1.5), hashable (>=1.4.3 && <1.5), hashtables (>=1.3.1 && <1.4), lambdasound, massiv (>=1.0.4 && <1.1), proteaaudio (>=0.9.3 && <1.1), random (>=1.2.1 && <1.3), text (>=2.0.2 && <2.2), transformers (>=0.5.6 && <0.7), vector (>=0.13.0 && <0.14), wave (>=0.2.0 && <0.3), zlib (>=0.6.3 && <0.7) [details]
License MIT
Copyright 2023 Simon Reitinger
Author Simon Reitinger
Maintainer simre4775@gmail.com
Category Sound
Home page https://github.com/Simre1/lambdasound
Bug tracker https://github.com/Simre1/lambdasound/issues
Source repo head: git clone https://github.com/Simre1/lambdasound
Uploaded by voyager at 2023-12-03T13:52:39Z
Distributions
Executables lambdasound-profile, example3, example2, example1
Downloads 91 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for lambdasound-1.2.0

[back to package description]

LambdaSound

A Haskell libary for generating low-level sounds with high-level combinators.

You can create sounds as a list of floats and then manipulate them with combinators like parallel, sequentially or dropSound.

Examples

-- An infinite 440hz sinus curve
sound440Hz :: Sound I Pulse
sound440Hz = sineWave 440 

-- Three infinite sounds in parallel
triad :: Sound I Pulse
triad = parallel $ fmap (asNote sineWave) [c4, e4, g4]

-- Five sequential 1 second sounds 
ascending :: Sound T Pulse
ascending = sequentially $
  fmap (setDuration 1 . asNote sineWave) [c4,d4,e4,f4,g4]

-- Cut apart sounds with takeSound and dropSound
ascendingPart :: Sound T Pulse
ascendingPart = takeSound 1 $ dropSound 1 ascending

-- Add a quiet noise to a sound
noisyAscending :: Sound T Pulse
noisyAscending = parallel
  [ setDuration (getDuration ascending) (reduce 3 (noise 42)),
    ascending
  ]

-- Raise the frequency of a sound so it has a higher pitch
ascendingAnOctaveHigher :: Sound T Pulse
ascendingAnOctaveHigher = raise 8 ascending 

-- Reverse the samples in a sound
descending :: Sound T Pulse
descending = reverseSound ascending

-- Change the tempo the parts of a sound are played at
speedupDuringSound :: Sound d Pulse -> Sound d Pulse
speedupDuringSound = changeTempo $ \progress -> progress ** 1.2

-- Play sound with a sample rate of 44100
main :: IO ()
main = do
  let volume = 0.5
      sampleRate = 44100
  play sampleRate volume ascending

You can also take a look at example/Example1.hs and example/Example2.hs for bigger examples and play them with:

cabal run example1
cabal run example2

Feature Overview

  • Play sounds with RTAudio
  • Save sounds as WAV
  • Create raw audio samples by defining a vector of floats
  • Manipulate the duration of a sound
  • Combine sounds via parallel, sequentially or zipSound
  • Change volume
  • Modify the pitch
  • Create a sound and then map over its samples
  • Convolve sounds
  • IIR filters
  • Cut apart sounds with takeSound and dropSound
  • Scaling playing speed
  • Cache expensive to compute sounds in your XDG-cache directory
  • Loading wav files (with some caveats)
  • Embed IO into sounds

Building

lambdasound can be built as usual with the cabal package manager.

git clone https://github.com/Simre1/lambdasound
cabal build lambdasound

You can run the example with:

cabal run example1
cabal run example2
cabal run example3

Contributing

Feel free to try out this library and add additional functionality.