Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simre1/lambdasound
A Haskell libary for generating low-level sounds with high-level combinators.
https://github.com/simre1/lambdasound
Last synced: 2 months ago
JSON representation
A Haskell libary for generating low-level sounds with high-level combinators.
- Host: GitHub
- URL: https://github.com/simre1/lambdasound
- Owner: Simre1
- License: mit
- Created: 2023-06-03T13:57:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-10T14:48:46.000Z (3 months ago)
- Last Synced: 2024-10-11T14:38:44.233Z (3 months ago)
- Language: Haskell
- Homepage:
- Size: 188 KB
- Stars: 15
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```haskell
-- 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:
```haskell
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:
```haskell
cabal run example1
cabal run example2
cabal run example3
```## Contributing
Feel free to try out this library and add additional functionality.