Click on an Option to read more about it!

 

 

VB6 Code:

This is the code that allowed me to refine my microphone's signal, before outputting it to both the screen and the motor (I wrote it myself).

Program In Action

Dim buffer(60000) As Integer 'must be big enough to handle all the data
Dim c1a(10000) As Integer
Dim c2a(10000) As Integer
Dim val(1 To 2) As Double
Dim cal As Boolean
Dim calib As Double
Dim calib2 As Double

Private Sub A2D_NewData(ByVal Count As Integer)
'InputChart.Chart (A2D.GetData)

NewData = Count - Count Mod A2D.ADChannelCount 'always take multiple of channel count
NewCalData = NewData / A2D.ADChannelCount
If NewCalData > 1 Then
A2D.GetDataEx buffer(0), NewData 'the data will be in the array
Inputchart.ChartEx buffer(0), A2D.ADChannelCount, NewCalData 'plot all three channels here
End If
mult = (2 ^ (CLng(exp)))
If cal = True Then calib = 0
If cal = True Then mult = 1
If cal = True Then calib2 = 0

For I = 0 To Count - 1
If I Mod 2 = 0 Then

If cal = False Then c1a(I / 2) = min(32766, (buffer(I) - calib) * mult) Else c1a(I / 2) = buffer(I) * mult

If cal = True Then calib = calib + buffer(I)
'Debug.Print (buffer(I) - calib)
Else
If cal = False Then c2a((I - 1) / 2) = min(32766, (buffer(I) - calib2) * mult) Else c2a((I - 1) / 2) = buffer(I) * mult

If cal = True Then calib2 = calib2 + buffer(I)
End If
Next I
If cal = True Then
calib = calib / (Count / 2)
calib2 = calib2 / (Count / 2)
End If
cal = False

Dim r2d(20000) As Integer

guacamole = 0

For guacamole = 1 To (Count / 2)
r2d(2 * guacamole - 1) = c1a(guacamole - 1)
r2d(2 * guacamole) = c2a(guacamole - 1)
Next guacamole

AdjustChart.ChartEx r2d(0), 2, Count / 2 'plot all three channels here
val(1) = RMS(0, Count / 2)
val(2) = RMS(1, Count / 2)
End Sub

Private Function min(minimum As Double, value As Double) As Integer
urb = 0
If value > minimum Then
urb = minimum
Else
urb = value
End If
If urb > 0 Then
min = urb
Exit Function
End If
urb = 0
If value < -1 * minimum Then
urb = -1 * minimum
Else
urb = value
End If
min = urb
End Function

Private Sub calibrator_Click()
cal = True
End Sub

Private Sub cmdStart_Click()

 

A2D.DeviceID = "COM4 148 38400"
A2D.MaxBurstRate = 50000 'sets MaxBurstRate
A2D.EventPoint = 10
A2D.ADChannelCount = 2
A2D.SampleRate = 14400

A2D.Start

End Sub

Private Function RMS(channel As Integer, Count As Integer) As Double

 

Dim data

If (channel = 0) Then
data = c1a
Else
data = c2a
End If

 

Dim squaresum As Double

For I = 0 To Count - 1
squaresum = squaresum + (data(I) ^ 2)
Next I

squaresum = squaresum / Count

RMS = Math.Sqr(squaresum)

End Function

Private Function PWM(volume As Double) As Integer
Randomize Timer
'10752
volume = volume / 32766
If volume > 0.15 Then
If Rnd < volume Then Output = 1 Else Output = 0
PWM = Output
Else
PWM = 0
End If
'Debug.Print output & "," & volume

End Function

Private Sub Form_Load()
cal = False
End Sub

Private Sub PWMer_Timer()
Dim val2(0 To 1) As Integer

val2(0) = PWM(val(1))
val2(1) = PWM(val(2))

Dim ca(1) As Integer
ca(0) = val2(0) * 256 * 100
ca(1) = val2(1) * 256 * 100
Debug.Print (val2(0))
agh = 0
If val2(0) = 1 Then agh = 4
If val2(1) = 1 Then agh = agh + 8

A2D.DigitalOutput = &H8000
A2D.DigitalOutput = agh

Call Outputchart.ChartEx(ca(0), 2, 1)
Call Outputchart.ChartEx(ca(0), 2, 1)
Call Outputchart.ChartEx(ca(0), 2, 1)
Call Outputchart.ChartEx(ca(0), 2, 1)

Call Outputchart.ChartEx(ca(1), 1, 1)
Call Outputchart.ChartEx(ca(1), 1, 1)
Call Outputchart.ChartEx(ca(1), 1, 1)
Call Outputchart.ChartEx(ca(1), 1, 1)

End Sub