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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

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]

Properties

Versions 1.0.0, 1.0.1, 1.0.1, 1.1, 1.2.0
Change log CHANGELOG.md
Dependencies ansi-terminal (>=1.0 && <1.1), base (>=4.17.0.0 && <4.18), binary (>=0.8.9 && <0.9), bytestring (>=0.11.4 && <0.12), bytestring-to-vector (>=0.3.0 && <0.4), deepseq (>=1.4.8 && <1.5), directory (>=1.3.7 && <1.4), 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-sdl (>=0.9.3 && <1.1), random (>=1.2.1 && <1.3), text (>=2.0.2 && <2.1), transformers (>=0.5.6 && <0.6), 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-09-13T14:15:06Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for lambdasound-1.0.1

[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

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

For this library, you will need to have SDL2 installed. Take a look at proteeaudio-sdl for installation instructions.

Contributing

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