VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Stream"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Private mHandle As Long
Private mUsr

Public Enum BassStreamProcsConst
STREAMPROC_DUMMY = 0 ' "dummy" stream
STREAMPROC_PUSH = -1 ' push stream
End Enum

Public Enum BassStreamFileConst
STREAMFILE_NOBUFFER = 0
STREAMFILE_BUFFER = 1
STREAMFILE_BUFFERPUSH = 2
End Enum

Public Enum BassStreamConst
BASS_STREAM_PRESCAN = &H20000   ' enable pin-point seeking/length (MP3/MP2/MP1)
BASS_MP3_SETPOS = BASS_STREAM_PRESCAN
BASS_STREAM_AUTOFREE = &H40000 ' automatically free the stream when it stop/ends
BASS_STREAM_RESTRATE = &H80000 ' restrict the download rate of internet file streams
BASS_STREAM_BLOCK = &H100000   ' download/play internet file stream in small blocks
BASS_STREAM_DECODE = &H200000  ' don't play the stream, only decode (BASS_ChannelGetData)
BASS_STREAM_STATUS = &H800000  ' give server status info (HTTP/ICY tags) in DOWNLOADPROC
BASS_STREAMPROC_END = &H80000000 ' end of user stream flag
End Enum

Public Enum BassFileDataConst
BASS_FILEDATA_END = 0 ' end & close the file
End Enum

Public Enum BassFilePositionConst
BASS_FILEPOS_CURRENT = 0
BASS_FILEPOS_DECODE = BASS_FILEPOS_CURRENT
BASS_FILEPOS_DOWNLOAD = 1
BASS_FILEPOS_END = 2
BASS_FILEPOS_START = 3
BASS_FILEPOS_CONNECTED = 4
BASS_FILEPOS_BUFFER = 5
BASS_FILEPOS_SOCKET = 6
BASS_FILEPOS_ASYNCBUF = 7
BASS_FILEPOS_SIZE = 8
End Enum

Public Enum BassSampleConst
BASS_SAMPLE_8BITS = 1          ' 8 bit
BASS_SAMPLE_FLOAT = 256        ' 32-bit floating-point
BASS_SAMPLE_MONO = 2           ' mono
BASS_SAMPLE_LOOP = 4           ' looped
BASS_SAMPLE_3D = 8             ' 3D functionality
BASS_SAMPLE_SOFTWARE = 16      ' not using hardware mixing
BASS_SAMPLE_MUTEMAX = 32       ' mute at max distance (3D only)
BASS_SAMPLE_VAM = 64           ' DX7 voice allocation & management
BASS_SAMPLE_FX = 128           ' old implementation of DX8 effects
BASS_SAMPLE_OVER_VOL = &H10000 ' override lowest volume
BASS_SAMPLE_OVER_POS = &H20000 ' override longest playing
BASS_SAMPLE_OVER_DIST = &H30000 ' override furthest from listener (3D only)
End Enum

Private Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4() As Byte
End Type

Private Declare Function BASS_StreamCreate Lib "bass.dll" (ByVal Freq As Long, ByVal Chans As Long, ByVal Flags As Long, ByVal Proc As Long, ByVal User As Long) As Long
Private Declare Function BASS_StreamCreateFile64 Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Long, ByVal file As Any, ByVal Offset As Long, ByVal offsethigh As Long, ByVal Length As Long, ByVal lengthhigh As Long, ByVal Flags As Long) As Long
Private Declare Function BASS_StreamCreateURL Lib "bass.dll" (ByVal URL As String, ByVal Offset As Long, ByVal Flags As Long, ByVal Proc As Long, ByVal User As Long) As Long
Private Declare Function BASS_StreamCreateFileUser Lib "bass.dll" (ByVal System As Long, ByVal Flags As Long, ByVal procs As Long, ByVal User As Long) As Long
Private Declare Function BASS_StreamFree Lib "bass.dll" (ByVal Handle As Long) As Long
Private Declare Function BASS_StreamGetFilePosition Lib "bass.dll" (ByVal Handle As Long, ByVal Mode As Long) As Long
Private Declare Function BASS_StreamPutData Lib "bass.dll" (ByVal Handle As Long, ByRef Buffer As Any, ByVal Length As Long) As Long
Private Declare Function BASS_StreamPutFileData Lib "bass.dll" (ByVal Handle As Long, ByRef Buffer As Any, ByVal Length As Long) As Long

Sub Create(Freq As Long, Chans As Long, Flags As Long)
mHandle = BASS_StreamCreate(Freq, Chans, Flags, AddressOf STREAMPROC, mUsr)
End Sub

Sub CreateFileUser(System As BassStreamFileConst, Optional Flags As Long = 0)

Dim bprcs As BASS_FILEPROCS
Dim User

bprcs.close_ = GetAddressPtr(AddressOf FILECLOSEPROC)
bprcs.Length = GetAddressPtr(AddressOf FILELENPROC)
bprcs.read = GetAddressPtr(AddressOf FILEREADPROC)
bprcs.Seek_ = GetAddressPtr(AddressOf FILESEEKPROC)

mHandle = BASS_StreamCreateFileUser(System, Flags, VarPtr(bprcs), mUsr)

End Sub

Sub CreateURL(URL As String, Optional Offset As Long = 0, Optional Flags As Long = 0)
Dim User
mHandle = BASS_StreamCreateURL(URL, Offset, Flags, AddressOf DOWNLOADPROC, mUsr)
End Sub

Function Free() As Boolean
Free = BASS_StreamFree(mHandle)
End Function

Function GetFilePosition(Mode As BassFilePositionConst) As Long
GetFilePosition = BASS_StreamGetFilePosition(mHandle, Mode)
End Function

Function PutData(Buffer, Length As Long) As Long
PutData = BASS_StreamPutData(mHandle, Buffer, Length)
End Function

Function PutFileData(Buffer, Length As Long) As Long
PutFileData = BASS_StreamPutFileData(mHandle, Buffer, Length)
End Function

Property Get Handle() As Long
Handle = mHandle
End Property

Property Get UserData()
UserData = mUsr
End Property

Sub CreateFile(ByVal Filename As String, Optional ByVal Offset As Long = 0, Optional ByVal Length As Long = 0, Optional ByVal Flags As Long = 0)
mHandle = BASS_StreamCreateFile64(BASS_FALSE, StrPtr(Filename), Offset, 0, Length, 0, Flags Or BASS_UNICODE)
End Sub

