43 lines
1.1 KiB
Forth
43 lines
1.1 KiB
Forth
open System.IO
|
|
open SoundGen
|
|
open PCMWave
|
|
open Fx
|
|
open Synth
|
|
open System
|
|
|
|
|
|
type Note = { Name: string; Length: int }
|
|
|
|
let parseNotes (input: string) =
|
|
input.Replace('\n', ' ').Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
|
|> Seq.map (fun noteStr ->
|
|
let noteSigns = noteStr.Split('-')
|
|
let name = noteSigns[0].Trim()
|
|
let length = noteSigns[1].Trim() |> int
|
|
{ Name = name; Length = length })
|
|
|> List.ofSeq
|
|
|
|
let getNoteSound (input: Note) =
|
|
let length = 1.0 / float input.Length
|
|
let semitoneShift = getSemitoneShift input.Name
|
|
note semitoneShift length
|
|
|
|
let input =
|
|
"A4-4 A4-4 A4-4 A4-4 A4-2 A4-4 A4-4 A4-4 A4-4 A4-4 A4-2 D5-4 D5-4 D5-4 D5-4 D5-4 D5-4 D5-2 C5-4 C5-4 C5-4 C5-4 C5-4 C5-4 C5-2 G4-2 "
|
|
|
|
let notes = String.replicate 2 input |> parseNotes
|
|
|
|
let song = notes |> Seq.map getNoteSound |> Seq.concat
|
|
|
|
let writeToFile (ms: MemoryStream) =
|
|
use fs =
|
|
new FileStream(Path.Combine(__SOURCE_DIRECTORY__, "test.wav"), FileMode.Create)
|
|
|
|
ms.WriteTo(fs)
|
|
|
|
song
|
|
//|> reverb
|
|
|> Seq.map (waveshaper { Gain = 1.5; Factor = 2.5 })
|
|
|> createWAV
|
|
|> writeToFile
|