Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main
- open System
- open System.Windows.Forms
- open System.Media
- open System.Drawing
- open System.IO
- open System.Timers
- open MathNet.Numerics.Transformations
- open LineChart
- open ContinueChart
- open WaveUtils
- open Charts
- open Utils
- open DSoundPlayer
- open ViewStream
- [<EntryPointAttribute>]
- let main argv =
- let refreshFrequency = 25
- //let tick = 1000 / refreshFrequency
- let tick = 1000. / double refreshFrequency
- printfn "%f" tick
- let form = new Form(Text = "Chart test");
- let sampleChart = new ContinueChart()
- let transformChart = new ContinueChart()
- sampleChart.Width <- 500
- sampleChart.Height <- 200
- (* sampleChart.XFix <- XFix.Middle *)
- (* sampleChart.YFix <- YFix.Left *)
- transformChart.Width <- 500
- transformChart.Height <- 200
- transformChart.Top <- 200
- transformChart.XFix <- XFix.Bottom
- transformChart.YFix <- YFix.Left
- let mutable phase = 0.
- let timer = new Timer()
- timer.Interval <- tick
- let _sampleRate = 48000
- let fileStream = new FileStream(argv.[0], FileMode.Open)
- let printb (buffer: byte array) =
- for i in 0..(buffer.Length-1) do
- printf "0x%2x " buffer.[i]
- printfn ""
- let soundPlayer = new SoundPlayer()
- let buffer: byte[] = Array.zeroCreate((2 * _sampleRate) / refreshFrequency)
- let streamReader = new BinaryReader(fileStream)
- let rec printListP (list: PointF list) =
- match list with
- | [] -> printfn ""
- | a::b ->
- printfn "(%f, %f) " (a.X) (a.Y)
- printListP b
- let rec printListF (list: float list) =
- match list with
- | [] -> printfn ""
- | a::b ->
- printf "%.2f," a
- printListF b
- let rec printListI (list: int list) =
- match list with
- | [] -> printfn ""
- | a::b ->
- printf "%d," a
- printListI b
- let rft = new RealFourierTransformation()
- transformChart.AutoFix <- false
- let soundStream = new MemoryStream()
- let counter = ref 0
- timer.Elapsed.Add(fun _ ->
- let x = streamReader.Read(buffer, 0, buffer.Length)
- let bufferList = Array.toList(buffer)
- let values: float[] = ArrayFromPCM16 buffer
- let chartPoints = PointsFromArray(values, _sampleRate)
- let rTransf, cTransf = (ref null, ref null)
- let sizeNew = nextTwoPower values.Length
- //printfn "%d %d" values.Length sizeNew
- let trValues = Array.zeroCreate sizeNew
- for i in 0..(values.Length-1) do
- trValues.[i] <- values.[i]
- rft.TransformForward(trValues, rTransf, cTransf)
- let transfPoints = PointsFromArray(!rTransf, 44100)
- sampleChart.newData(chartPoints)
- //sampleChart.Color <- Color.FromArgb(25 * (!counter%10), 25 * (!counter%10), 0)
- transformChart.newData(transfPoints)
- if x < buffer.Length then timer.Stop()
- counter := !counter + 1
- )
- soundPlayer.Stream <- fileStream
- soundPlayer.Play()
- streamReader.BaseStream.Seek(0L, SeekOrigin.Begin) |> ignore
- timer.Start()
- let mutable count = 0
- let x = new PointF(3.f, 2.f)
- let upButton = new Button()
- let downButton = new Button()
- upButton.Click.Add(fun _ -> sampleChart.UpScale())
- downButton.Click.Add(fun _ -> sampleChart.DownScale())
- let tablePanel = new TableLayoutPanel()
- tablePanel.RowCount <- 2
- tablePanel.ColumnCount <- 1
- let panel = new Panel()
- upButton.Text <- "↑"
- upButton.Dock <- DockStyle.Left
- upButton.Height <- 20
- downButton.Text <- "↓"
- downButton.Dock <- DockStyle.Right
- downButton.Height <- 20
- panel.Controls.Add(upButton)
- panel.Controls.Add(downButton)
- panel.Height <- 20
- tablePanel.Controls.Add(sampleChart, 0, 0)
- tablePanel.Controls.Add(transformChart, 1, 0)
- tablePanel.Controls.Add(panel, 2, 0)
- tablePanel.Dock <- DockStyle.Fill
- form.Controls.Add(tablePanel)
- form.Controls.Add(transformChart)
- form.Width <- 500
- form.Height <- 500
- form.Show()
- //timer.Start()
- Application.Run(form)
- let ret = 0
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement