fork(3) download
  1. Imports System
  2. Imports System.Collections
  3. Imports System.ComponentModel
  4. Imports System.Drawing
  5. Imports System.Windows.Forms
  6. Imports Microsoft.DirectX.DirectSound
  7. Imports System.Threading
  8. Imports System.Collections.Specialized
  9. Public Class Sound_Card_Form
  10. Private Sub StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
  11. 'Dim MyVU As New VolumeMeter
  12. 'MyVU.Start()
  13. Start()
  14. End Sub
  15. Private Sub FindButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindButton.Click
  16. 'Dim MyVU As New VolumeMeter
  17. 'MyVU.FindDevices()
  18. FindDevices()
  19. End Sub
  20.  
  21. ' Public Class VolumeMeter
  22. 'Inherits System.Windows.Forms.UserControl
  23. 'Public Delegate Sub VolumeChangedEventHandler(ByVal vcea As VolumeChangedEventArgs)
  24. 'Public Event VolumeChanged As VolumeChangedEventHandler
  25. Private Const SAMPLES As Integer = 8
  26. Private Shared SAMPLE_FORMAT_ARRAY As Integer() = {SAMPLES, 2, 1}
  27. Public Shared audioDevices As CaptureDevicesCollection
  28. Private Shared m_deviceNames As StringCollection
  29. Private deviceName As String = "(none)"
  30. Private deviceIndex As Integer = -1
  31. Private buffer As Microsoft.DirectX.DirectSound.CaptureBuffer
  32. Private liveVolumeThread As System.Threading.Thread
  33. Private m_sampleDelay As Integer = 100
  34. Private m_frameDelay As Integer = 10
  35. Private m_autoStart As Boolean = True
  36. 'Private components As System.ComponentModel.Container = Nothing
  37. Public Sub FindDevices()
  38. Dim audioDevices As New CaptureDevicesCollection
  39. Dim x As Integer = 0
  40. While x < audioDevices.Count
  41. ComboBox1.Items.Add(audioDevices.Item(x).Description)
  42. x = x + 1
  43. End While
  44. ComboBox1.SelectedIndex = 0
  45. End Sub
  46. Public Sub Start()
  47. [Stop]()
  48. Dim audioDevices As New CaptureDevicesCollection
  49. deviceIndex = ComboBox1.SelectedIndex
  50. If deviceIndex <> -1 Then
  51. ' initialize the capture buffer and start the animation thread
  52. Dim cap As New Capture(audioDevices(deviceIndex).DriverGuid)
  53. Dim desc As New CaptureBufferDescription()
  54. Dim wf As New WaveFormat()
  55. wf.BitsPerSample = 16
  56. wf.SamplesPerSecond = 44100
  57. wf.Channels = 2
  58. wf.BlockAlign = CShort(wf.Channels * wf.BitsPerSample / 8)
  59. wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond
  60. wf.FormatTag = WaveFormatTag.Pcm
  61. desc.Format = wf
  62. desc.BufferBytes = SAMPLES * wf.BlockAlign
  63. buffer = New Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap)
  64. buffer.Start(True)
  65. ' Start a seperate thread to read the buffer and update the progress bars
  66. liveVolumeThread = New Thread(AddressOf updateProgress) 'Thread starts at updateProgress
  67. Control.CheckForIllegalCrossThreadCalls = False ' This is needed otherwise the form will not update
  68. liveVolumeThread.Priority = ThreadPriority.Lowest ' Thread works in the background
  69. liveVolumeThread.Start()
  70. End If
  71. End Sub
  72. Public Sub [Stop]()
  73. If liveVolumeThread IsNot Nothing Then
  74. liveVolumeThread.Abort()
  75. liveVolumeThread.Join()
  76. liveVolumeThread = Nothing
  77. End If
  78. If buffer IsNot Nothing Then
  79. If buffer.Capturing Then
  80. buffer.[Stop]()
  81. End If
  82. buffer.Dispose()
  83. buffer = Nothing
  84. End If
  85. End Sub
  86.  
  87. Public Sub updateProgress()
  88. While True
  89. Dim tempFrameDelay As Integer = m_frameDelay
  90. Dim tempSampleDelay As Integer = m_sampleDelay
  91. Dim samples__1 As Array = buffer.Read(0, GetType(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY)
  92. ' for each channel, determine the step size necessary for each iteration
  93. Dim leftGoal As Integer = 0
  94. Dim rightGoal As Integer = 0
  95. ' Sum the 8 samples
  96. For i As Integer = 0 To SAMPLES - 1
  97. leftGoal += CType(samples__1.GetValue(i, 0, 0), Int16)
  98. rightGoal += CType(samples__1.GetValue(i, 1, 0), Int16)
  99. Next
  100. ' Calculate the average of the 8 samples
  101. leftGoal = CInt(Math.Abs(leftGoal \ SAMPLES))
  102. rightGoal = CInt(Math.Abs(rightGoal \ SAMPLES))
  103. Dim range1 As Double = leftGoal - ProgressBar1.Value ' calculates the difference between new and the current progress bar value
  104. Dim range2 As Double = rightGoal - ProgressBar2.Value
  105. ' Assign the exact current value to the progress bar
  106. Dim exactValue1 As Double = ProgressBar1.Value
  107. Dim exactValue2 As Double = ProgressBar2.Value
  108. Dim stepSize1 As Double = range1 / tempSampleDelay * tempFrameDelay
  109. ' Limit the value range to positive values
  110. If Math.Abs(stepSize1) < 0.01 Then
  111. stepSize1 = Math.Sign(range1) * 0.01
  112. End If
  113. Dim absStepSize1 As Double = Math.Abs(stepSize1)
  114. Dim stepSize2 As Double = range2 / tempSampleDelay * tempFrameDelay
  115. If Math.Abs(stepSize2) < 0.01 Then
  116. stepSize2 = Math.Sign(range2) * 0.01
  117. End If
  118. Dim absStepSize2 As Double = Math.Abs(stepSize2)
  119. ' increment/decrement the bars' values until both equal their desired goals,
  120. ' sleeping between iterations
  121. If (ProgressBar1.Value = leftGoal) AndAlso (ProgressBar2.Value = rightGoal) Then
  122. Thread.Sleep(tempSampleDelay)
  123. Else
  124. Do
  125. If ProgressBar1.Value <> leftGoal Then
  126. If absStepSize1 < Math.Abs(leftGoal - ProgressBar1.Value) Then
  127. exactValue1 += stepSize1
  128. ProgressBar1.Value = CInt(Math.Truncate(Math.Round(exactValue1)))
  129. 'This is the real value
  130. 'decibels = 20 * Log10(ProgressBar1.Value/ 32768.0)
  131. Else
  132. ProgressBar1.Value = leftGoal
  133. End If
  134. End If
  135. If ProgressBar2.Value <> rightGoal Then
  136. If absStepSize2 < Math.Abs(rightGoal - ProgressBar2.Value) Then
  137. exactValue2 += stepSize2
  138. ProgressBar2.Value = CInt(Math.Truncate(Math.Round(exactValue2)))
  139. Else
  140. ProgressBar2.Value = rightGoal
  141. End If
  142. End If
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Visual Basic.Net Compiler version 0.0.0.5943 (Mono 3.8 - tarball)
Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.

/home/fVMSh9/<MyGenerator> (1,13) : error VBNC90019: Expected 'Loop'.
/home/fVMSh9/<MyGenerator> (1,13): Compiler error around this location, the compiler hasn't implemented the error message, nor error recovery, so the compiler will probably crash soon.
   at vbnc.Helper.ErrorRecoveryNotImplemented(Span Location)
   at vbnc.Parser.ParseDoStatement(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseCodeBlock(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseIfStatement(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseCodeBlock(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseWhileStatement(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseCodeBlock(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseSubDeclaration(vbnc.TypeDeclaration Parent, vbnc.ParseAttributableInfo Info)
   at vbnc.Parser.ParseTypeMembers(vbnc.TypeDeclaration Parent)
   at vbnc.Parser.ParseClassDeclaration(vbnc.ParsedObject Parent, vbnc.Attributes Attributes, System.String Namespace)
   at vbnc.Parser.ParseTypeDeclaration(vbnc.ParsedObject Parent, vbnc.Attributes Attributes, System.String Namespace)
   at vbnc.Parser.ParseAssemblyMembers(vbnc.AssemblyDeclaration Parent, System.String RootNamespace)
   at vbnc.Parser.ParseAssemblyDeclaration(System.String RootNamespace, vbnc.AssemblyDeclaration assembly)
   at vbnc.Parser.Parse(System.String RootNamespace, vbnc.AssemblyDeclaration assembly)
   at vbnc.Compiler.Compile_Parse()
   at vbnc.Compiler.Compile()
   at vbnc.Compiler.Compile(System.String[] CommandLine)
   at vbnc.Main.Main(System.String[] CmdArgs)
/home/fVMSh9/<MyGenerator> (1,13) : error VBNC90019: Expected 'End'.
/home/fVMSh9/<MyGenerator> (1,13) : error VBNC90019: Expected 'End'.
/home/fVMSh9/<MyGenerator> (1,13): Compiler error around this location, the compiler hasn't implemented the error message, nor error recovery, so the compiler will probably crash soon.
   at vbnc.Helper.ErrorRecoveryNotImplemented(Span Location)
   at vbnc.Parser.ParseWhileStatement(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseCodeBlock(vbnc.ParsedObject Parent, Boolean IsOneLiner)
   at vbnc.Parser.ParseSubDeclaration(vbnc.TypeDeclaration Parent, vbnc.ParseAttributableInfo Info)
   at vbnc.Parser.ParseTypeMembers(vbnc.TypeDeclaration Parent)
   at vbnc.Parser.ParseClassDeclaration(vbnc.ParsedObject Parent, vbnc.Attributes Attributes, System.String Namespace)
   at vbnc.Parser.ParseTypeDeclaration(vbnc.ParsedObject Parent, vbnc.Attributes Attributes, System.String Namespace)
   at vbnc.Parser.ParseAssemblyMembers(vbnc.AssemblyDeclaration Parent, System.String RootNamespace)
   at vbnc.Parser.ParseAssemblyDeclaration(System.String RootNamespace, vbnc.AssemblyDeclaration assembly)
   at vbnc.Parser.Parse(System.String RootNamespace, vbnc.AssemblyDeclaration assembly)
   at vbnc.Compiler.Compile_Parse()
   at vbnc.Compiler.Compile()
   at vbnc.Compiler.Compile(System.String[] CommandLine)
   at vbnc.Main.Main(System.String[] CmdArgs)
/home/fVMSh9/<MyGenerator> (1,13) : error VBNC90019: Expected 'End'.
/home/fVMSh9/<MyGenerator> (1,13) : error VBNC90019: Expected 'End'.
There were 5 errors and 0 warnings.
Compilation took 00:00:00.6510330
stdout
Standard output is empty