Skip to content

albertp007/FSound

Repository files navigation

Synopsis

FSound is a library for processing sound using F#

Code Example

You can run these examples in F# interactive in Visual Studio. Make sure you build the project first. Then in Solution Explorer, right click on the FSound project and select "Send Project Output to F# Interactive". This will load the FSound project assembly into F# Interactive. After that, simply copy and paste the code over in each of the following code examples.

Here are some of the things you can do with FSound:

Generate mono wav file

  • Generate a .wav file containing a single channel of sawtooth wave of amplitude 10000, 440Hz, sampling rate 44100Hz, 1 channel, 16-bit sample (2 bytes) and which lasts for 2 seconds

    open FSound.Signal;;
    open FSound.IO;;
    
    [saw 10000.0 440.0] 
    |> List.map (generate 44100.0 2.0) 
    |> streamToWav 44100 2 @"blah.wav";;
    

Generate stereo wav file

  • Generate a .wav file containing a triangular wave in the left channel and white noise on the right channel

    open FSound.Signal;;
    open FSound.IO;;
    
    [triangle 10000.0 440.0; whiteNoise 10000.0]
    |> List.map (generate 44100.0 2.0)
    |> streamToWav 44100 2 @"blah.wav";;
    

Play a mono signal

Play different signals in left and right channel

ADSR envelope

Delay with ADSR envelope on triangular waveform

Delay with ADSR envelope on white noise

Smith-Angell resonator

Smith-Angell resonator with an ADSR envelope

High-pass filter on white noise

Low-pass filter on white noise with an LFO

Plotting frequency response

  • Plot the magnitude response of a biquad low-pass filter with a centre frequency of 1000Hz and Q equal to 1 To run the following in F# interactive, you need to send the Newtonsoft.Json reference to F# interactive in addition to the FSound project reference

    open FSound.Filter;;
    open FSound.Plotly;;
    
    bqlpCoeff 44100.0 1000.0 1.0
    |> plotMagnitude 44100.0 5000.0;;
    

    alt text

Vibrato

Flanging

Flanging on white noise

Chorus

Streaming sample sequences

  • Streaming a sequence of samples to a wav file as the sample is being evaluated.

    open FSound.IO;;
    open FSound.Signal;;
    open FSound.Filter;;
    [modulate (square 10000.0 440.0 >> chorus 44100.0 30.0 0.4 1.5) (adsr 0.05 1.0 0.05 0.3 0.1 0.05) 
    >> delay 4410.0 2.0 200.0 1.0 0.9 0.5 
    |> generate 44100.0 2.0 ]
    |> streamToWav 44100 2 @"C:\Users\panga\project\FSound\blah.wav";;
    

Karplus-Strong algorithm

Arrangement of instruments

Ping-pong delay

Chord progression

Telephone ringing tone

Schroeder reverberation

Ring modulation

FM Synthesis

Chowning's FM instruments

Representing relationships in Western Tonal Music

  • Chords - Construction of chords from intervals

    open FSound.Tonal;;
    addIntervalToNote (Sh A) (Aug Third);;
    makeChord (Major (N C));; // C Major
    makeChord (Major (Sh G));; // G-sharp Major
    makeChord (Neo6 (N C));; // C neopolitan 6th
    

Motivation

This project arises purely out of a personal interest in learning the F# programming language and applying it to a domain I have always found fascinating - Sound

Installation

Simply download the project and load it in visual studio 2015.

If your version of Visual Studio does not have F#, you may install the free Visual Studio 2015 Community Edition. The Visual F# Tools are installed automatically when you first create or open an F# project. See: http://fsharp.org/use/windows/

This project requires you to install a couple of dependent packages.

To do this with Nu-Get in VS:

  1. Right click References in Solution Explorer
  2. Click Manage Nu-Get packages
  3. Click Restore when you see "Some NuGet packages are missing from this solution. Click to restore from your online package sources"

You should be all set. Simply rebuild the project. Feel free to send an email to [email protected] if you run into any problems.

Tests

SignalTest.fsx is the only test script for now. Load it into F# interactive:

C:\Users\panga\project\fsharp\FSound>fsi --load:SignalTest.fsx

Microsoft (R) F# Interactive version 14.0.23020.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

[Loading C:\Users\panga\project\fsharp\FSound\SignalTest.fsx]

namespace FSI_0002
  val main : unit -> bool

> SignalTest.main();;
val it : bool = true

> exit 0;;

C:\Users\panga\project\fsharp\FSound>dir *.wav
 Volume in drive C has no label.
 Directory of C:\Users\panga\project\fsharp\FSound

01/09/15  07:17 pm           176,446 saw-440.wav
01/09/15  07:17 pm           176,446 sinusoid-440.wav
01/09/15  07:17 pm           176,446 square-440.wav
01/09/15  07:17 pm           176,446 triangle-440.wav
01/09/15  07:17 pm           882,046 wave.wav
01/09/15  07:17 pm           176,446 whitenoise.wav
               6 File(s)      1,764,276 bytes
               0 Dir(s)  30,879,870,976 bytes free

Contributors

Albert Pang ([email protected])

Showcase

William Sharkey's compositions (https://github.com/williamsharkey/William-FSound-Songs)

License

Released under GPL v3.0 licence

About

F# sound processing library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages