VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CBASS_TIME"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'//////////////////////////////////////////////////////////////////////////
' CBASS_TIME.cls - Copyright (c) 2001-2004 JOBnik! [Arthur Aminov, ISRAEL]
'                                          e-mail: jobnik@jobnik.tk
'
' Other sources: frmMemory.frm & SYNCtest.bas
'
' This VB Class Module, shows how to Get:
'   - Total Playing Time, in Seconds, of any Stream/Music
'   - Playing Position in Seconds
'   - a Function that will Convert Total Seconds into:
'       Hours:Minutes:Seconds   [01:25:50]
'   - and much more... :)
'   * Some Functions are Based on Ian Lucks 'C' Examples!
'//////////////////////////////////////////////////////////////////////////

Option Explicit

Dim info As BASS_CHANNELINFO

'Returns - Total duration from seconds as Time format: HH:MM:SS
Public Function GetTime(ByVal seconds As Long) As String
    Dim hour As Single, min As Single, sec As Single

    hour = seconds / 60 / 60
    sec = seconds Mod 60
    min = (hour - Int(hour)) * 60

    GetTime = Format(Int(hour), "00") & ":" & Format(Int(min), "00") & ":" & Format(Int(sec), "00")
End Function

'Returns - Playing position in seconds of a stream (not for music)
Public Function GetPlayingPos(ByVal handle As Long) As Single
    GetPlayingPos = BASS_ChannelBytes2Seconds(handle, BASS_ChannelGetPosition(handle))
End Function

'Returns - Total duration in seconds of stream/music
Public Function GetDuration(ByVal handle As Long) As Single
    Dim lens As Long

    lens = BASS_StreamGetLength(handle) 'Stream Length
    If lens = -1 Then lens = BASS_MusicGetLength(handle, BASSTRUE)  'Music Length

    GetDuration = BASS_ChannelBytes2Seconds(handle, lens)
End Function

'Returns - Bytes Per Second
Public Function GetBytesPerSecond(ByVal handle As Long) As Long
    Dim bps As Long

    Call BASS_ChannelGetAttributes(handle, bps, 0, 0)  'sample rate
    Call BASS_ChannelGetInfo(handle, info) 'stereo/mono, 8/16 bit flags

    bps = bps * IIf(info.chans > 2, 2, info.chans)
    If (info.flags And BASS_SAMPLE_8BITS) = 0 Then bps = bps * 2

    GetBytesPerSecond = bps
End Function

'Returns - Kilo Bits Per Second
Public Function GetBitsPerSecond(ByVal handle As Long, ByVal FileLength As Long) As Long
    GetBitsPerSecond = CInt(((FileLength * 8) / GetDuration(handle)) / 1000)
End Function

'Returns - 'Stereo'/'Mono' or 'MultiChannel'
Public Function GetMode(ByVal handle As Long) As String
    Call BASS_ChannelGetInfo(handle, info)
    Select Case info.chans
        Case 1: GetMode = "Mono"
        Case 2: GetMode = "Stereo"
        Case Else: GetMode = info.chans & " MultiChannel"
    End Select
End Function

'Returns - 8/16 bits
Public Function GetBits(ByVal handle As Long) As Byte
    Call BASS_ChannelGetInfo(handle, info)
    GetBits = IIf(info.flags And BASS_SAMPLE_8BITS, 8, 16)
End Function

'Returns - Sample Rate [Frequency]
Public Function GetFrequency(ByVal handle As Long) As Long
    Call BASS_ChannelGetAttributes(handle, GetFrequency, 0, 0)
End Function

'Returns - DirectX version
Public Function GetDXver() As Byte
    Dim bi As BASS_INFO
    bi.size = LenB(bi)      'LenB(..) returns a byte data
    Call BASS_GetInfo(bi)
    GetDXver = bi.dsver
End Function
