home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / WaveIn_Rec2001136152006.psc / clsSmooth.cls < prev    next >
Text File  |  2006-06-15  |  2KB  |  86 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsSmooth"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ' translated from the XMMS volume normalization plugin
  17. ' http://volnorm.sourceforge.net/
  18. '
  19. ' returns the average of an array of values
  20. ' (the XMMS version searches for the maximum
  21. '  and once it got it, it will return it forever,
  22. '  that's not what I want)
  23.  
  24. Private sngData()   As Single
  25. Private sngMax      As Single
  26. Private lngSize     As Long
  27. Private lngUsed     As Long
  28. Private lngCurrent  As Long
  29.  
  30. Public Sub SmoothNew( _
  31.     ByVal size As Long _
  32. )
  33.  
  34.     ReDim sngData(size - 1) As Single
  35.  
  36.     lngSize = size
  37.     lngCurrent = 0
  38.     lngUsed = 0
  39.     sngMax = 0
  40. End Sub
  41.  
  42. Public Sub SmoothAdd( _
  43.     ByVal Sample As Single _
  44. )
  45.  
  46.     ' /* Put the sample in the buffer */
  47.     sngData(lngCurrent) = Sample
  48.  
  49.     ' /* Adjust the sample stats */
  50.     lngCurrent = lngCurrent + 1
  51.  
  52.     If lngCurrent > lngUsed Then
  53.         lngUsed = lngUsed + 1
  54.     End If
  55.  
  56.     If lngCurrent >= lngSize Then
  57.         lngCurrent = lngCurrent Mod lngSize
  58.     End If
  59. End Sub
  60.  
  61. Public Function SmoothGetMax( _
  62. ) As Single
  63.  
  64.     Dim smoothed    As Single
  65.     Dim i           As Long
  66.  
  67.     ' /* Calculate the smoothed value */
  68.     For i = 0 To lngUsed - 1
  69.         smoothed = smoothed + sngData(i)
  70.     Next
  71.  
  72.     smoothed = smoothed / lngUsed
  73.  
  74.     ' /* If we haven't filled the smoothing buffer, dont save the max value. */
  75.     If lngUsed < lngSize Then
  76.         SmoothGetMax = smoothed
  77.         Exit Function
  78.     End If
  79.  
  80.     If sngMax < smoothed Then
  81.         sngMax = smoothed
  82.     End If
  83.  
  84.     SmoothGetMax = smoothed
  85. End Function
  86.