Advertisement
meanhacker

cbass_time (cbass_time.cls)

Mar 12th, 2011
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '////////////////////////////////////////////////////////////////////////////////
  2. ' cbass_time.cls - Copyright (c) 2001-2007 (: JOBnik! :) [Arthur Aminov, ISRAEL]
  3. '                                                        [http://www.jobnik.org]
  4. '                                                        [  jobnik@jobnik.org  ]
  5. '
  6. ' Other sources: frmMemory.frm & SYNCtest.bas
  7. '
  8. ' This VB class module, shows how to get:
  9. '  * Total playing time, in seconds, of any stream/music
  10. '  * Playing position in seconds
  11. '  * A function that will convert total seconds into:
  12. '       Hours:Minutes:Seconds   [01:25:50]
  13. '  * and much more... :)
  14. '
  15. '  * Some functions are based on Ian Lucks 'C' examples!
  16. '////////////////////////////////////////////////////////////////////////////////
  17.  
  18. Option Explicit
  19.  
  20. Dim info As BASS_CHANNELINFO
  21.  
  22. ' Returns - Total duration from seconds as Time format: HH:MM:SS
  23. Public Function GetTime(ByVal seconds As Long) As String
  24.     Dim hour As Single, min As Single, sec As Single
  25.  
  26.     hour = seconds / 60 / 60
  27.     sec = seconds Mod 60
  28.     min = (hour - Int(hour)) * 60
  29.  
  30.     GetTime = Format(Int(hour), "00") & ":" & Format(Int(min), "00") & ":" & Format(Int(sec), "00")
  31. End Function
  32.  
  33. ' Returns - Playing position in seconds
  34. Public Function GetPlayingPos(ByVal handle As Long) As Single
  35.     GetPlayingPos = BASS_ChannelBytes2Seconds(handle, BASS_ChannelGetPosition(handle, BASS_POS_BYTE))
  36. End Function
  37.  
  38. ' Returns - Total duration in seconds
  39. Public Function GetDuration(ByVal handle As Long) As Single
  40.     GetDuration = BASS_ChannelBytes2Seconds(handle, BASS_ChannelGetLength(handle, BASS_POS_BYTE))
  41. End Function
  42.  
  43. ' Returns - Bytes Per Second
  44. Public Function GetBytesPerSecond(ByVal handle As Long) As Long
  45.     Dim bps As Long
  46.  
  47.     Call BASS_ChannelGetInfo(handle, info) ' stereo/mono, 8/16 bit flags
  48.  
  49.     bps = info.freq * info.chans
  50.     If (info.flags And BASS_SAMPLE_8BITS) = 0 Then bps = bps * 2
  51.  
  52.     GetBytesPerSecond = bps
  53. End Function
  54.  
  55. ' Returns - Kilo Bits Per Second
  56. Public Function GetBitsPerSecond(ByVal handle As Long, ByVal FileLength As Long) As Long
  57.     GetBitsPerSecond = CInt(((FileLength * 8) / GetDuration(handle)) / 1000)
  58. End Function
  59.  
  60. ' Returns - 'Stereo'/'Mono' or 'MultiChannel'
  61. Public Function GetMode(ByVal handle As Long) As String
  62.     Call BASS_ChannelGetInfo(handle, info)
  63.     Select Case info.chans
  64.         Case 1: GetMode = "Mono"
  65.         Case 2: GetMode = "Stereo"
  66.         Case Else: GetMode = info.chans & " MultiChannel"
  67.     End Select
  68. End Function
  69.  
  70. ' Returns - 8/16/32-float bits
  71. Public Function GetBits(ByVal handle As Long) As Byte
  72.     Call BASS_ChannelGetInfo(handle, info)
  73.         If (info.flags And BASS_SAMPLE_8BITS) Then
  74.             GetBits = 8
  75.         ElseIf (info.flags And BASS_SAMPLE_FLOAT) Then
  76.             GetBits = 32
  77.         Else
  78.             GetBits = 16
  79.         End If
  80. End Function
  81.  
  82. ' Returns - Sample Rate [Frequency]
  83. Public Function GetFrequency(ByVal handle As Long) As Long
  84.     Dim freq As Single
  85.     Call BASS_ChannelGetAttribute(handle, BASS_ATTRIB_FREQ, freq)
  86.     GetFrequency = freq
  87. End Function
  88.  
  89. ' Returns - DirectX version
  90. Public Function GetDXver() As Byte
  91.     Dim bi As BASS_INFO
  92.     Call BASS_GetInfo(bi)
  93.     GetDXver = bi.dsver
  94. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement