|
sak2005
Posts: 82
|
 |
« on: 12 Jun '12 - 03:13 » |
Quote
|
Example: Public Class Form1
Private Declare Function BASS_Init Lib "bass.dll" (ByVal device As Integer, ByVal freq As UInteger, ByVal flags As UInteger, ByVal win As IntPtr, ByVal clsid As UInteger) As Boolean Private Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As IntPtr) As Integer Private Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean Private Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean Private Declare Function BASS_ChannelPause Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean Private Declare Function BASS_StreamCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Boolean, ByVal file As String, ByVal offset As UInteger, ByVal offsethigh As UInteger, ByVal length As UInteger, ByVal lengthhigh As UInteger, ByVal flags As UInteger) As IntPtr Private BASS_STREAM_PRESCAN As UInteger = &H20000 Private BASS_STREAM_AUTOFREE As UInteger = &H40000 Private stream As IntPtr
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load BASS_Init(-1, 44100, 1024, IntPtr.Zero, Nothing) End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click stream = BASS_StreamCreateFile(False, TextBox1.Text, 0, 0, 0, 0, BASS_STREAM_AUTOFREE Or BASS_STREAM_PRESCAN) Try BASS_ChannelPlay(stream, True) Timer1.Enabled = True Catch End Try End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim valZero As Integer = 0 BASS_ChannelStop(stream, True) ProgressBar1.Value = valZero ProgressBar2.Value = valZero Timer1.Enabled = False End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click OpenFileDialog1.Filter = "Mp3 File(*.mp3)|*.mp3" If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = OpenFileDialog1.FileName End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim level, left, right As Integer level = BASS_ChannelGetLevel(stream) left = LoWord(level) right = HiWord(level) Try ProgressBar1.Value = Math.Round(left / 100 / 100 * 20) ProgressBar2.Value = Math.Round(right / 100 / 100 * 20) Catch End Try End Sub
Private Function LoWord(ByVal lparam As Long) As Long LoWord = lparam And &HFFFF& End Function
Private Function HiWord(ByVal lparam As Long) As Long If lparam < 0 Then HiWord = (lparam \ &H10000 - 1) And &HFFFF& Else HiWord = lparam \ &H10000 End If End Function End Class ============================================================== Example: For bass register with out splash screen. You wanted contect: Un4Seen ports System Imports Un4seen.Bass
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Un4seen.Bass.BassNet.Registration("test@gmail.com", "2XXXXXXXXXXXXXX") Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) Me.Text = "Basic BASS Audio" 'Me.Size = New Size(300, 130) Me.MaximizeBox = False Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink Me.TopMost = True Me.CenterToScreen() Button1.Text = "Open" Button2.Text = "Pause" Button3.Text = "Stop" Button1.Cursor = Cursors.Hand Button2.Cursor = Cursors.Hand Button3.Cursor = Cursors.Hand Label1.Text = "L" Label2.Text = "R" TextBox1.Text = 0 TextBox2.Text = 0 End Sub
Private stream As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Bass.BASS_Start() With OpenFileDialog1 .Title = "Open" .FileName = "" .Filter = "Song files(*.mp3)|*.mp3" .RestoreDirectory = 2 End With Select Case Button1.Text Case "Open" If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then stream = Bass.BASS_StreamCreateFile(OpenFileDialog1.FileName, 0, 0, BASSFlag.BASS_DEFAULT) If stream <> 0 Then Button1.Text = "Play" Exit Sub End If End If Case "Play" Bass.BASS_ChannelPlay(stream, False) Timer1.Enabled = True End Select End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = False If Bass.BASS_ChannelPause(stream) Then ProgressBar1.Value = 0 ProgressBar2.Value = 0 TextBox1.Text = 0 TextBox2.Text = 0
End If End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If Bass.BASS_Stop() Then ProgressBar1.Value = 0 ProgressBar2.Value = 0 TextBox1.Text = 0 TextBox2.Text = 0 Timer1.Enabled = False Button1.Text = "Open" End If End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim level As Integer = Bass.BASS_ChannelGetLevel(stream) Dim left As Double = Utils.LowWord32(level) Dim right As Double = Utils.HighWord32(level) ProgressBar1.Value = Math.Round(left / 200 / 2) ProgressBar2.Value = Math.Round(right / 200 / 2) Timer1.Interval = 50 End Sub End Class
|
|
|
|
« Last Edit: 17 Jun '12 - 02:04 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #1 on: 17 Jun '12 - 02:07 » |
Quote
|
Example: BassClass & BassForm VB.NET Programming BassClass: Imports System.Runtime.InteropServices Public Class BassClass 'Declare Function BASS_Init Lib "bass.dll" (ByVal device As Integer, ByVal freq As UInteger, ByVal flags As UInteger, ByVal win As IntPtr, ByVal clsid As UInteger) As Boolean 'Declare Function BASS_StreamCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Boolean, ByVal file As String, ByVal offset As UInteger, ByVal offsethigh As UInteger, ByVal length As UInteger, ByVal lengthhigh As UInteger, ByVal flags As UInteger) As IntPtr 'Private Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As IntPtr, ByVal mode As Single()) As Integer 'Private Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean 'Private Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean Public Shared Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BassInit, ByVal win As System.IntPtr) As Boolean Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero) End Function
<DllImport("bass.dll")> _ Private Shared Function BASS_Init(ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BassInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean End Function
<DllImport("bass.dll")> _ Shared Function BASS_StreamCreateFile(ByVal mem As Boolean, ByVal file As String, ByVal offset As UInteger, ByVal offsethigh As UInteger, ByVal length As UInteger, ByVal lengthhigh As UInteger, ByVal flags As UInteger) As IntPtr End Function
<DllImport("bass.dll", EntryPoint:="BASS_Init", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.[Auto], SetLastError:=False)> _ Private Shared Function BASS_InitGuid(<MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BassInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.Guid) As Boolean End Function
<DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile")> _ Public Shared Function BASS_StreamCreateFileMemory(ByVal A_0 As Boolean, ByVal A_1 As System.IntPtr, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer End Function
<DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile", ExactSpelling:=True, CharSet:=CharSet.[Auto], SetLastError:=False)> _ Private Shared Function BASS_StreamCreateFileUnicode(ByVal A_0 As Boolean, ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelGetLevel(ByVal handle As Integer) As Integer End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelPlay(ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelStop(ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelPause(ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelGetPosition(ByVal handle As Integer, ByVal mode As BASSMode) As Long End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelGetLength(ByVal handle As Integer, ByVal mode As BASSMode) As Long End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelBytes2Seconds(ByVal handle As Integer, ByVal pos As Long) As Double End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelSeconds2Bytes(ByVal handle As Integer, ByVal pos As Double) As Long End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_ChannelSetPosition(ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_GetVolume() As Single End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_SetVolume(ByVal A_0 As Single) As Boolean End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_Free() As Boolean End Function
<DllImport("bass.dll")> _ Public Shared Function BASS_Start() As Boolean End Function
Public Shared Function HighWord(ByVal dWord As Integer) As Integer Return (dWord >> 16) And 65535 End Function
Public Shared Function LowWord(ByVal dWord As Integer) As Integer Return dWord And 65535 End Function
Public Shared Function BASS_StreamCreateFileA(ByVal [file] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer flags = flags Or BASSFlag.BASS_UNICODE Return BASS_StreamCreateFileUnicode(False, [file], offset, length, flags) End Function
Public Shared Function SecToTime(ByVal Seconds As Integer, Optional ByRef rHour As Integer = 0, Optional ByRef rMinute As Integer = 0, Optional ByRef rSecond As Integer = 0) As String rHour = (Seconds \ 3600) rMinute = (Seconds - (rHour * 3600)) \ 60 rSecond = (Seconds - (rHour * 3600) - (rMinute * 60)) SecToTime = Format(rMinute, "00") & ":" & Format(rSecond, "00") End Function <Flags()> _ Public Enum BassInit BASS_DEVICE_DEFAULT = 0 BASS_DEVICE_8BITS = 1 BASS_DEVICE_MONO = 2 BASS_DEVICE_LATENCY = 256 BASS_DEVICE_CPSPEAKERS = 1024 BASS_DEVICE_SPEAKERS = 2048 BASS_DEVICE_NOSPEAKER = 4096 End Enum <Flags()> _ Public Enum BASSFlag BASS_DEFAULT = 0 BASS_SAMPLE_FLOAT = 256 BASS_STREAM_PRESCAN = 131072 BASS_STREAM_AUTOFREE = 262144 BASS_UNICODE = -2147483648 End Enum <Flags()> _ Public Enum BASSMode BASS_POS_BYTES = 0 BASS_POS_MUSIC_ORDERS = 1 BASS_POS_MIDI_TICK = 2 End Enum End Class BassForm: Imports WindowsApplication1.BassClass Public Class BassForm Public Declare Function SendMessageW Lib "user32" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr Public Const APPCOMMAND_VOLUME_MUTE_DOWN As Integer = &HA0000 Public Const APPCOMMAND_VOLUME_MUTE As Integer = &H80000 Public Const WM_APPCOMMAND As Integer = &H319 Public stream As Integer Public ProgressZero As Integer Public percent As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TrackBar2.Value = 10 Me.Size = New Size(367, 200) Me.Text = "BASS Sound Sample" Me.MaximizeBox = False Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink BASS_SetVolume(0) Button1.Text = "Open" Button2.Text = "Play" Button3.Text = "Stop" Button4.Text = "Mute" Label1.Text = "0%" Label2.Text = "00:00" Label3.Text = "00:00" Button1.Cursor = Cursors.Hand Button2.Cursor = Cursors.Hand Button3.Cursor = Cursors.Hand Button4.Cursor = Cursors.Hand Me.CenterToScreen() End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If percent = 0 Then If stream <> 0 Then BASS_ChannelPlay(stream, True) Timer1.Enabled = True End If End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click percent = 0 With OpenFileDialog1 .Filter = ("SongFile(*.mp3)|*.mp3") .FileName = "" End With If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then BASS_Free() ProgressBar1.Value = ProgressZero ProgressBar2.Value = ProgressZero BASS_Init(-1, 44100, BassInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) stream = BASS_StreamCreateFileA(OpenFileDialog1.FileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_STREAM_PRESCAN) If stream Then BASS_GetVolume() Dim len As Long = BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTES) Dim pos As Long = BASS_ChannelGetPosition(stream, BASSMode.BASS_POS_BYTES) Dim totaltime As Double = BASS_ChannelBytes2Seconds(stream, len) Dim elapsedtime As Double = BASS_ChannelBytes2Seconds(stream, pos) Dim remainingtime As Double = totaltime - elapsedtime Label2.Text = SecToTime(remainingtime, remainingtime, remainingtime) End If End If End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If stream <> 0 Then BASS_Free() BASS_ChannelStop(stream, True) ProgressBar1.Value = ProgressZero ProgressBar2.Value = ProgressZero TrackBar1.Value = 0 Label1.Text = "0%" Label2.Text = "00:00" Label3.Text = "00:00" Timer1.Enabled = False End If End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim level As Integer = BASS_ChannelGetLevel(stream) Dim left As Integer = LowWord(level) Dim right As Integer = HighWord(level) Dim len As Long = BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTES) Dim pos As Long = BASS_ChannelGetPosition(stream, BASSMode.BASS_POS_BYTES) Dim totaltime As Double = BASS_ChannelBytes2Seconds(stream, len) Dim elapsedtime As Double = BASS_ChannelBytes2Seconds(stream, pos) Dim remainingtime As Double = totaltime - elapsedtime Label3.Text = SecToTime(remainingtime, remainingtime, remainingtime) percent = Math.Round((pos / len) * 100, 0) TrackBar1.Value = percent Label1.Text = String.Concat(percent, "%") If TrackBar1.Value >= 100 Then BASS_ChannelPlay(stream, True) 'BASS_ChannelPause(stream, True) End If Try ProgressBar1.Value = (Math.Round(left, 3) / 1000 * 3) ProgressBar2.Value = (Math.Round(right, 3) / 1000 * 3) Timer1.Interval = 30 Catch End Try End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Select Case Button4.Text Case "Mute" SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_MUTE, IntPtr)) Button4.Text = "UnMute" Button4.ForeColor = Color.Red Case "UnMute" SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_MUTE, IntPtr)) Button4.Text = "Mute" Button4.ForeColor = Color.Black End Select End Sub
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll BASS_SetVolume(TrackBar2.Value / 10).ToString() End Sub End Class
|
|
|
|
« Last Edit: 22 Jun '12 - 06:23 by sak2005 »
|
Logged
|
|
|
|
|
gnag
Posts: 160
|
 |
« Reply #2 on: 17 Jun '12 - 18:02 » |
Quote
|
Its nice that you share your code with us by why would someone need to implement a .NET Wrapper for BASS if there is already the existing, working and well-documented BASS.NET Component existing which is basically already what you started?
But nevertheless it looks like you know about what you are doing.
|
|
|
|
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #3 on: 22 Jun '12 - 06:24 » |
Quote
|
Try with windows multimedia winMM modify. Download: DLL and Sample project. Click here---------------------------------------------------------------- Download: WindowsMediaLib Sample project Click here---------------------------------------------------------------- Download: MediaControl.dll & Sample project Click here----------------------------------------------------------------------- Download: Basic MCI Sound Click here--------------------------------------------------------------------------------- Download: Basic nBASS Programming Click here
|
|
|
|
« Last Edit: 27 Jun '12 - 02:02 by sak2005 »
|
Logged
|
|
|
|
|
gnag
Posts: 160
|
 |
« Reply #4 on: 23 Jun '12 - 21:17 » |
Quote
|
The Peakmeter looks nice, how did you made that out of which Controls ? However when I open a Music (MP3 File) and try to click Play it displays me this message and I only hear some distorted seconds of Playback: 
|
|
|
|
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #5 on: 24 Jun '12 - 04:18 » |
Quote
|
You must select song file before click play button.
If not select song file. Message will show.
If you wanted modify. Skip command message now.
Example: //MessageBox.Show("คุณยังไม่ได้เลือกเพลง"); -------------------------------------------------- [Basic Programming From Thailand]
|
|
|
|
« Last Edit: 24 Jun '12 - 04:50 by sak2005 »
|
Logged
|
|
|
|
|
gnag
Posts: 160
|
 |
« Reply #6 on: 24 Jun '12 - 17:25 » |
Quote
|
I selected a File like I said and it did display that Message !
|
|
|
|
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #7 on: 27 Jun '12 - 11:00 » |
Quote
|
nBASS Level Progress Meter Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim posBytes As Integer = BASS_ChannelGetPosition(strm) Dim lenBytes As Integer = BASS_StreamGetLength(strm) lblPos.Text = "Position: " & BASS_ChannelBytes2Seconds(strm, posBytes) & " / " & BASS_ChannelBytes2Seconds(strm, lenBytes) barPos.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm)) If posBytes = lenBytes Then BASS_StreamPlay(strm, 0, 0) Dim levelL As Integer = BASS_ChannelGetLevel(strm) Dim levelR As Integer = BASS_ChannelGetLevel(strm) Dim peakL As Integer = GetLoWord(levelL) Dim peakR As Integer = GetHiWord(levelR) Try ProgressBar1.Value = Math.Round(peakL) / 1.3 ProgressBar2.Value = Math.Round(peakR) / 1.3 Timer1.Interval = 35 Catch End Try End Sub ======================================================= nBASS Mouse Slide Scroll Position Private Sub barPos_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles barPos.Scroll BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, barPos.Value)) End Sub ======================================================== nBASS Mouse Slide Srcoll Volume Private Sub barVol_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles barVol.Scroll BASS_SetVolume(barVol.Value) lblVol.Text = "Volume: " & barVol.Value & "%" End Sub ========================================================== nBASS Mouse Slide Scroll Volume Balance You must set properties barBal.Minimum = -100 Private Sub barBal_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles barBal.Scroll Dim a As String = Nothing BASS_ChannelSetAttributes(strm, -1, -1, barBal.Value) Select Case barBal.Value Case Is < 0 lblBal.Text = "Balance: Left: " & barBal.Value & "%" Case Is > 0 lblBal.Text = "Balance: Right: " & barBal.Value & "%" Case Else lblBal.Text = "Balance: Center: " & barBal.Value & "%" End Select End Sub
|
|
|
|
« Last Edit: 27 Jun '12 - 13:11 by sak2005 »
|
Logged
|
|
|
|
|
Gamo
Posts: 86
|
 |
« Reply #8 on: 27 Jun '12 - 13:52 » |
Quote
|
Why not put your project file?
|
|
|
|
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #9 on: 27 Jun '12 - 16:30 » |
Quote
|
Project Files is Download
|
|
|
|
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #10 on: 27 Jun '12 - 18:15 » |
Quote
|
Info: nbass.dll has 2 versions. 0.9.6.1 and 1.8.0.0 ..It's bass.net.dll ..Create from vb.net You must select to use. bass.dll It's Lib.dll ..Create from C++ Support nbass 2 versions. ------------------------------------------------------------------ Tip: If you create program project and before run debug you must add file.net.dll and file.dll in to debug folder of your the project. The writting code made 2 ways 1. Create Class or Module 2. Referents file.net.dll into the Visual Studio.
|
|
|
|
« Last Edit: 27 Jun '12 - 18:38 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #11 on: 27 Jun '12 - 18:54 » |
Quote
|
Easy bass Sample : Three in OneTouchButton (Open , Play and Stop) Unuse nBass.net.dll Add bass.dll in to the debug folder. Public Class Form1 Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer Public strm As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case Button1.Text Case "Open" Dim fileDLG As New OpenFileDialog() With fileDLG .FileName = "" .Filter = "Song file(*.mp3)|*.mp3" End With If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32) BASS_ChannelStart() strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0) Button1.Text = "Play" End If Case "Play" If strm <> 0 Then BASS_ChannelPlay(strm, 0, 0) Button1.Text = "Stop" End If Case "Stop" If strm <> 0 Then BASS_ChannelStop(strm) Button1.Text = "Open" End If End Select End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() Button1.Text = "Open" End Sub End Class
|
|
|
|
« Last Edit: 28 Jun '12 - 04:05 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #12 on: 28 Jun '12 - 04:16 » |
Quote
|
Step by step sample: Set TrackBar sound file position. Add TrackBar1 and Timer1 on the form. Public Class Form1 Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer Public strm As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() TrackBar1.TickStyle = TickStyle.None Button1.Text = "Open" End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case Button1.Text Case "Open" Dim fileDLG As New OpenFileDialog() With fileDLG .FileName = "" .Filter = "Song file(*.mp3)|*.mp3" End With If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32) BASS_ChannelStart() strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0) Button1.Text = "Play" End If Case "Play" If strm <> 0 Then BASS_ChannelPlay(strm, 0, 0) Button1.Text = "Stop" Timer1.Enabled = True TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm)) End If Case "Stop" If strm <> 0 Then BASS_ChannelStop(strm) Button1.Text = "Open" Timer1.Enabled = False End If End Select End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim sLen As Long = BASS_ChannelGetLength(strm) Dim sPos As Long = BASS_ChannelGetPosition(strm) Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen) Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos) TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm)) If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0) End If End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value)) End Sub End Class
|
|
|
|
« Last Edit: 28 Jun '12 - 06:50 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #13 on: 28 Jun '12 - 07:02 » |
Quote
|
Tip: TimeSpanEx function. Using for add systemTime and counter Timer or other. Function TimeSpanEx(ByVal hour As Integer, ByVal min As Integer, ByVal sec As Integer) Dim retValue As New TimeSpan(hour, min, sec) Return retValue.ToString() End Function ================================================== Example: SystemTime Add Timer1 on the form. Public Class Form1
Dim Label1 As New Label() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Controls.Add(Label1) Label1.Location = New Point(100, 100) Label1.Text = TimeSpanEx(0, 0, 0) Timer1.Enabled = True End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim hh As Integer = Now.Hour Dim mm As Integer = Now.Minute Dim ss As Integer = Now.Second Label1.Text = TimeSpanEx(hh, mm, ss) End Sub
Public Function TimeSpanEx(ByVal hour As Integer, ByVal min As Integer, ByVal sec As Integer) Dim retValue As New TimeSpan(hour, min, sec) Return retValue.ToString() End Function End Class ================================================== Example: Counter Timer Public Class Form1
Dim Label1 As New Label() Dim s As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Controls.Add(Label1) Label1.Location = New Point(100, 100) Label1.Text = TimeSpanEx(0, 0, 0) Timer1.Enabled = True End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim h As Integer = Nothing Dim m As Integer = Nothing s += 1 Label1.Text = TimeSpanEx(h, m, s) Timer1.Interval = 1000 End Sub
Public Function TimeSpanEx(ByVal hour As Integer, ByVal min As Integer, ByVal sec As Integer) Dim retValue As New TimeSpan(hour, min, sec) Return retValue.ToString() End Function End Class
|
|
|
|
« Last Edit: 30 Jun '12 - 11:50 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #14 on: 28 Jun '12 - 07:05 » |
Quote
|
Step by step: Set Progress Level meter. Add ProgressBar1 and ProgressBar2 on the form. Public Class Form1 Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer
Public Function HiWord(ByRef lparam As Integer) As Integer HiWord = lparam \ &H10000 And &HFFFF End Function Public Function LoWord(ByRef lparam As Integer) As Integer LoWord = lparam And &HFFFF End Function
Public strm As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() TrackBar1.TickStyle = TickStyle.None Button1.Text = "Open" End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case Button1.Text Case "Open" Dim fileDLG As New OpenFileDialog() With fileDLG .FileName = "" .Filter = "Song file(*.mp3)|*.mp3" End With If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32) BASS_ChannelStart() strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0) Button1.Text = "Play" End If Case "Play" If strm <> 0 Then BASS_ChannelPlay(strm, 0, 0) Button1.Text = "Stop" Timer1.Enabled = True TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm)) End If Case "Stop" If strm <> 0 Then BASS_ChannelStop(strm) Button1.Text = "Open" Timer1.Enabled = False ProgressBar1.Value = 0 ProgressBar2.Value = 0 TrackBar1.Value = 0 End If End Select End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim sLen As Long = BASS_ChannelGetLength(strm) Dim sPos As Long = BASS_ChannelGetPosition(strm) Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen) Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos) TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm)) If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0) Dim levels As Integer = BASS_ChannelGetLevel(strm) Dim RightChLvl As Integer = LoWord(levels) Dim rightChLvlper As Double = Math.Round((RightChLvl / 32768) * 25000, 0) Dim LeftChLvl As Integer = HiWord(levels) Dim leftChLvlper As Double = Math.Round((LeftChLvl / 32768) * 25000, 0) Try ProgressBar1.Value = rightChLvlper ProgressBar2.Value = leftChLvlper Timer1.Interval = 50 Catch End Try End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value)) End Sub End Class
|
|
|
|
« Last Edit: 28 Jun '12 - 08:30 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #15 on: 28 Jun '12 - 08:34 » |
Quote
|
Step by step: Set sound timer. Add Label1 and Label2 on the form. Public Class Form1 Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer
Public Function HiWord(ByRef lparam As Integer) As Integer HiWord = lparam \ &H10000 And &HFFFF End Function Public Function LoWord(ByRef lparam As Integer) As Integer LoWord = lparam And &HFFFF End Function
Public Function TimeCalculation(ByVal intSecond As Integer) As String Dim v_i As Integer Dim v_i1 As Integer Dim v_str As String Dim v_str1 As String Dim v_arrstr As String() v_i = intSecond / 3600 v_i1 = intSecond / 60 v_i1 = v_i1 Mod 60 intSecond = intSecond Mod 60 v_arrstr = New String(4) {} v_arrstr(0) = v_i.ToString("00") v_arrstr(1) = ":" v_arrstr(2) = v_i1.ToString("00") v_arrstr(3) = ":" v_arrstr(4) = intSecond.ToString("00") v_str = String.Concat(v_arrstr) v_str1 = v_str Return v_str1 End Function
Public strm As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() Label1.Text = "00:00:00" Label2.Text = "00:00:00" Label1.BackColor = Color.White Label2.BackColor = Color.White Label1.BorderStyle = BorderStyle.Fixed3D Label2.BorderStyle = BorderStyle.Fixed3D TrackBar1.TickStyle = TickStyle.None Button1.Text = "Open" End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case Button1.Text Case "Open" Dim fileDLG As New OpenFileDialog() With fileDLG .FileName = "" .Filter = "Song file(*.mp3)|*.mp3" End With If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32) BASS_ChannelStart() strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0) Button1.Text = "Play" End If Case "Play" If strm <> 0 Then BASS_ChannelPlay(strm, 0, 0) Button1.Text = "Stop" Timer1.Enabled = True TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm)) End If Case "Stop" If strm <> 0 Then BASS_ChannelStop(strm) Button1.Text = "Open" Timer1.Enabled = False ProgressBar1.Value = 0 ProgressBar2.Value = 0 TrackBar1.Value = 0 End If End Select End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim sLen As Long = BASS_ChannelGetLength(strm) Dim sPos As Long = BASS_ChannelGetPosition(strm) Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen) Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos) TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm)) If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0) Label1.Text = TimeCalculation(cPos) Label2.Text = TimeCalculation(cLen) Dim levels As Integer = BASS_ChannelGetLevel(strm) Dim RightChLvl As Integer = LoWord(levels) Dim rightChLvlper As Double = Math.Round((RightChLvl / 32768) * 25000, 0) Dim LeftChLvl As Integer = HiWord(levels) Dim leftChLvlper As Double = Math.Round((LeftChLvl / 32768) * 25000, 0) Try ProgressBar1.Value = rightChLvlper ProgressBar2.Value = leftChLvlper Timer1.Interval = 50 Catch End Try End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value)) End Sub End Class
|
|
|
|
« Last Edit: 28 Jun '12 - 09:47 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #16 on: 28 Jun '12 - 10:02 » |
Quote
|
Step by step: Set sound volume Add TrackBar2 on the form. Public Class Form1 Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer Declare Function BASS_GetVolume Lib "bass.dll" () As Integer Declare Function BASS_SetVolume Lib "bass.dll" (ByVal volume As Integer) As Integer
Public Function HiWord(ByRef lparam As Integer) As Integer HiWord = lparam \ &H10000 And &HFFFF End Function Public Function LoWord(ByRef lparam As Integer) As Integer LoWord = lparam And &HFFFF End Function
Public Function TimeCalculation(ByVal intSecond As Integer) As String Dim v_i As Integer Dim v_i1 As Integer Dim v_str As String Dim v_str1 As String Dim v_arrstr As String() v_i = intSecond / 3600 v_i1 = intSecond / 60 v_i1 = v_i1 Mod 60 intSecond = intSecond Mod 60 v_arrstr = New String(4) {} v_arrstr(0) = v_i.ToString("00") v_arrstr(1) = ":" v_arrstr(2) = v_i1.ToString("00") v_arrstr(3) = ":" v_arrstr(4) = intSecond.ToString("00") v_str = String.Concat(v_arrstr) v_str1 = v_str Return v_str1 End Function
Public strm As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CenterToScreen() BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32) BASS_GetVolume() Label1.Text = "00:00:00" Label2.Text = "00:00:00" Label1.BackColor = Color.White Label2.BackColor = Color.White Label1.BorderStyle = BorderStyle.Fixed3D Label2.BorderStyle = BorderStyle.Fixed3D TrackBar1.TickStyle = TickStyle.None TrackBar2.Maximum = 100 TrackBar2.Value = 100 TrackBar2.TickStyle = TickStyle.Both Button1.Text = "Open" End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case Button1.Text Case "Open" Dim fileDLG As New OpenFileDialog() With fileDLG .FileName = "" .Filter = "Song file(*.mp3)|*.mp3" End With If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then BASS_ChannelStart() strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0) Button1.Text = "Play" End If Case "Play" If strm <> 0 Then BASS_ChannelPlay(strm, 0, 0) Button1.Text = "Stop" Timer1.Enabled = True TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm)) End If Case "Stop" If strm <> 0 Then BASS_ChannelStop(strm) Button1.Text = "Open" Timer1.Enabled = False ProgressBar1.Value = 0 ProgressBar2.Value = 0 TrackBar1.Value = 0 Label1.Text = "00:00:00" Label2.Text = "00:00:00" End If End Select End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim sLen As Long = BASS_ChannelGetLength(strm) Dim sPos As Long = BASS_ChannelGetPosition(strm) Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen) Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos) TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm)) If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0) Label1.Text = TimeCalculation(cPos) Label2.Text = TimeCalculation(cLen) Dim levels As Integer = BASS_ChannelGetLevel(strm) Dim RightChLvl As Integer = LoWord(levels) Dim rightChLvlper As Double = Math.Round((RightChLvl / 32768) * 25000, 0) Dim LeftChLvl As Integer = HiWord(levels) Dim leftChLvlper As Double = Math.Round((LeftChLvl / 32768) * 25000, 0) Try ProgressBar1.Value = rightChLvlper ProgressBar2.Value = leftChLvlper Timer1.Interval = 50 Catch End Try End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value)) End Sub
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll BASS_SetVolume(TrackBar2.Value) End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing If strm <> 0 Then TrackBar2.Value = 0 BASS_ChannelStop(strm) Else BASS_ChannelStop(strm) End If End Sub End Class
|
|
|
|
« Last Edit: 28 Jun '12 - 11:06 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #17 on: 30 Jun '12 - 07:55 » |
Quote
|
Download: Get start DirectBass (Un4Seen) basic programming Click here
|
|
|
|
« Last Edit: 30 Jun '12 - 08:00 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #18 on: 30 Jun '12 - 08:17 » |
Quote
|
Imports System.Runtime.InteropServices Add this code on ClassForm1 without Bass Module Public strm As Integer Public Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As System.IntPtr) As Boolean Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero) End Function <DllImport("bass.dll", SetLastError:=False)> _ Private Shared Function BASS_Init(ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BASSInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean End Function Public Function BASS_StreamCreateFile(ByVal [file] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer flags = flags Or BASSFlag.BASS_UNICODE Return BASS_StreamCreateFileUnicode(False, [file], offset, length, flags) End Function <DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.[Auto], SetLastError:=False)> _ Private Shared Function BASS_StreamCreateFileUnicode(<MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal A_0 As Boolean, <MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer End Function <DllImport("bass.dll")> _ Public Shared Function BASS_StreamFree(ByVal A_0 As Integer) As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelPlay(ByVal A_0 As Integer, ByVal handle As Boolean) As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelPause(ByVal A_0 As Integer) As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelStop(ByVal handle As Integer) As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_Start() As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_Stop() As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelGetLevel(ByVal handle As Integer) As Integer End Function <DllImport("bass.dll", SetLastError:=False)> _ Public Shared Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelSeconds2Bytes(ByVal handle As Integer, ByVal pos As Double) As Long End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelBytes2Seconds(ByVal handle As Integer, ByVal pos As Long) As Double End Function Public Function BASS_ChannelGetLength(ByVal handle As Integer) As Long Return BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTES) End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelGetLength(ByVal handle As Integer, ByVal mode As BASSMode) As Long End Function Public Function BASS_ChannelGetPosition(ByVal handle As Integer) As Long Return BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES) End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelGetPosition(ByVal handle As Integer, ByVal mode As BASSMode) As Long End Function Public Function BASS_ChannelSetPosition(ByVal handle As Integer, ByVal pos As Long) As Boolean Return BASS_ChannelSetPosition(handle, pos, BASSMode.BASS_POS_BYTES) End Function <DllImport("bass.dll")> _ Public Shared Function BASS_ChannelSetPosition(ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean End Function <DllImport("bass.dll")> _ Public Shared Function BASS_GetVolume() As Single End Function <DllImport("bass.dll")> _ Public Shared Function BASS_SetVolume(ByVal A_0 As Single) As Boolean End Function Public Function FixTimespan(ByVal seconds As Double) As String Dim v_timeSpan As System.TimeSpan v_timeSpan = System.TimeSpan.FromSeconds(seconds) Return v_timeSpan.ToString End Function Public Function HighWord(ByVal dWord As Integer) As Short Return CShort((dWord >> 16) And 65535) End Function Public Function HighWord(ByVal qWord As Long) As Integer Return CInt((qWord >> 32) And -1) End Function Public Function HighWord32(ByVal dWord As Integer) As Integer Return (dWord >> 16) And 65535 End Function Public Function LowWord(ByVal dWord As Integer) As Short Return CShort(dWord And 65535) End Function Public Function LowWord(ByVal qWord As Long) As Integer Return CInt(qWord And -1) End Function Public Function LowWord32(ByVal dWord As Integer) As Integer Return dWord And 65535 End Function Public Function BASS_ChannelGetLevel(ByVal handle As Integer, ByVal level As Single()) As Boolean Dim v_i As Integer Dim v_arrsng As Single() Dim v_i1 As Integer Dim v_sng As Single Dim v_i2 As Integer If level.Length <= 0 Then GoTo ILO_0012 End If System.Array.Clear(level, 0, level.Length) GoTo ILO_0014 ILO_0012: Return False ILO_0014: v_i = CInt(BASS_ChannelSeconds2Bytes(handle, 0.02)) If v_i <= 0 Then GoTo ILO_0079 End If v_arrsng = New Single((v_i / 4) - 1) {} v_i = BASS_ChannelGetData(handle, v_arrsng, v_i Or 1073741824) v_i /= 4 v_i1 = 0 v_i2 = 0 GoTo ILO_0072 ILO_004c: v_sng = System.Math.Abs(v_arrsng(v_i2)) If v_sng <= level(v_i1) Then GoTo ILO_0060 End If level(v_i1) = v_sng ILO_0060: v_i1 += 1 If v_i1 < level.Length Then GoTo ILO_006c End If v_i1 = 0 ILO_006c: v_i2 += 1 ILO_0072: If v_i2 < v_i Then GoTo ILO_004c End If Return True ILO_0079: Return False End Function <Flags()> _ Public Enum BASSFlag BASS_DEFAULT = 0 BASS_SAMPLE_FLOAT = 256 BASS_STREAM_PRESCAN = 131072 BASS_STREAM_AUTOFREE = 262144 BASS_STREAM_STATUS = 8388608 BASS_UNICODE = -2147483648 BASS_MUSIC_MONO = 2 BASS_MUSIC_LOOP = 4 BASS_MUSIC_3D = 8 BASS_MUSIC_FX = 128 BASS_MUSIC_AUTOFREE = 262144 BASS_MUSIC_PRESCAN = 131072 BASS_MUSIC_POSRESET = 32768 End Enum <Flags()> _ Public Enum BASSInit BASS_DEVICE_DEFAULT = 0 BASS_DEVICE_CPSPEAKERS = 1024 BASS_DEVICE_SPEAKERS = 2048 BASS_DEVICE_NOSPEAKER = 4096 BASS_DEVICE_FREQ = 16384 End Enum <Flags()> _ Public Enum BASSMode BASS_POS_BYTES = 0 BASS_POS_MUSIC_ORDERS = 1 BASS_POS_MIDI_TICK = 2 BASS_MUSIC_POSRESET = 32768 BASS_MUSIC_POSRESETEX = 4194304 End Enum Bass form design. Use ImageList set Image all Buttons to use Writting code Sub New InitializeComponent Add code Create ImageList and Form Object Properties Without Form Load. Public Sub New() InitializeComponent() '-------------------- Form Object properties --------------------- Me.CenterToScreen() Me.Text = "Bass Un4Seen Sample" Me.MaximizeBox = False Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) Label1.Text = "SongName:" Label2.Text = "00:00:00" Label3.Text = "00:00:00" Label4.Text = "0%" TrackBar1.TickStyle = TickStyle.None Button1.Text = "" Button2.Text = "" Button3.Text = "" Button4.Text = "" BASS_GetVolume() ProgressBar1.Maximum = 100 ProgressBar2.Maximum = 100 TrackBar2.Maximum = 100 TrackBar2.Value = 100 '-------------------------------- ImageList Create ---------------------------- Dim ImageList1 As New ImageList() ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnOpen.ico")) Button1.ImageList = ImageList1 Button1.ImageIndex = 0 ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnPlay.ico")) Button2.ImageList = ImageList1 Button2.ImageIndex = 1 ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnPause.ico")) Button3.ImageList = ImageList1 Button3.ImageIndex = 2 ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnStop.ico")) Button4.ImageList = ImageList1 Button4.ImageIndex = 3 End Sub 
|
|
|
|
« Last Edit: 1 Jul '12 - 12:06 by sak2005 »
|
Logged
|
|
|
|
|
sak2005
Posts: 82
|
 |
« Reply #19 on: 2 Jul '12 - 10:29 » |
Quote
|
Get DirectBass(Un4Seen) Lib Function Command Public Class Form1 Declare Function BASS_Init Lib "bass.dll" (ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BASSInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean Declare Function BASS_StreamCreateFileUnicode Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal A_0 As Boolean, <MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer Declare Function BASS_StreamFree Lib "bass.dll" (ByVal A_0 As Integer) As Boolean Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Boolean) As Boolean Declare Function BASS_ChannelPause Lib "bass.dll" (ByVal A_0 As Integer) As Boolean Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As Integer) As Boolean Declare Function BASS_Start Lib "bass.dll" () As Boolean Declare Function BASS_Stop Lib "bass.dll" () As Boolean Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer Declare Function BASS_ChannelGetData Lib "bass.dll" (ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Double) As Long Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Double Declare Function BASS_ChannelGetLength Lib "bass.dll" (ByVal handle As Integer, ByVal mode As BASSMode) As Long Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal mode As BASSMode) As Long Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean Declare Function BASS_GetVolume Lib "bass.dll" () As Single Declare Function BASS_SetVolume Lib "bass.dll" (ByVal A_0 As Single) As Boolean Public strm As Integer Public Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As System.IntPtr) As Boolean Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero) End Function Public Function BASS_StreamCreateFile(ByVal [File] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer flags = flags Or BASSFlag.BASS_UNICODE Return BASS_StreamCreateFileUnicode(False, [File], offset, length, flags) End Function Public Function BASS_ChannelGetLength(ByVal handle As Integer) As Long Return BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTES) End Function Public Function BASS_ChannelGetPosition(ByVal handle As Integer) As Long Return BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES) End Function Public Function BASS_ChannelSetPosition(ByVal handle As Integer, ByVal pos As Long) As Boolean Return BASS_ChannelSetPosition(handle, pos, BASSMode.BASS_POS_BYTES) End Function Public Function FixTimespan(ByVal seconds As Double) As String Dim v_timeSpan As System.TimeSpan v_timeSpan = System.TimeSpan.FromSeconds(seconds) Return v_timeSpan.ToString End Function Public Function HighWord32(ByVal dWord As Integer) As Integer Return (dWord >> 16) And 65535 End Function Public Function LowWord32(ByVal dWord As Integer) As Integer Return dWord And 65535 End Function <Flags()> _ Public Enum BASSFlag BASS_DEFAULT = 0 BASS_SAMPLE_FLOAT = 256 BASS_STREAM_PRESCAN = 131072 BASS_STREAM_AUTOFREE = 262144 BASS_STREAM_STATUS = 8388608 BASS_UNICODE = -2147483648 BASS_MUSIC_LOOP = 4 BASS_MUSIC_AUTOFREE = 262144 BASS_MUSIC_PRESCAN = 131072 BASS_MUSIC_POSRESET = 32768 End Enum <Flags()> _ Public Enum BASSInit BASS_DEVICE_DEFAULT = 0 BASS_DEVICE_CPSPEAKERS = 1024 BASS_DEVICE_SPEAKERS = 2048 BASS_DEVICE_NOSPEAKER = 4096 BASS_DEVICE_FREQ = 16384 End Enum <Flags()> _ Public Enum BASSMode BASS_POS_BYTES = 0 BASS_POS_MUSIC_ORDERS = 1 BASS_MUSIC_POSRESET = 32768 BASS_MUSIC_POSRESETEX = 4194304 End Enum End Class
|
|
|
|
« Last Edit: 3 Jul '12 - 21:54 by sak2005 »
|
Logged
|
|
|
|
|