feat: refactoring
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
open SoundGen
|
||||
open PCMWave
|
||||
open Fx
|
||||
open SoundGen.Fx
|
||||
open Synth
|
||||
open System
|
||||
|
||||
@@ -10,29 +9,27 @@ open System
|
||||
type Note = { Name: string; Length: int }
|
||||
|
||||
let parseNotes (input: string) =
|
||||
let gluedString = input.Replace ('\n', ' ')
|
||||
gluedString.Split([| ' ' |], StringSplitOptions.RemoveEmptyEntries)
|
||||
let gluedString = input.Replace('\n', ' ')
|
||||
|
||||
gluedString.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
||||
|> Seq.map (fun noteStr ->
|
||||
let noteSigns = noteStr.Split([| '-' |])
|
||||
let noteSigns = noteStr.Split('-')
|
||||
let name = noteSigns[0].Trim()
|
||||
let length = noteSigns[1].Trim() |> int
|
||||
{ Name = name.Trim(); Length = length })
|
||||
{ Name = name; Length = length })
|
||||
|> List.ofSeq
|
||||
|
||||
let getNoteSound (input: Note) =
|
||||
let length = 1.0 / float input.Length
|
||||
let semitoneShift = getSemitoneShift "A4" input.Name
|
||||
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 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 song =
|
||||
notes
|
||||
|> Seq.map getNoteSound
|
||||
|> Seq.concat
|
||||
let notes = String.replicate 2 input |> parseNotes
|
||||
|
||||
let song = notes |> Seq.map getNoteSound |> Seq.concat
|
||||
|
||||
let writeToFile (ms: MemoryStream) =
|
||||
use fs =
|
||||
@@ -42,6 +39,6 @@ let writeToFile (ms: MemoryStream) =
|
||||
|
||||
song
|
||||
//|> reverb
|
||||
|> Seq.map (waveshaper {Gain=1.5; Factor=2.5})
|
||||
|> Seq.map (waveshaper { Gain = 1.5; Factor = 2.5 })
|
||||
|> createWAV
|
||||
|> writeToFile
|
||||
|
||||
Reference in New Issue
Block a user