Sub Class_Globals
Private fx As JFX
Private xui As XUI
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
Public Sub Draw(data() As Short) As B4XBitmap
data = Compress(data)
Dim normalized() As Float= Normalize(data)
Dim bc As BitmapCreator
bc.Initialize(3000,500)
Dim height As Int = 500 - 200
Dim NbSamples As Int = normalized.Length
For i = 0 To NbSamples - 1
If i = NbSamples - 1 Then
Exit
End If
Dim centerY As Double = 250
Dim x1 As Int = i
Dim y1 As Double = centerY + normalized(i)*height
Dim x2 As Int = i+1
Dim y2 As Double = centerY + normalized(i+1)*height
bc.DrawLine(x1,y1,x2,y2,xui.Color_Red,1)
Next
Return bc.Bitmap
End Sub
Private Sub Compress(data() As Short) As Short()
Dim times As Int
If data.Length > 3000 Then
times = data.Length / 3000
Else
Return data
End If
Dim compressed(3000) As Short
For i = 0 To compressed.Length - 1
compressed(i) = data(i*times)
Next
Return compressed
End Sub
Private Sub Normalize(data() As Short) As Float()
Dim normalized(data.Length) As Float
Dim maxValue As Short = 0
For i = 0 To data.Length - 1
Dim value As Short = data(i)
maxValue = Max(maxValue,value)
Next
For i = 0 To data.Length - 1
normalized(i) = data(i) / maxValue
Next
Return normalized
End Sub