feat: refactoring

This commit is contained in:
2023-06-05 16:56:55 +04:00
parent 07cb8f8003
commit 059ea3db5b
7 changed files with 54 additions and 74 deletions

View File

@@ -1,15 +1,15 @@
module SoundGen.PCMWave
open Settings
open System.IO
let private toInt16Sample sample = sample |> (*) 32767. |> int16
let private pack (d: int16 []) =
let private pack (d: int16[]) =
let stream = new MemoryStream()
let writer =
new BinaryWriter(stream, System.Text.Encoding.ASCII)
let writer = new BinaryWriter(stream, System.Text.Encoding.ASCII)
let dataLength = Array.length d * 2
@@ -33,12 +33,11 @@ let private pack (d: int16 []) =
writer.Write(System.Text.Encoding.ASCII.GetBytes("data"))
writer.Write(dataLength)
let data: byte [] =
Array.zeroCreate dataLength
let data: byte[] = Array.zeroCreate dataLength
System.Buffer.BlockCopy(d, 0, data, 0, dataLength)
writer.Write(data)
stream
let createWAV(wave: float seq) =
wave |> Seq.map (fun x -> x |> toInt16Sample) |> Seq.toArray |> pack
let createWAV (wave: float seq) =
wave |> Seq.map (fun x -> x |> toInt16Sample) |> Seq.toArray |> pack