+ private int _stream;
+ // create a BPMCounter instance, the timer will be fired every 20ms
+ private BPMCounter _bpm = new BPMCounter(20, 44100);
+ ...
+ // create a stream
+ _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_DEFAULT);
+ // get the samplerate of that stream
+ BASS_CHANNELINFO info = new BASS_CHANNELINFO();
+ Bass.BASS_ChannelGetInfo(_stream, info);
+ // and start playing the and also start the BPM counter
+ if (_stream != 0 && Bass.BASS_ChannelPlay(_stream, false) )
+ {
+ //playing...
+ _bpm.Reset(info.freq);
+ // start our bpm timer callback
+ this.timerBPM.Start();
+ }
+
+ private void timerBPM_Tick(object sender, System.EventArgs e)
+ {
+ if ( _stream == 0 || Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ this.timerBPM.Stop();
+ return;
+ }
+ bool beat = _bpm.ProcessAudio(_stream, true);
+ if (beat)
+ {
+ // display the live calculated BPM value
+ this.labelBPM.Text = _bpm.BPM.ToString( "#00.0" );
+ }
+ }
+
+
+ Private _stream As Integer
+ ' create a BPMCounter instance, the timer will be fired every 20ms
+ Private _bpm As New BPMCounter(20, 44100)
+ ...
+ ' create a stream
+ _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_DEFAULT)
+ ' get the samplerate of that stream
+ Dim info As New BASS_CHANNELINFO()
+ Bass.BASS_ChannelGetInfo(_stream, info)
+ ' and start playing the and also start the BPM counter
+ If _stream <> 0 AndAlso Bass.BASS_ChannelPlay(_stream, False) Then
+ 'playing...
+ _bpm.Reset(info.freq)
+ ' start our bpm timer callback
+ Me.timerBPM.Start()
+ End If
+
+ Private Sub timerBPM_Tick(sender As Object, e As System.EventArgs)
+ If _stream = 0 OrElse Bass.BASS_ChannelIsActive(_stream) <> BASSActive.BASS_ACTIVE_PLAYING Then
+ Me.timerBPM.Stop()
+ Return
+ End If
+ Dim beat As Boolean = _bpm.ProcessAudio(_stream, True)
+ If beat Then
+ ' display the live calculated BPM value
+ Me.labelBPM.Text = _bpm.BPM.ToString("#00.0")
+ End If
+ End Sub
+
+
+ // create a new HiPerfTimer object
+ HiPerfTimer pt = new HiPerfTimer();
+ pt.Start(); // start the timer
+ // the code to be timed
+ Console.WriteLine("Test");
+ pt.Stop(); // stop the timer
+ // print the duration of the timed code
+ Console.WriteLine("Duration: {0} sec", pt.Duration);
+
+
+ ' create a new HiPerfTimer object
+ Dim pt As New HiPerfTimer()
+ pt.Start() ' start the timer
+ Console.WriteLine("Test") ' the code to be timed
+ pt.Stop() ' stop the timer
+ ' print the duration of the timed code
+ Console.WriteLine("Duration: {0} sec", pt.Duration)
+
+
+ // create any stream
+ int stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT);
+ // and assign a VST effect
+ int vstHandle = BassVst.BASS_VST_ChannelSetDSP(stream,
+ "C:\\VstPlugins\\DelayEditGUI.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1);
+ // and play the stream
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ // if the VST effect is not needed anymore...
+ BassVst.BASS_VST_ChannelRemoveDSP(stream, vstHandle);
+
+
+ ' create any stream
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' and assign a VST effect
+ Dim vstHandle As Integer = BassVst.BASS_VST_ChannelSetDSP(stream,
+ "C:\VstPlugins\DelayEditGUI.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+ ' and play the stream
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ ' if the VST effect is not needed anymore...
+ BassVst.BASS_VST_ChannelRemoveDSP(stream, vstHandle)
+
+
+ using Un4seen.Bass.AddOn.Vst;
+ using Un4seen.Bass.AddOn.Midi;
+
+ int vstHandle = BassVst.BASS_VST_ChannelCreate(44100, 2, "yourVSTi.dll", BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(vstHandle);
+ BassVst.BASS_VST_ProcessEvent(vstHandle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, Utils.MakeWord(60, 100));
+
+
+ Imports Un4seen.Bass.AddOn.Vst
+ Imports Un4seen.Bass.AddOn.Midi
+
+ Dim vstHandle As Integer = BassVst.BASS_VST_ChannelCreate(44100, 2, "yourVSTi.dll", BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(vstHandle)
+ BassVst.BASS_VST_ProcessEvent(vstHandle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, Utils.MakeWord(60, 100))
+
+
+ using Un4seen.Bass.AddOn.Vst;
+ using Un4seen.Bass.AddOn.Midi;
+
+ int vstHandle = BassVst.BASS_VST_ChannelCreate(44100, 2, "yourVSTi.dll", BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(vstHandle);
+
+ // create a new system-exclusive message
+ MidiSysExMessage sysex = new MidiSysExMessage(false, IntPtr.Zero);
+ // message will be 8 byte (incl. SoX and EoX)
+ sysex.CreateBuffer(8);
+ // write start-of-system-exclusive
+ sysex.MessageWriteSoX();
+ int offset = 1;
+ // write 6 more bytes...
+ sysex.MessageWrite8(ref offset, 65);
+ sysex.MessageWrite16(ref offset, 1023);
+ sysex.MessageWrite16(ref offset, 13);
+ sysex.MessageWrite8(ref offset, 1);
+ // write end-of-system-exusive
+ sysex.MessageWriteEoX();
+
+ BassVst.BASS_VST_ProcessEvent(vstHandle, sysex);
+
+
+ Imports Un4seen.Bass.AddOn.Vst
+ Imports Un4seen.Bass.AddOn.Midi
+
+ Dim vstHandle As Integer = BassVst.BASS_VST_ChannelCreate(44100, 2, "yourVSTi.dll", BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(vstHandle)
+
+ ' create a new system-exclusive message
+ Dim sysex As New MidiSysExMessage(False, IntPtr.Zero)
+ ' message will be 8 byte (incl. SoX and EoX)
+ sysex.CreateBuffer(8)
+ ' write start-of-system-exclusive
+ sysex.MessageWriteSoX()
+ Dim offset As Integer = 1
+ ' write 6 more bytes...
+ sysex.MessageWrite8(offset, 65)
+ sysex.MessageWrite16(offset, 1023)
+ sysex.MessageWrite16(offset, 13)
+ sysex.MessageWrite8(offset, 1)
+ ' write end-of-system-exusive
+ sysex.MessageWriteEoX()
+
+ BassVst.BASS_VST_ProcessEvent(vstHandle, sysex)
+
+
+ // assign and load the VST effect
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\\VstPlugins\\DelayEditGUI.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1);
+ // get the total number of parameters
+ int vstParams = BassVst.BASS_VST_GetParamCount(vstHandle);
+ // create a paramInfo object
+ BASS_VST_PARAM_INFO paramInfo = new BASS_VST_PARAM_INFO();
+ for (int i=0; i<vstParams; i++)
+ {
+ // get the info about the parameter
+ float paramValue = BassVst.BASS_VST_GetParam(vstHandle, i);
+ Console.WriteLine( paramValue.ToString() );
+
+ // and get further info about the parameter
+ BassVst.BASS_VST_GetParamInfo(vstHandle, i, paramInfo);
+ Console.WriteLine( paramInfo.ToString() );
+ }
+
+
+ ' assign and load the VST effect
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\VstPlugins\DelayEditGUI.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+ ' get the total number of parameters
+ Dim vstParams As Integer = BassVst.BASS_VST_GetParamCount(vstHandle)
+ ' create a paramInfo object
+ Dim paramInfo As New BASS_VST_PARAM_INFO()
+ Dim i As Integer
+ For i = 0 To vstParams - 1
+ ' get the info about the parameter
+ Dim paramValue As Single = BassVst.BASS_VST_GetParam(vstHandle, i)
+ Console.WriteLine(paramValue.ToString())
+
+ ' and get further info about the parameter
+ BassVst.BASS_VST_GetParamInfo(vstHandle, i, paramInfo)
+ Console.WriteLine(paramInfo.ToString())
+ Next i
+
+ The output from the above might look like this:
+
+ 0,5
+ Delay = 22049 samples
+ 0,5
+ FeedBack = 0.500000 amount
+ 0,75
+ Volume = -2.49877 dB
+
+
+ // assign and load the VST effect
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\\VstPlugins\\DelayEditGUI.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1);
+
+ // create a paramInfo object
+ BASS_VST_PARAM_INFO paramInfo = new BASS_VST_PARAM_INFO();
+ // set a parameter with index number 1 to 0.7
+ BassVst.BASS_VST_SetParam(vstHandle, 1, 0.75);
+ // and get the info about the parameter back, so that we know how is looks like in a readable format
+ BassVst.BASS_VST_GetParamInfo(vstHandle, i, paramInfo);
+ Console.WriteLine(String.Format( "{0} = {1} {2}", paramInfo.name, paramInfo.display, paramInfo.unit));
+ // this might look like this: "Volume = -2.49877 dB"
+
+
+ ' assign and load the VST effect
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\VstPlugins\DelayEditGUI.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+
+ ' create a paramInfo object
+ Dim paramInfo As New BASS_VST_PARAM_INFO()
+ ' set a parameter with index number 1 to 0.7
+ BassVst.BASS_VST_SetParam(vstHandle, 1, 0.75)
+ ' and get the info about the parameter back, so that we know how is looks like in a readable format
+ BassVst.BASS_VST_GetParamInfo(vstHandle, i, paramInfo)
+ Console.WriteLine([String].Format("{0} = {1} {2}", paramInfo.name, paramInfo.display, paramInfo.unit))
+ ' this might look like this: "Volume = -2.49877 dB"
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1 );
+ // get the number of available programs
+ int vstProgCount = BassVst.BASS_VST_GetProgramCount(vstHandle);
+ if (vstProgCount > 1)
+ {
+ // as an example get the parameters of program #1 (selected should be #0 in this case)
+ float[] progParams = BassVst.BASS_VST_GetProgramParam(vstHandle, 1);
+ if (progParams != null)
+ {
+ BASS_VST_PARAM_INFO paramInfo = new BASS_VST_PARAM_INFO();
+ // loop over all paramter
+ for (int i=0; i<progParams.Length; i++)
+ {
+ // get the program's value
+ float paramValue = progParams[i];
+ // qurey the info to get the parameter name
+ BassVst.BASS_VST_GetParamInfo(vstHandle, i, paramInfo);
+
+ Console.WriteLine( String.Format( "{0} = {1}", paramInfo.name, paramValue ) );
+ }
+ }
+ }
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+ ' get the number of available programs
+ Dim vstProgCount As Integer = BassVst.BASS_VST_GetProgramCount(vstHandle)
+ If vstProgCount > 1 Then
+ ' as an example get the parameters of program #1 (selected should be #0 in this case)
+ Dim progParams As Single() = BassVst.BASS_VST_GetProgramParam(vstHandle, 1)
+ If Not (progParams Is Nothing) Then
+ Dim paramInfo As New BASS_VST_PARAM_INFO()
+ ' loop over all paramter
+ Dim i As Integer
+ For i = 0 To progParams.Length - 1
+ ' get the program's value
+ Dim paramValue As Single = progParams(i)
+ ' qurey the info to get the parameter name
+ BassVst.BASS_VST_GetParamInfo(vstHandle, i, paramInfo)
+
+ Console.WriteLine([String].Format("{0} = {1}", paramInfo.name, paramValue))
+ Next i
+ End If
+ End If
+
+
+ // get the current program number
+ int vstCurrProg = BassVst.BASS_VST_GetProgram(vstHandle);
+ // query all parameter values of the current program
+ float[] prog0Params = BassVst.BASS_VST_GetProgramParam(vstHandle, vstCurrProg);
+ // query all parameter values of the program #3
+ float[] prog1aParams = BassVst.BASS_VST_GetProgramParam(vstHandle, 3);
+ // copy all parameters from the current program to #3
+ bool ok = BassVst.BASS_VST_SetProgramParam(vstHandle, 3, prog0Params);
+ // and query all parameter values of the program #3 again...
+ float[] prog1bParams = BassVst.BASS_VST_GetProgramParam(vstHandle, 3);
+
+
+ ' get the current program number
+ Dim vstCurrProg As Integer = BassVst.BASS_VST_GetProgram(vstHandle)
+ ' query all parameter values of the current program
+ Dim prog0Params As Single() = BassVst.BASS_VST_GetProgramParam(vstHandle, vstCurrProg)
+ ' query all parameter values of the program #3
+ Dim prog1aParams As Single() = BassVst.BASS_VST_GetProgramParam(vstHandle, 3)
+ ' copy all parameters from the current program to #3
+ Dim ok As Boolean = BassVst.BASS_VST_SetProgramParam(vstHandle, 3, prog0Params)
+ ' and query all parameter values of the program #3 again...
+ Dim prog1bParams As Single() = BassVst.BASS_VST_GetProgramParam(vstHandle, 3)
+
+
+ // assign a Vst effect to a channel
+ int vst = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0);
+
+ // change some parameters (e.g. #1 to 0.75)
+ BassVst.BASS_VST_SetParam(vst, 1, 0.75f);
+
+ // restore all parameters to it's default values
+ BassVst.BASS_VST_SetParamRestoreDefaults(vst);
+
+
+ ' assign a Vst effect to a channel
+ Dim vst As Integer = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0)
+
+ ' change some parameters (e.g. #1 to 0.75)
+ BassVst.BASS_VST_SetParam(vst, 1, 0.75F)
+
+ ' restore all parameters to it's default values
+ BassVst.BASS_VST_SetParamRestoreDefaults(vst)
+
+
+ private VSTPROC _myVstProc; // make global, so GC will not collect it
+ private int vst1;
+ private int vst2;
+ private int ch1;
+ private int ch2;
+ ...
+ // create the 'real' channels to use
+ ch1 = BASS_StreamCreateFile(...);
+ vst1 = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1);
+ ch2 = BASS_StreamCreateFile(...);
+ vst2 = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1);
+
+ // create an 'unchanneled' VST-editor
+ int vstDummy = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0);
+
+ // we want to be notified about parameter changes ...
+ myVstProc = new VSTPROC(vstEditorCallback);
+ BassVst.BASS_VST_SetCallback(vstDummy, myVstProc, IntPtr.Zero);
+
+ // so when the user opens the VST-editor this is being called
+ public int vstEditorCallback(int vstDummy, int action, int param1, int param2, IntPtr user)
+ {
+ if (action == BASS_VST_PARAM_CHANGED)
+ {
+ // the user has changed some slider in the unchanneled editor
+ // copy the changes to the 'real' channels
+ BassVst.BASS_VST_SetParamCopyParams(vstDummy, vst1);
+ BassVst.BASS_VST_SetParamCopyParams(vstDummy, vst2);
+ }
+ return 0;
+ }
+
+
+ Private _myVstProc As VSTPROC ' make global, so GC will not collect it
+ Private vst1 As Integer
+ Private vst2 As Integer
+ Private ch1 As Integer
+ Private ch2 As Integer
+ ...
+ ' create the 'real' channels to use
+ ch1 = BASS_StreamCreateFile(...)
+ vst1 = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+ ch2 = BASS_StreamCreateFile(...)
+ vst2 = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+
+ ' create an 'unchanneled' VST-editor
+ Dim vstDummy As Integer = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0)
+
+ ' we want to be notified about parameter changes ...
+ myVstProc = New VSTPROC(vstEditorCallback)
+ BassVst.BASS_VST_SetCallback(vstDummy, myVstProc, IntPtr.Zero)
+
+ ' so when the user opens the VST-editor this is being called
+ Public Function vstEditorCallback(vstDummy As Integer, action As Integer,
+ param1 As Integer, param2 As Integer, user As IntPtr) As Integer
+ If action = BASS_VST_PARAM_CHANGED Then
+ ' the user has changed some slider in the unchanneled editor
+ ' copy the changes to the 'real' channels
+ BassVst.BASS_VST_SetParamCopyParams(vstDummy, vst1)
+ BassVst.BASS_VST_SetParamCopyParams(vstDummy, vst2)
+ End If
+ Return 0
+ End Function
+
+
+ BASS_VST_INFO vstInfo = new BASS_VST_INFO();
+ if ( BassVst.BASS_VST_GetInfo(vstHandle, vstInfo))
+ Console.WriteLine(vstInfo.ToString());
+
+
+ Dim vstInfo As New BASS_VST_INFO()
+ If BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) Then
+ Console.WriteLine(vstInfo.ToString())
+ End If
+
+
+ BASS_VST_INFO vstInfo = BassVst.BASS_VST_GetInfo(vstHandle);
+ if (vstInfo != null)
+ Console.WriteLine(vstInfo.ToString());
+
+
+ Dim vstInfo As BASS_VST_INFO = BassVst.BASS_VST_GetInfo(vstHandle)
+ If Not (vstInfo Is Nothing) Then
+ Console.WriteLine(vstInfo.ToString())
+ End If
+
+
+ private int _vstHandle = 0;
+ ...
+ _vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1 );
+ // show the embedded editor
+ BASS_VST_INFO vstInfo = new BASS_VST_INFO();
+ if ( BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) && vstInfo.hasEditor )
+ {
+ // create a new System.Windows.Forms.Form
+ Form f = new Form();
+ f.Width = vstInfo.editorWidth+4;
+ f.Height = vstInfo.editorHeight+34;
+ f.Closing += new CancelEventHandler(f_Closing);
+ f.Text = vstInfo.effectName;
+ f.Show();
+ BassVst.BASS_VST_EmbedEditor(_vstHandle, f.Handle);
+ }
+
+ private void f_Closing(object sender, CancelEventArgs e)
+ {
+ // unembed the VST editor
+ BassVst.BASS_VST_EmbedEditor(_vstHandle, IntPtr.Zero);
+ }
+
+
+ Private _vstHandle As Integer = 0
+ ...
+ _vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 1)
+ ' show the embedded editor
+ Dim vstInfo As New BASS_VST_INFO()
+ If BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) AndAlso vstInfo.hasEditor Then
+ ' create a new System.Windows.Forms.Form
+ Dim f As New Form()
+ f.Width = vstInfo.editorWidth + 4
+ f.Height = vstInfo.editorHeight + 34
+ AddHandler f.Closing, AddressOf f_Closing
+ f.Text = vstInfo.effectName
+ f.Show()
+ BassVst.BASS_VST_EmbedEditor(_vstHandle, f.Handle)
+ End If
+
+ Private Sub f_Closing(sender As Object, e As CancelEventArgs)
+ ' unembed the VST editor
+ BassVst.BASS_VST_EmbedEditor(_vstHandle, IntPtr.Zero)
+ End Sub
+
+
+ ch1 = BASS_StreamCreateFile(false, "sth1.mp3", ...);
+ dsp1 = BASS_VST_ChannelSetDSP(ch1, "sth.dll", ...);
+ ch2 = BASS_StreamCreateFile(false, "sth2.mp3", ...);
+ dsp2 = BASS_VST_ChannelSetDSP(ch2, "sth.dll", ...);
+
+ For the user, this is one logical channel. If the user opens the editor for the 'sth' effect, it should display first the spectrum/vu/etc. from the first,
+ after crossfading from the second channel. To let the editor know this, you should use the 'scope'.
+ The 'scope' simply brings independent channels together to one logical unit - mainly for displaying the correct spectrum/vu/etc. in the editors.
+
+ BASS_VST_SetScope(dsp1, 123); // any number, scope is created implicitly
+ BASS_VST_SetScope(dsp2, 123); // any number, scope is created implicitly
+
+
+ editor = BASS_VST_ChannelSetDSP(0, "sth.dll", ...);
+ BASS_VST_SetScope(editor, 123);
+ BASS_VST_EmbedEditor(editor, ...);
+
+ The editor can then be opened, closed, created and destroyed independingly of the playing stuff.
+
+ private VSTPROC _myVstProc; // keep the callback delegate in a global member
+ ...
+ // your VST callback - referenced below by BASS_VST_SetCallback()
+ private int YourVstProc(int vstHandle, BASSVSTAction action, int param1, int param2, IntPtr user)
+ {
+ switch (action)
+ {
+ case BASSVSTAction.BASS_VST_PARAM_CHANGED:
+ // we get notified that the user has changed some sliders in the editor -
+ // do what to do here ...
+ break;
+ case BASSVSTAction.BASS_VST_EDITOR_RESIZED:
+ // the editor window requests a new size,
+ // maybe we should resize the window the editor is embedded in?
+ // the new width/height can be found in param1/param2
+ break;
+ case BASSVSTAction.BASS_VST_AUDIO_MASTER:
+ // this is only for people familiar with the VST SDK,
+ // param1 is a pointer to a BASS_VST_AUDIO_MASTER_PARAM structure
+ // which contains all information needed
+ break;
+ }
+ return 0;
+ }
+ ...
+ // open the VST editor (e.g. if we are inside a System.Windows.Forms.Form)
+ BassVst.BASS_VST_EmbedEditor(vstHandle, this.Handle);
+ // we want to get notified for parameter changes etc.
+ _myVstProc = new VSTPROC(YourVstProc);
+ BassVst.BASS_VST_SetCallback(vstHandle, _myVstProc, IntPtr.Zero);
+
+
+ Private _myVstProc As VSTPROC ' keep the callback delegate in a global member
+ ...
+ ' your VST callback - referenced below by BASS_VST_SetCallback()
+ Private Function YourVstProc(vstHandle As Integer, action As BASSVSTAction, param1 As Integer, param2 As Integer, user As IntPtr) As Integer
+ Select Case action
+ Case BASSVSTAction.BASS_VST_PARAM_CHANGED
+ ' we get notified that the user has changed some sliders in the editor -
+ ' do what to do here ...
+ Case BASSVSTAction.BASS_VST_EDITOR_RESIZED
+ ' the editor window requests a new size,
+ ' maybe we should resize the window the editor is embedded in?
+ ' the new width/height can be found in param1/param2
+ Case BASSVSTAction.BASS_VST_AUDIO_MASTER
+ ' this is only for people familiar with the VST SDK,
+ ' param1 is a pointer to a BASS_VST_AUDIO_MASTER_PARAM structure
+ ' which contains all information needed
+ End Select
+ Return 0
+ End Function
+ ...
+ ' open the VST editor (e.g. if we are inside a System.Windows.Forms.Form)
+ BassVst.BASS_VST_EmbedEditor(vstHandle, Me.Handle)
+ ' we want to get notified for parameter changes etc.
+ _myVstProc = New VSTPROC(AddressOf YourVstProc)
+ BassVst.BASS_VST_SetCallback(vstHandle, _myVstProc, IntPtr.Zero)
+
+
+ Bass.LoadMe();
+ BassVst.LoadMe();
+ ...
+ // when not used anymore...
+ BassVst.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassVst.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassVst.FreeMe();
+ Bass.FreeMe();
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0);
+ BASS_VST_INFO vstInfo = new BASS_VST_INFO();
+ if (BassVst.BASS_VST_GetInfo(vstHandle, vstInfo))
+ {
+ BASS_VST_AEFFECT aeffect = BASS_VST_AEFFECT.FromIntPtr(vstInfo.aeffect);
+ if (aeffect != null)
+ {
+ // now you might use the aeffect instance, e.g. retrieve the number of programs...
+ int numPrograms = aeffect.numPrograms;
+ ...
+ // or call the dispatcher...
+ string cmd = "bypass";
+ GCHandle gch = GCHandle.Alloc(cmd, GCHandleType.Pinned);
+ if (aeffect.dispatcher(vstInfo.aeffect, BASSVSTDispatcherOpCodes.effCanDo,
+ 0, 0, gch.AddrOfPinnedObject(), 0.0f) != 0)
+ {
+ int ret = aeffect.dispatcher(vstInfo.aeffect, BASSVSTDispatcherOpCodes.effSetBypass,
+ 0, 1, IntPtr.Zero, 0.0f);
+ Console.WriteLine(ret.ToString());
+ }
+ gch.Free();
+ ...
+ }
+ }
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0)
+ Dim vstInfo As New BASS_VST_INFO()
+ If BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) Then
+ Dim aeffect As BASS_VST_AEFFECT = BASS_VST_AEFFECT.FromIntPtr(vstInfo.aeffect)
+ If Not (aeffect Is Nothing) Then
+ ' now you might use the aeffect instance, e.g. retrieve the number of programs
+ Dim numPrograms As Integer = aeffect.numPrograms
+ ...
+ ' or call the dispatcher...
+ Dim cmd As String = "bypass"
+ Dim gch As GCHandle = GCHandle.Alloc(cmd, GCHandleType.Pinned)
+ If aeffect.dispatcher(vstInfo.aeffect, BASSVSTDispatcherOpCodes.effCanDo,
+ 0, 0, gch.AddrOfPinnedObject(), 0F) <> 0 Then
+ Dim ret As Integer = aeffect.dispatcher(vstInfo.aeffect, BASSVSTDispatcherOpCodes.effSetBypass,
+ 0, 1, IntPtr.Zero, 0F)
+ ...
+ Console.WriteLine(ret.ToString())
+ End If
+ gch.Free()
+ ...
+ End If
+ End If
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0);
+ BASS_VST_INFO vstInfo = new BASS_VST_INFO();
+ if ( BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) )
+ {
+ if (vstInfo.aeffect != IntPtr.Zero)
+ {
+ BASS_VST_AEFFECT aeffect = BASS_VST_AEFFECT.FromIntPtr(vstInfo.aeffect);
+ // list all available programs
+ for (int i=0; i<aeffect.numPrograms; i++)
+ Console.WriteLine( aeffect.GetProgramName(i) );
+ }
+ }
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(0, "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0)
+ Dim vstInfo As New BASS_VST_INFO()
+ If BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) Then
+ If vstInfo.aeffect <> IntPtr.Zero Then
+ Dim aeffect As BASS_VST_AEFFECT = BASS_VST_AEFFECT.FromIntPtr(vstInfo.aeffect)
+ ' list all available programs
+ Dim i As Integer
+ For i = 0 To aeffect.numPrograms - 1
+ Console.WriteLine(aeffect.GetProgramName(i))
+ Next i
+ End If
+ End If
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\\VstPlugins\\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0);
+ BASS_VST_INFO vstInfo = new BASS_VST_INFO();
+ if (BassVst.BASS_VST_GetInfo(vstHandle, vstInfo))
+ {
+ if (vstInfo.aeffect != IntPtr.Zero)
+ {
+ // get all available programs
+ string[] progs = aeffect.GetProgramNames();
+ if (progs != null)
+ {
+ for (int i = 0; i < progs.Length; i++)
+ Console.WriteLine(String.Format( "{0}: {1}", i, progs[i]));
+ }
+ }
+ }
+
+
+ vstHandle = BassVst.BASS_VST_ChannelSetDSP(0,
+ "C:\VstPlugins\Ambience.dll", BASSVSTDsp.BASS_VST_DEFAULT, 0)
+ Dim vstInfo As New BASS_VST_INFO()
+ If BassVst.BASS_VST_GetInfo(vstHandle, vstInfo) Then
+ If vstInfo.aeffect <> IntPtr.Zero Then
+ ' get all available programs
+ Dim progs As String() = aeffect.GetProgramNames()
+ If Not (progs Is Nothing) Then
+ Dim i As Integer
+ For i = 0 To progs.Length - 1
+ Console.WriteLine([String].Format("{0}: {1}", i, progs(i)))
+ Next i
+ End If
+ End If
+ End If
+
+
+ private VSTPROC _myVstProc; // keep the callback delegate in a global member
+ ...
+ // your VST callback - referenced below by BASS_VST_SetCallback()
+ private int YourVstProc(int vstHandle, BASSVSTAction action, int param1, int param2, IntPtr user)
+ {
+ switch (action)
+ {
+ case BASSVSTAction.BASS_VST_PARAM_CHANGED:
+ // we get notified that the user has changed some sliders in the editor -
+ // do what to do here ...
+ break;
+ case BASSVSTAction.BASS_VST_EDITOR_RESIZED:
+ // the editor window requests a new size,
+ // maybe we should resize the window the editor is embedded in?
+ // the new width/height can be found in param1/param2
+ break;
+ case BASSVSTAction.BASS_VST_AUDIO_MASTER:
+ // this is only for people familiar with the VST SDK,
+ // param1 is a pointer to a BASS_VST_AUDIO_MASTER_PARAM structure
+ // which contains all information needed
+ break;
+ }
+ return 0;
+ }
+ ...
+ // open the VST editor (e.g. if we are inside a System.Windows.Forms.Form)
+ BassVst.BASS_VST_EmbedEditor(vstHandle, this.Handle);
+ // we want to get notified for parameter changes etc.
+ _myVstProc = new VSTPROC(YourVstProc);
+ BassVst.BASS_VST_SetCallback(vstHandle, _myVstProc, IntPtr.Zero);
+
+
+ Private _myVstProc As VSTPROC ' keep the callback delegate in a global member
+ ...
+ ' your VST callback - referenced below by BASS_VST_SetCallback()
+ Private Function YourVstProc(vstHandle As Integer, action As BASSVSTAction, param1 As Integer, param2 As Integer, user As IntPtr) As Integer
+ Select Case action
+ Case BASSVSTAction.BASS_VST_PARAM_CHANGED
+ ' we get notified that the user has changed some sliders in the editor -
+ ' do what to do here ...
+ Case BASSVSTAction.BASS_VST_EDITOR_RESIZED
+ ' the editor window requests a new size,
+ ' maybe we should resize the window the editor is embedded in?
+ ' the new width/height can be found in param1/param2
+ Case BASSVSTAction.BASS_VST_AUDIO_MASTER
+ ' this is only for people familiar with the VST SDK,
+ ' param1 is a pointer to a BASS_VST_AUDIO_MASTER_PARAM structure
+ ' which contains all information needed
+ End Select
+ Return 0
+ End Function
+ ...
+ ' open the VST editor (e.g. if we are inside a System.Windows.Forms.Form)
+ BassVst.BASS_VST_EmbedEditor(vstHandle, Me.Handle)
+ ' we want to get notified for parameter changes etc.
+ _myVstProc = New VSTPROC(AddressOf YourVstProc)
+ BassVst.BASS_VST_SetCallback(vstHandle, _myVstProc, IntPtr.Zero)
+
+
+ TAG_INFO tagInfo = BassTags.BASS_TAG_GetFromFile(fileName);
+ if ( tagInfo != null )
+ {
+ // display the tags...
+ }
+
+
+ Dim tagInfo As TAG_INFO = BassTags.BASS_TAG_GetFromFile(fileName)
+ If Not (tagInfo Is Nothing) Then
+ ' display the tags...
+ End If
+
+
+ TAG_INFO tagInfo = BassTags.BASS_TAG_GetFromFile(fileName, true, true);
+ if ( tagInfo != null )
+ {
+ // display the tags...
+ }
+
+
+ Dim tagInfo As TAG_INFO = BassTags.BASS_TAG_GetFromFile(fileName, True, True)
+ If Not (tagInfo Is Nothing) Then
+ ' display the tags...
+ End If
+
+
+ TAG_INFO tagInfo = BassTags.BASS_TAG_GetFromFile(fileName, true, true);
+ if ( tagInfo != null )
+ {
+ // display the tags...
+ }
+
+
+ Dim tagInfo As TAG_INFO = BassTags.BASS_TAG_GetFromFile(fileName, True, True)
+ If Not (tagInfo Is Nothing) Then
+ ' display the tags...
+ End If
+
+
+ // create a stream
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0, BASSFlag.BASS_DEFAULT);
+ // update the tags
+ TAG_INFO tagInfo = new TAG_INFO(fileName);
+ if ( BassTags.BASS_TAG_GetFromFile( stream, tagInfo) )
+ {
+ // display the tags...
+ }
+
+
+ ' create a stream
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tagInfo As New TAG_INFO(fileName)
+ If BassTags.BASS_TAG_GetFromFile(stream, tagInfo) Then
+ ' display the tags...
+ End If
+
+
+ // create a stream
+ int stream = BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_STATUS, null, 0);
+ // update the tags
+ TAG_INFO tagInfo = new TAG_INFO(url);
+ if ( BassTags.BASS_TAG_GetFromURL( stream, tagInfo) )
+ {
+ // display the tags...
+ }
+
+
+ ' create a stream
+ Dim stream As Integer = BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_STATUS, Nothing, 0)
+ ' update the tags
+ Dim tagInfo As New TAG_INFO(url)
+ If BassTags.BASS_TAG_GetFromURL(stream, tagInfo) Then
+ ' display the tags...
+ End If
+
+
+ private SYNCPROC _mySync;
+ private TAG_INFO _tags;
+ ...
+ string url = "http://someurl...";
+ int stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_STATUS, null, 0);
+ _tags = new TAG_INFO(url);
+ // set a sync to get the title updates out of the meta data...
+ _mySync = new SYNCPROC(MetaSync);
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero);
+ ...
+ private void MetaSync(int handle, int channel, int data, IntPtr user)
+ {
+ // BASS_SYNC_META is triggered on meta changes of SHOUTcast streams
+ _tags.UpdateFromMETA( Bass.BASS_ChannelGetTags(channel, BASSTag.BASS_TAG_META), false );
+ }
+
+
+ Private _mySync As SYNCPROC
+ Private _tags As TAG_INFO
+ ...
+ Dim url As String = "http://someurl..."
+ Dim stream As Integer = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_STATUS, Nothing, 0)
+ _tags = New TAG_INFO(url)
+ ' set a sync to get the title updates out of the meta data...
+ _mySync = New SYNCPROC(AddressOf MetaSync)
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero)
+ ...
+ Private Sub MetaSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ ' BASS_SYNC_META is triggered on meta changes of SHOUTcast streams
+ _tags.UpdateFromMETA(Bass.BASS_ChannelGetTags(channel, BASSTag.BASS_TAG_META), False)
+ End Sub
+
+
+ private SYNCPROC _mySync;
+ private TAG_INFO _tags;
+ ...
+ int midi = BassMidi.BASS_MIDI_StreamCreateFile("test.mid", 0, 0, BASSFlag.BASS_STREAM_AUTOFREE, 44100);
+ _tags = new TAG_INFO("test.mid");
+ // set a sync to get the lyric text updates out of the MIDI data...
+ _mySync = new SYNCPROC(LyricSync);
+ Bass.BASS_ChannelSetSync(midi, BASSSync.BASS_SYNC_MIDI_LYRIC, 0, _mySync, IntPtr.Zero);
+ // get the initial tags
+ BassTags.BASS_TAG_GetFromFile(midi, _tags);
+ ...
+ private void LyricSync(int handle, int channel, int data, IntPtr user)
+ {
+ _tags.UpdateFromMIDILyric( BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_LYRIC, data) );
+ // tags.comment now contains the updated lyric text
+ Console.Write("{0}\r", _tags.comment)
+ }
+
+
+ Private _mySync As SYNCPROC
+ Private _tags As TAG_INFO
+ ...
+ Dim midiStream As Integer = BassMidi.BASS_MIDI_StreamCreateFile("test.mid", 0, 0, BASSFlag.BASS_STREAM_AUTOFREE, 44100)
+ _tags = New TAG_INFO("test.mid")
+ ' set a sync to get the lyric text updates out of the MIDI data...
+ _mySync = New SYNCPROC(AddressOf LyricSync)
+ Bass.BASS_ChannelSetSync(midi, BASSSync.BASS_SYNC_MIDI_LYRIC, 0, _mySync, IntPtr.Zero)
+ ' get the initial tags...
+ BassTags.BASS_TAG_GetFromFile(midi, _tags)
+ ...
+ Private Sub LyricSync(ByVal handle As Integer, ByVal channel As Integer, ByVal data As Integer, ByVal user As IntPtr)
+ tags.UpdateFromMIDILyric(BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_LYRIC, data))
+ ' tags.comment now contains the updated lyric text
+ Console.Write("{0}\r", _tags.comment)
+ End Sub
+
+
+ byte[] listData = TAGs.ConvertToRiffINFO(false);
+ if (listData != null)
+ BassEnc.BASS_Encode_AddChunk(_encoderHandle, "LIST", listData, listData.Length);
+
+
+ Dim listData As Byte() = TAGs.ConvertToRiffINFO(False)
+ If listData IsNot Nothing Then
+ BassEnc.BASS_Encode_AddChunk(_encoderHandle, "LIST", listData, listData.Length)
+ End If
+
+
+ byte[] bextData = TAGs.ConvertToRiffBEXT(true);
+ if (bextData != null)
+ BassEnc.BASS_Encode_AddChunk(_encoderHandle, "bext", bextData, bextData.Length);
+
+
+ Dim bextData As Byte() = TAGs.ConvertToRiffBEXT(True)
+ If bextData IsNot Nothing Then
+ BassEnc.BASS_Encode_AddChunk(_encoderHandle, "bext", bextData, bextData.Length)
+ End If
+
+
+ byte[] cartData = TAGs.ConvertToRiffCART(true);
+ if (cartData != null)
+ BassEnc.BASS_Encode_AddChunk(_encoderHandle, "cart", cartData, cartData.Length);
+
+
+ Dim cartData As Byte() = TAGs.ConvertToRiffCART(True)
+ If cartData IsNot Nothing Then
+ BassEnc.BASS_Encode_AddChunk(_encoderHandle, "cart", cartData, cartData.Length)
+ End If
+
+
+ The 10 byte header looks like this:
+ struct Id3v2Header
+ {
+ char magic[3]; // always "Id3"
+ char majorVersion;
+ char minorVersion;
+ char flags;
+ int28 size;
+ };
+ The version is always v2.maj.min -- the v2 is implied.
+ flags currently only defines 4 flags. More on these later.
+ The int28 type is a 28-bit integer padded out to a
+ 32-bit integer, to make it sync-safe. It's padded by setting
+ the most significant bit of each byte to zero.
+ i.e. it looks like this:
+ 0xxxxxxx0xxxxxxx0xxxxxxx0xxxxxxx
+ Integers in Id3v2 are big-endian.
+ A frame looks like this:
+ struct Id3v2Frame
+ {
+ char frame_id[4];
+ int28 size;
+ char flags[2];
+ };
+
+ bool
and so on.
+
+ IntPtr p = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ADX_LOOP);
+ if (p != IntPtr.Zero)
+ {
+ BASS_ADX_TAG_LOOP adxLoop = (BASS_ADX_TAG_LOOP)Marshal.PtrToStructure(p, typeof(BASS_ADX_TAG_LOOP));
+ ...
+ }
+
+
+ Dim p As IntPtr = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ADX_LOOP)
+ If p <> IntPtr.Zero Then
+ Dim adxLoop As BASS_ADX_TAG_LOOP = DirectCast(Marshal.PtrToStructure(p, GetType(BASS_ADX_TAG_LOOP)), BASS_ADX_TAG_LOOP)
+ ...
+ End If
+
+ Setting a loop according to the ADX tag data (as given in adxLoop):
+
+ private int _loopSync = 0;
+ private SYNCPROC _loopSyncCallback;
+ ...
+ if (adxLoop.LoopEnabled)
+ {
+ _loopSyncCallback = new SYNCPROC(LoopSync);
+ _loopSync = Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
+ adxLoop.ByteEnd, _loopSyncCallback, new IntPtr(adxLoop.ByteStart));
+ }
+ ...
+ // to remove the loop call this
+ Bass.Bass.BASS_ChannelRemoveSync(stream, _loopSync);
+ ...
+ // the sync callback
+ private void LoopSync(int syncHandle, int channel, int data, IntPtr user)
+ {
+ // move the position to the start (which is given in the user data)
+ Bass.BASS_ChannelSetPosition(channel, user.ToInt64());
+ }
+
+
+ Private _loopSync As Integer = 0
+ Private _loopSyncCallback As SYNCPROC
+ ...
+ If adxLoop.LoopEnabled Then
+ _loopSyncCallback = New SYNCPROC(AddressOf LoopSync);
+ _loopSync = Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_POS Or BASSSync.BASS_SYNC_MIXTIME,
+ adxLoop.ByteEnd, _loopSyncCallback, New IntPtr(adxLoop.ByteStart))
+ End If
+ ...
+ ' to remove the loop call this
+ Bass.Bass.BASS_ChannelRemoveSync(stream, _loopSync)
+ ...
+ ' the sync callback
+ Private Sub LoopSync(ByVal handle As Integer, ByVal channel As Integer,
+ ByVal data As Integer, ByVal user As IntPtr)
+ ' move the position to the start (which is given in the user data)
+ Bass.BASS_ChannelSetPosition(channel, user.ToInt64())
+ End Sub
+
+
+ Dictionary<int, string> loadedPlugIns = Bass.BASS_PluginLoadDirectory(dir);
+ string exts = Utils.BASSAddOnGetSupportedFileExtensions(loadedPlugIns, true);
+
+
+ Dim loadedPlugIns As Dictionary(Of Integer, String) = Bass.BASS_PluginLoadDirectory(dir)
+ Dim exts As String = Utils.BASSAddOnGetSupportedFileExtensions(loadedPlugIns, True)
+
+
+ Dictionary<int, string> loadedPlugIns = Bass.BASS_PluginLoadDirectory(dir);
+ openFileDialog.Filter = Utils.BASSAddOnGetSupportedFileFilter(loadedPlugIns, "All supported Audio Files");
+
+
+ Dim loadedPlugIns As Dictionary(Of Integer, String) = Bass.BASS_PluginLoadDirectory(dir)
+ openFileDialog.Filter = Utils.BASSAddOnGetPluginFileFilter(loadedPlugIns, "All supported Audio Files")
+
+
+ Dictionary<int, string> loadedPlugIns = Bass.BASS_PluginLoadDirectory(dir);
+ openFileDialog.Filter = Utils.BASSAddOnGetSupportedFileFilter(loadedPlugIns, null, false);
+
+
+ Dim loadedPlugIns As Dictionary(Of Integer, String) = Bass.BASS_PluginLoadDirectory(dir)
+ openFileDialog.Filter = Utils.BASSAddOnGetPluginFileFilter(loadedPlugIns, Nothing, False)
+
+
+ Dictionary<int, string> loadedPlugIns = Bass.BASS_PluginLoadDirectory(dir);
+ openFileDialog.Filter = Utils.BASSAddOnGetPluginFileFilter(loadedPlugIns, "All supported Audio Files");
+
+
+ Dim loadedPlugIns As Dictionary(Of Integer, String) = Bass.BASS_PluginLoadDirectory(dir)
+ openFileDialog.Filter = Utils.BASSAddOnGetPluginFileFilter(loadedPlugIns, "All supported Audio Files")
+
+
+ Dictionary<int, string> loadedPlugIns = Bass.BASS_PluginLoadDirectory(dir);
+ openFileDialog.Filter = Utils.BASSAddOnGetPluginFileFilter(loadedPlugIns, null, false);
+
+
+ Dim loadedPlugIns As Dictionary(Of Integer, String) = Bass.BASS_PluginLoadDirectory(dir)
+ openFileDialog.Filter = Utils.BASSAddOnGetPluginFileFilter(loadedPlugIns, Nothing, False)
+
+
+ | 32-bit |
+ | right-peak | left-peak |
+
+
+ | 64-bit |
+ | right | left |
+ |max.peak|min.peak|max.peak|min.peak|
+
+
+ | 32-bit |
+ | right-peak | left-peak |
+
+
+ | 64-bit |
+ | right | left |
+ |max.peak|min.peak|max.peak|min.peak|
+
+
+ | 32-bit |
+ | right-peak | left-peak |
+
+
+ | 64-bit |
+ | right | left |
+ |max.peak|min.peak|max.peak|min.peak|
+
+
+ | 32-bit |
+ | right-peak | left-peak |
+
+
+ | 64-bit |
+ | right | left |
+ |max.peak|min.peak|max.peak|min.peak|
+
+
+ private RECORDPROC _myRecProc; // make it global, so that the GC can not remove it
+ private int _recHandle = 0;
+ // The buffer: 44.1kHz, 16-bit, stereo (like we record!)
+ private BASSBuffer _monBuffer = new BASSBuffer(2f, 44100, 2, 16);
+ private int _monStream = 0;
+ private STREAMPROC _monProc = null;
+ ...
+ // enable lower latency settings (optional)
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20);
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 100);
+ // start recording with 20ms update period
+ _myRecProc = new RECORDPROC(MyRecording);
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, _myRecProc, IntPtr.Zero);
+ // setup the full-duplex monitoring
+ _monProc = new STREAMPROC(MonitoringStream);
+ _monStream = Bass.BASS_StreamCreate(44100, 2, 0, _monProc, IntPtr.Zero); // user = reader#
+ Bass.BASS_ChannelPlay(_monStream, false);
+
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ monBuffer.Write(buffer, length);
+ }
+
+ private int MonitoringStream(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ return monBuffer.Read(buffer, length, user.ToInt32());
+ }
+
+
+ Private _myRecProc As RECORDPROC ' make it global, so that the GC can not remove it
+ Private _recHandle As Integer = 0
+ ' The buffer: 44.1kHz, 16-bit, stereo (like we record!)
+ Private _monBuffer As New BASSBuffer(2F, 44100, 2, 16)
+ Private _monStream As Integer = 0
+ Private _monProc As STREAMPROC = Nothing
+ ...
+ ' enable lower latency settings (optional)
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20)
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 100)
+ ' start recording with 20ms update period
+ _myRecProc = New RECORDPROC(MyRecording)
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, _myRecProc, IntPtr.Zero)
+ ' setup the full-duplex monitoring
+ _monProc = New STREAMPROC(AddressOf MonitoringStream)
+ _monStream = Bass.BASS_StreamCreate(44100, 2, 0, _monProc, IntPtr.Zero) ' user = reader#
+ Bass.BASS_ChannelPlay(_monStream, False)
+
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ monBuffer.Write(buffer, length)
+ End Function
+
+ Private Function MonitoringStream(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ Return monBuffer.Read(buffer, length, user.ToInt32())
+ End Function
+
+
+ if ( Utils.HighWord(BassSfx.BASS_SFX_GetVersion()) != BassSfx.BASSSFXVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassSfx Version!");
+ }
+
+
+ If Utils.HighWord(BassSfx.BASS_SFX_GetVersion()) <> BassSfx.BASSSFXVERSION Then
+ MessageBox.Show(Me, "Wrong BassSfx Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassSfx.BASS_SFX_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassSfx Version!");
+ }
+
+
+ If BassSfx.BASS_SFX_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassSfx Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassSfx.BASS_SFX_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassSfx Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassSfx.BASS_SFX_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassSfx Version!")
+ End If
+
+
+ BassSfx.BASS_SFX_Init();
+
+
+ BassSfx.BASS_SFX_Init()
+
+
+ // create a plugin object
+ int sfx = BassSfx.BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT);
+ if (sfx != 0)
+ {
+ // loaded file successfully
+ BASS_SFX_PluginStart(sfx);
+ }
+
+
+ ' create a plugin object
+ Dim sfx As Integer = BassSfx.BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT)
+ If sfx <> 0 Then
+ ' loaded file successfully
+ BASS_SFX_PluginStart(sfx);
+ End If
+
+
+ if (BassSfx.BASS_SFX_PluginGetType(sfx) == BASSSFXPlugin.BASS_SFX_WINAMP)
+ {
+ // a winamp visual plugin was loaded
+ }
+ else if (BassSfx.BASS_SFX_PluginGetType(sfx) == BASSSFXPlugin.BASS_SFX_SONIQUE)
+ {
+ // a sonique visual plugin was loaded
+ }
+ else if (BassSfx.BASS_SFX_PluginGetType(sfx) == BASSSFXPlugin.BASS_SFX_WMP)
+ {
+ // a WMP visual plugin was loaded
+ }
+ else if (BassSfx.BASS_SFX_PluginGetType(sfx) == BASSSFXPlugin.BASS_SFX_BBP)
+ {
+ // a BassBox visual plugin was loaded
+ }
+ else
+ {
+ // we have either loaded nothing or an unsupported plugin
+ }
+
+
+ If BassSfx.BASS_SFX_PluginGetType(sfx) = BASSSFXPlugin.BASS_SFX_WINAMP Then
+ ' a winamp visual plugin was loaded
+ ElseIf BassSfx.BASS_SFX_PluginGetType(sfx) = BASSSFXPlugin.BASS_SFX_SONIQUE Then
+ ' a sonique visual plugin was loaded
+ ElseIf BassSfx.BASS_SFX_PluginGetType(sfx) = BASSSFXPlugin.BASS_SFX_WMP Then
+ ' a WMP visual plugin was loaded
+ ElseIf BassSfx.BASS_SFX_PluginGetType(sfx) = BASSSFXPlugin.BASS_SFX_BBP Then
+ ' a BassBox visual plugin was loaded
+ Else
+ ' we have either loaded nothing or an unsupported plugin
+ End If
+
+
+ // create a BASS channel
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ // create a plugin object
+ int sfx = BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT);
+ if (sfx != 0 && stream != 0)
+ {
+ // loaded file successfully
+ if (BASS_SFX_PluginStart(sfx))
+ BASS_SFX_PluginSetStream(sfx, stream);
+ }
+
+
+ ' create a BASS channel
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ ' create a plugin object
+ Dim sfx As Integer = BassSfx.BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT)
+ If sfx <> 0 AndAlso stream <> 0 Then
+ ' loaded file successfully
+ If BASS_SFX_PluginStart(sfx) Then
+ BASS_SFX_PluginSetStream(sfx, stream)
+ End If
+ End If
+
+
+ // create a BASS channel
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ // create a plugin object
+ int sfx = BassSfx.BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT);
+ if (sfx != 0 && stream != 0)
+ {
+ // loaded file successfully
+ if (BASS_SFX_PluginStart(sfx))
+ BASS_SFX_PluginSetStream(sfx, stream);
+ }
+
+
+ ' create a BASS channel
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ ' create a plugin object
+ Dim sfx As Integer = BassSfx.BASS_SFX_PluginCreate("corona.svp", 320, 240)
+ If sfx <> 0 AndAlso stream <> 0 Then
+ ' loaded file successfully
+ If BASS_SFX_PluginStart(sfx) Then
+ BASS_SFX_PluginSetStream(sfx, stream)
+ End If
+ End If
+
+
+ // create a plugin object
+ int sfx = BassSfx.BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT);
+ if (sfx != 0)
+ {
+ // get the plugin name
+ Console.WriteLine(BassSfx.BASS_SFX_PluginGetName(sfx));
+ }
+
+
+ ' create a plugin object
+ Dim sfx As Integer = BassSfx.BASS_SFX_PluginCreate("corona.svp", pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height, BASSSFXFlag.BASS_SFX_DEFAULT)
+ If sfx <> 0 Then
+ ' get the plugin name
+ Console.WriteLine(BassSfx.BASS_SFX_PluginGetName(sfx));
+ End If
+
+
+ string name;
+ for (int n=0; (name = BassSfx.BASS_SFX_PluginModuleGetName(sfx, n)) != null; n++)
+ {
+ Console.WriteLine(name);
+ }
+
+
+ Dim n As Integer = 0
+ Dim name As String = ""
+ While Not (name Is Nothing)
+ name = BassSfx.BASS_SFX_PluginModuleGetName(sfx, n)
+ n += 1
+ If Not (name Is Nothing) Then
+ Console.WriteLine(name)
+ End If
+ End While
+
+
+ // set OpenGL flag:
+ BassSfx.BASS_SFX_PluginFlags(hsfx, BASSSFXFlag.BASS_SFX_SONIQUE_OPENGL, BASSSFXFlag.BASS_SFX_SONIQUE_OPENGL);
+
+ // remove OpenGL flag:
+ BassSfx.BASS_SFX_PluginFlags(hsfx, BASSSFXFlag.BASS_SFX_DEFAULT, BASSSFXFlag.BASS_SFX_SONIQUE_OPENGL);
+
+
+ ' set openGL flag:
+ BassSfx.BASS_SFX_PluginFlags(hsfx, BASSSFXFlag.BASS_SFX_SONIQUE_OPENGL, BASSSFXFlag.BASS_SFX_SONIQUE_OPENGL)
+
+ ' remove OpenGL flag:
+ BassSfx.BASS_SFX_PluginFlags(hsfx, BASSSFXFlag.BASS_SFX_DEFAULT, BASSSFXFlag.BASS_SFX_SONIQUE_OPENGL)
+
+
+ BASS_SFX_PLUGININFO info = new BASS_SFX_PLUGININFO();
+ BassSfx.BASS_SFX_WMP_GetPlugin(0, info);
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As New BASS_SFX_PLUGININFO()
+ BassSfx.BASS_SFX_WMP_GetPlugin(0, info)
+ Console.WriteLine(info.ToString())
+
+
+ BASS_SFX_PLUGININFO info = BassSfx.BASS_SFX_WMP_GetPlugin(0);
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As BASS_SFX_PLUGININFO = Bass.BASS_SFX_WMP_GetPlugin(0)
+ Console.WriteLine(info.ToString())
+
+
+ if ( Utils.HighWord(BassWasapi.BASS_WASAPI_GetVersion()) != BassWasapi.BASSWASAPIVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassWasapi Version!");
+ }
+
+
+ If Utils.HighWord(BassWasapi.BASS_WASAPI_GetVersion()) <> BassWasapi.BASSWASAPIVERSION Then
+ MessageBox.Show(Me, "Wrong BassWasapi Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassWasapi.BASS_WASAPI_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassWasapi Version!");
+ }
+
+
+ If BassWasapi.BASS_WASAPI_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassWasapi Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassWasapi.BASS_WASAPI_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassWasapi Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassWasapi.BASS_WASAPI_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassWasapi Version!")
+ End If
+
+
+ BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO();
+ for (int n=0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info); n++)
+ {
+ Console.WriteLine(info.ToString());
+ }
+
+
+ Dim n As Integer = 0
+ Dim info As New BASS_WASAPI_DEVICEINFO()
+ While (BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info))
+ Console.WriteLine(info.ToString())
+ n += 1
+ End While
+
+ Or use the
+ BASS_WASAPI_DEVICEINFO info;
+ for (int n = 0; (info = BassWasapi.BASS_WASAPI_GetDeviceInfo(n)) != null; n++)
+ {
+ ...
+ }
+
+
+ Dim n As Integer = 0
+ Dim info As New BASS_WASAPI_DEVICEINFO()
+ While Not (info Is Nothing)
+ info = BassWasapi.BASS_WASAPI_GetDeviceDescription(n)
+ If Not (info Is Nothing) Then
+ ...
+ End If
+ n += 1
+ End While
+
+ Or use the
+ Bass.LoadMe();
+ BassWma.LoadMe();
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassWma.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ private BassWasapiHandler _wasapi;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ ...
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // assign WASAPI output in shared-mode
+ _wasapi = new BassWasapiHandler(-1, false, 48000, 2, 0f, 0f);
+ // add the source channel
+ _wasapi.AddOutputSource(stream, BASSFlag.BASS_DEFAULT)
+ // init and start WASAPI
+ _wasapi.Init();
+ _wasapi.Start();
+ }
+
+
+ Private _wasapi As BassWasapiHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' assign WASAPI output in shared-mode
+ _wasapi = new BassWasapiHandler(-1, false, 48000, 2, 0f, 0f)
+ ' add the source channel
+ _wasapi.AddOutputSource(stream, BASSFlag.BASS_DEFAULT)
+ ' init and start WASAPI
+ _wasapi.Init()
+ _wasapi.Start()
+ End If
+
+ Automatic use of the BassWasapiHandler (Wasapi recording input):
+
+ private BassWasapiHandler _wasapi;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ ...
+ // assign WASAPI input in shared-mode
+ _wasapi = new BassWasapiHandler(-2, false, 48000, 2, 0f, 0f);
+ // init and start WASAPI
+ _wasapi.Init();
+ int recordStream = _wasapi.InputChannel;
+ // double check, that the device is not muted externally
+ if (_wasapi.DeviceMute)
+ _wasapi.DeviceMute = false;
+ _wasapi.Start();
+ ...
+ // now you can use recordStream to setup any DSP/FX etc.
+
+
+ Private _wasapi As BassWasapiHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ ...
+ ' assign WASAPI input in shared-mode
+ _wasapi = new BassWasapiHandler(-2, false, 48000, 2, 0f, 0f)
+ ' init and start WASAPI
+ _wasapi.Init()
+ Dim recordStream As Integer = _wasapi.InputChannel
+ ' double check, that the device is not muted externally
+ If _wasapi.DeviceMute Then
+ _wasapi.DeviceMute = False
+ End If
+ _wasapi.Start()
+ End If
+ ...
+ ' now you can use recordStream to setup any DSP/FX etc.
+
+ Setup a full-duplex stream on Wasapi input and pass that to an Wasapi output instance:
+
+ // setup a full-duplex stream
+ _wasapiInput.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, false, 2000);
+ int fullDuplexStream = _wasapiInput.OutputChannel;
+ // and assign it to an output
+ _wasapiOutput.AddOutputSource(fullDuplexStream, BASSFlag.BASS_DEFAULT);
+
+
+ ' setup a full-duplex stream
+ _wasapiInput.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, False, 2000)
+ Dim fullDuplexStream As Integer = _wasapiInput.OutputChannel
+ ' and assign it to an output
+ _wasapiOutput.AddOutputSource(fullDuplexStream, BASSFlag.BASS_DEFAULT)
+
+
+ BASS_ASIO_DEVICEINFO info = new BASS_ASIO_DEVICEINFO();
+ for (int n=0; BassAsio.BASS_ASIO_GetDeviceInfo(n, info); n++)
+ {
+ Console.WriteLine(info.ToString());
+ }
+
+
+ Dim n As Integer = 0
+ Dim info As New BASS_ASIO_DEVICEINFO()
+ While (BassAsio.BASS_ASIO_GetDeviceInfo(n, info))
+ Console.WriteLine(info.ToString())
+ n += 1
+ End While
+
+ Or use the
+ BASS_ASIO_DEVICEINFO info;
+ for (int n = 0; (info = BassAsio.BASS_ASIO_GetDeviceInfo(n)) != null; n++)
+ {
+ ...
+ }
+
+
+ Dim n As Integer = 0
+ Dim info As New BASS_ASIO_DEVICEINFO()
+ While Not (info Is Nothing)
+ info = BassAsio.BASS_ASIO_GetDeviceDescription(n)
+ If Not (info Is Nothing) Then
+ ...
+ End If
+ n += 1
+ End While
+
+ Or use the
+ // select device 2
+ BassAsio.BASS_ASIO_SetDevice(2);
+ // get the sample rate
+ double rate = BassAsio.BASS_ASIO_GetRate();
+
+
+ ' select device 2
+ BassAsio.BASS_ASIO_SetDevice(2)
+ ' get the sample rate
+ Dim rate As Double = BassAsio.BASS_ASIO_GetRate()
+
+
+ if ( Utils.HighWord(BassAsio.BASS_ASIO_GetVersion()) != BassAsio.BASSASIOVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassAsio Version!");
+ }
+
+
+ If Utils.HighWord(BassAsio.BASS_ASIO_GetVersion()) <> BassAsio.BASSASIOVERSION Then
+ MessageBox.Show(Me, "Wrong BassAsio Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassAsio.BASS_ASIO_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassAsio Version!");
+ }
+
+
+ If BassAsio.BASS_ASIO_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassAsio Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassAsio.BASS_ASIO_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassAsio Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassAsio.BASS_ASIO_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassAsio Version!")
+ End If
+
+
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ BASS_ASIO_INFO info = new BASS_ASIO_INFO();
+ if ( BassAsio.BASS_ASIO_GetInfo(info) )
+ {
+ Console.WriteLine( info.ToString() );
+ }
+
+
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ Dim info As New BASS_ASIO_INFO()
+ If BassAsio.BASS_ASIO_GetInfo(info) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ BASS_ASIO_INFO info = BassAsio.BASS_ASIO_GetInfo();
+ if ( info != null )
+ {
+ Console.WriteLine( info.ToString() );
+ }
+
+
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ Dim info As BASS_ASIO_INFO = BassAsio.BASS_ASIO_GetInfo()
+ If Not (info Is Nothing) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+
+ // get the channel info of the decoding stream
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(streamDecoding);
+ // set the source rate
+ BassAsio.BASS_ASIO_ChannelSetRate(false, 0, (double)info.freq);
+ // try to set the device rate too (saves resampling)
+ BassAsio.BASS_ASIO_SetRate( (double)info.freq );
+
+
+ ' get the channel info of the decoding stream
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(streamDecoding)
+ ' set the source rate
+ BassAsio.BASS_ASIO_ChannelSetRate(False, 0, CDbl(info.freq))
+ ' try to set the device rate too (saves resampling)
+ BassAsio.BASS_ASIO_SetRate(CDbl(info.freq))
+
+
+ using Un4seen.Bass;
+ using Un4seen.BassAsio;
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // now setup ASIO
+ _myAsioProc = new ASIOPROC(AsioCallback);
+ // enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(stream));
+ // and join the next channels to it
+ BassAsio.BASS_ASIO_ChannelJoin(false, 1, 0);
+ // and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0);
+ }
+ ...
+ private ASIOPROC _myAsioProc; // make it global, so that it can not be removed by the Garbage Collector
+ private int AsioCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // Note: 'user' contains the underlying stream channel (see above)
+ // We can simply use the bass method to get some data from a decoding channel
+ // and store it to the asio buffer in the same moment...
+ return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length);
+ }
+
+
+ Imports Un4seen.Bass
+ Imports Un4seen.BassAsio
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' now setup ASIO
+ _myAsioProc = New ASIOPROC(AddressOf AsioCallback)
+ ' enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, New IntPtr(stream))
+ ' and join the next channels to it
+ BassAsio.BASS_ASIO_ChannelJoin(False, 1, 0)
+ ' and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0)
+ End If
+ ...
+ Private _myAsioProc As ASIOPROC ' make it global, so that it can not be removed by the Garbage Collector
+ Private Function AsioCallback(input As Boolean, channel As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' Note: 'user' contains the underlying stream channel (see above)
+ ' We can simply use the bass method to get some data from a decoding channel
+ ' and store it to the asio buffer in the same moment...
+ Return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length)
+ End Function
+
+
+ // get the sample rate
+ double rate = BassAsio.BASS_ASIO_GetRate();
+ Console.WriteLine("Input Latency = {0} ms", BassAsio.BASS_ASIO_GetLatency(true) * 1000.0 / rate);
+ Console.WriteLine("Output Latency = {0} ms", BassAsio.BASS_ASIO_GetLatency(false) * 1000.0 / rate);
+
+
+ Dim rate As Double = BassAsio.BASS_ASIO_GetRate()
+ Console.WriteLine("Input Latency = {0} ms", BassAsio.BASS_ASIO_GetLatency(True) * 1000.0 / rate)
+ Console.WriteLine("Output Latency = {0} ms", BassAsio.BASS_ASIO_GetLatency(False) * 1000.0 / rate)
+
+
+ BASS_ASIO_CHANNELINFO info = new BASS_ASIO_CHANNELINFO();
+ int chan = 0;
+ while (true)
+ {
+ if (!BassAsio.BASS_ASIO_ChannelGetInfo(false, chan, info))
+ break;
+ Console.WriteLine( info.ToString() );
+ chan++;
+ }
+
+
+ Dim info As New BASS_ASIO_CHANNELINFO()
+ Dim chan As Integer = 0
+ While True
+ If Not BassAsio.BASS_ASIO_ChannelGetInfo(False, chan, info) Then
+ Exit While
+ End If
+ Console.WriteLine(info.ToString())
+ chan += 1
+ End While
+
+
+ BASS_ASIO_CHANNELINFO info = BassAsio.BASS_ASIO_ChannelGetInfo(false, 0);
+ if (info != null)
+ {
+ Console.WriteLine( info.ToString() );
+ }
+
+
+ Dim info As BASS_ASIO_CHANNELINFO = BassAsio.BASS_ASIO_ChannelGetInfo(False, 0)
+ If Not (info Is Nothing) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+
+ using Un4seen.Bass;
+ using Un4seen.BassAsio;
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // now setup ASIO
+ _myAsioProc = new ASIOPROC(AsioCallback);
+ // enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(stream));
+ // and join the next channels to it
+ BassAsio.BASS_ASIO_ChannelJoin(false, 1, 0);
+ // and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0);
+ }
+ ...
+ private ASIOPROC _myAsioProc; // make it global, so that it can not be removed by the Garbage Collector
+ private int AsioCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // Note: 'user' contains the underlying stream channel (see above)
+ // We can simply use the bass method to get some data from a decoding channel
+ // and store it to the asio buffer in the same moment...
+ return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length);
+ }
+
+
+ Imports Un4seen.Bass
+ Imports Un4seen.BassAsio
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' now setup ASIO
+ _myAsioProc = New ASIOPROC(AddressOf AsioCallback)
+ ' enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, New IntPtr(stream))
+ ' and join the next channels to it
+ BassAsio.BASS_ASIO_ChannelJoin(False, 1, 0)
+ ' and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0)
+ End If
+ ...
+ Private _myAsioProc As ASIOPROC ' make it global, so that it can not be removed by the Garbage Collector
+ Private Function AsioCallback(input As Boolean, channel As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' Note: 'user' contains the underlying stream channel (see above)
+ ' We can simply use the bass method to get some data from a decoding channel
+ ' and store it to the asio buffer in the same moment...
+ Return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length)
+ End Function
+
+
+ // enable processing of output channel 0
+ BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, 0);
+ // join channel 1 to it
+ BassAsio.BASS_ASIO_ChannelJoin(false, 1, 0);
+
+
+ ' enable processing of output channel 0
+ BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, 0)
+ ' join channel 1 to it
+ BassAsio.BASS_ASIO_ChannelJoin(False, 1, 0)
+
+
+ BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
+
+
+ BassAsio.BASS_ASIO_ChannelSetFormat(False, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT)
+
+
+ // set the device rate
+ BassAsio.BASS_ASIO_SetRate(44100);
+ // set the channel's rate
+ BassAsio.BASS_ASIO_ChannelSetRate(false, 0, 44100);
+
+
+ ' set the device rate
+ BassAsio.BASS_ASIO_SetRate(44100)
+ ' set the channel's rate
+ BassAsio.BASS_ASIO_ChannelSetRate(False, 0, 44100)
+
+
+ BassAsio.BASS_ASIO_ChannelReset(false, -1, BASSASIOReset.BASS_ASIO_RESET_ENABLE | BASSASIOReset.BASS_ASIO_RESET_JOIN);
+
+
+ BassAsio.BASS_ASIO_ChannelReset(False, -1, BASSASIOReset.BASS_ASIO_RESET_ENABLE Or BASSASIOReset.BASS_ASIO_RESET_JOIN);
+
+
+ // get the linear level
+ float level = BassAsio.BASS_ASIO_ChannelSetVolume(false, 0);
+ // translate it to logarithmic dB
+ double db = 20.0 * Math.Log10(level);
+
+
+ ' get the linear level
+ Dim level As Single = BassAsio.BASS_ASIO_ChannelSetVolume(False, 0)
+ ' translate it to logarithmic dB
+ Dim db As Double = 20.0 * Math.Log10(level)
+
+
+ using Un4seen.Bass;
+ using Un4seen.BassAsio;
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // now setup ASIO
+ _myAsioProc = new ASIOPROC(AsioCallback);
+ // enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(stream));
+ // mirror it to channel 1
+ BassAsio.BASS_ASIO_ChannelEnableMirror(1, false, 0);
+ // and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0);
+ }
+ ...
+ private ASIOPROC _myAsioProc; // make it global, so that it can not be removed by the GC
+ private int AsioCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // Note: 'user' contains the underlying stream channel (see above)
+ // We can simply use the bass method to get some data from a decoding channel
+ // and store it to the asio buffer in the same moment...
+ return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length);
+ }
+
+
+ Imports Un4seen.Bass
+ Imports Un4seen.BassAsio
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' now setup ASIO
+ _myAsioProc = New ASIOPROC(AddressOf AsioCallback)
+ ' enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, New IntPtr(stream))
+ // mirror it to channel 1
+ BassAsio.BASS_ASIO_ChannelEnableMirror(1, False, 0)
+ ' and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0)
+ End If
+ ...
+ Private _myAsioProc As ASIOPROC ' make it global, so that it can not be removed by the GC
+ Private Function AsioCallback(input As Boolean, channel As Integer, buffer As IntPtr,
+ length As Integer, user As IntPtr) As Integer
+ ' Note: 'user' contains the underlying stream channel (see above)
+ ' We can simply use the bass method to get some data from a decoding channel
+ ' and store it to the asio buffer in the same moment...
+ Return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length)
+ End Function
+
+
+ // translate logarithmic dB level to linear
+ float volume = (float)Math.Pow(10d, db / 20d);
+ // apply it
+ BassAsio.BASS_ASIO_ChannelSetVolume(false, 0 , volume);
+
+
+ ' translate logarithmic dB level to linear
+ Dim volume As Single = CSng(Math.Pow(10.0, db / 20.0))
+ ' apply it
+ BassAsio.BASS_ASIO_ChannelSetVolume(False, 0, volume)
+
+
+ Bass.LoadMe();
+ BassWma.LoadMe();
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassWma.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // now setup ASIO
+ _myAsioProc = new ASIOPROC(AsioCallback);
+ // get the stream channel info
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ // enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(stream));
+ // and join the next channels to it
+ for (int a=1; a<info.chans; a++)
+ BassAsio.BASS_ASIO_ChannelJoin(false, a, 0);
+ // since we joined the channels, the next commands will apply to all channles joined
+ // so setting the values to the first channels changes them all automatically
+ // set the source format (float, as the decoding channel is)
+ BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
+ // set the source rate
+ BassAsio.BASS_ASIO_ChannelSetRate(false, 0, (double)info.freq);
+ // try to set the device rate too (saves resampling)
+ BassAsio.BASS_ASIO_SetRate( (double)info.freq );
+ // and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0);
+ }
+ ...
+ private ASIOPROC _myAsioProc; // make it global, so that it can not be removed by the GC
+ private int AsioCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // Note: 'user' contains the underlying stream channel (see above)
+ // We can simply use the bass method to get some data from a decoding channel
+ // and store it to the asio buffer in the same moment...
+ return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length);
+ }
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' now setup ASIO
+ _myAsioProc = New ASIOPROC(AsioCallback)
+ ' get the stream channel info
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ ' enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, New IntPtr(stream))
+ ' and join the next channels to it
+ Dim a As Integer
+ For a = 1 To info.chans - 1
+ BassAsio.BASS_ASIO_ChannelJoin(False, a, 0)
+ Next a
+ ' since we joined the channels, the next commands will apply to all channles joined
+ ' so setting the values to the first channels changes them all automatically
+ ' set the source format (float, as the decoding channel is)
+ BassAsio.BASS_ASIO_ChannelSetFormat(False, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT)
+ ' set the source rate
+ BassAsio.BASS_ASIO_ChannelSetRate(False, 0, CDbl(info.freq))
+ ' try to set the device rate too (saves resampling)
+ BassAsio.BASS_ASIO_SetRate(CDbl(info.freq))
+ ' and start playing it...start output using default buffer/latency
+ BassAsio.BASS_ASIO_Start(0)
+ End If
+ ...
+ Private _myAsioProc As ASIOPROC ' make it global, so that it can not be removed by the GC
+ Private Function AsioCallback(input As Boolean, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' Note: 'user' contains the underlying stream channel (see above)
+ ' We can simply use the bass method to get some data from a decoding channel
+ ' and store it to the asio buffer in the same moment...
+ Return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length)
+ End Function
+
+ Setting up a full-duplex input to output handler:
+
+ private byte[] _fullDuplexAsioBuffer;
+ private int _numchans = 2;
+
+ private void SetFullDuplex()
+ {
+ BASS_ASIO_INFO info = BassAsio.BASS_ASIO_GetInfo();
+ _fullDuplexAsioBuffer = new byte[info.bufmax * _numchans * 4];
+ ...
+ }
+
+ private int AsioToAsioFullDuplexCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (input)
+ {
+ if (_fullDuplexAsioBuffer.Length < length)
+ _fullDuplexAsioBuffer = new byte[length];
+ Marshal.Copy(buffer, _fullDuplexAsioBuffer, 0, length);
+ return 0;
+ }
+ else
+ {
+ if (length > _fullDuplexAsioBuffer.Length)
+ length = _fullDuplexAsioBuffer.Length;
+ Marshal.Copy(_fullDuplexAsioBuffer, 0, buffer, length);
+ return length;
+ }
+ }
+
+
+ Private _fullDuplexAsioBuffer As Byte()
+ Private _numchans As Integer = 2
+
+ Private Sub SetFullDuplex()
+ Dim info As BASS_ASIO_INFO = BassAsio.BASS_ASIO_GetInfo()
+ _fullDuplexAsioBuffer = New Byte(info.bufmax * _numchans * 4 - 1) {}
+ ...
+ End Sub
+
+ Private Function AsioToAsioFullDuplexCallback(ByVal input As Boolean, ByVal channel As Integer,
+ ByVal buffer As IntPtr, ByVal length As Integer,
+ ByVal user As IntPtr) As Integer
+ If input Then
+ If _fullDuplexAsioBuffer.Length < length Then
+ _fullDuplexAsioBuffer = New Byte(length - 1) {}
+ End If
+ Marshal.Copy(buffer, _fullDuplexAsioBuffer, 0, length)
+ Return 0
+ Else
+ If length > _fullDuplexAsioBuffer.Length Then
+ length = _fullDuplexAsioBuffer.Length
+ End If
+ Marshal.Copy(_fullDuplexAsioBuffer, 0, buffer, length)
+ Return length
+ End If
+ End Function
+
+
+ private BassAsioHandler _asio;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // assign ASIO output to the first device and channel
+ // and assume the ASIO format, samplerate and number of channels from the BASS stream
+ _asio = new BassAsioHandler(0, 0, stream);
+ // start ASIO
+ _asio.Start(0);
+ }
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' assign ASIO output to the first device and channel
+ ' and assume the ASIO format, samplerate and number of channels from the BASS stream
+ _asio = New BassAsioHandler(0, 0, stream)
+ ' start ASIO
+ _asio.Start(0)
+ End If
+
+ Automatic use of the BassAsioHandler (Asio recording input, Asio full-duplex output):
+
+ private BassAsioHandler _asio;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ // assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
+ // set the full-duplex option to the first ASIO output device and channel
+ // the ASIO output format will aways be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0);
+ // start ASIO
+ _asio.Start(0);
+ ...
+ // when you want to disbale all associated channels, call:
+ _asio.Dispose();
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ ' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
+ ' set the full-duplex option to the first ASIO output device and channel
+ ' the ASIO output format will aways be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0)
+ ' start ASIO
+ _asio.Start(0)
+ ...
+ ' when you want to disbale all associated channels, call:
+ _asio.Dispose()
+
+
+ private ASIOPROC _myAsioProc;
+ private BassAsioHandler _asio;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ _asio = new BassAsioHandler();
+ _asio.OutputChannel = stream;
+
+ // now setup ASIO manually
+ _myAsioProc = new ASIOPROC(_asio.BassToAsioOutputCallback);
+ // get the stream channel info
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ // enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, stream);
+ // and join the next channels to it
+ for (int a=1; a<info.chans; a++)
+ BassAsio.BASS_ASIO_ChannelJoin(false, a, 0);
+ // since we joined the channels, the next commands will apply to all channles joined
+ // so setting the values to the first channels changes them all automatically
+ // set the source format (float, as the decoding channel is)
+ BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
+ // set the source rate
+ BassAsio.BASS_ASIO_ChannelSetRate(false, 0, (double)info.freq);
+ // try to set the device rate too (saves resampling)
+ BassAsio.BASS_ASIO_SetRate( (double)info.freq );
+ // and start playing it...start output using default buffer/latency
+ _asio.Start(0);
+ }
+
+
+ Private _myAsioProc As ASIOPROC
+ Private _asio As BassAsioHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ _asio = New BassAsioHandler()
+ _asio.OutputChannel = stream
+
+ ' now setup ASIO manually
+ _myAsioProc = New ASIOPROC(AddressOf _asio.BassToAsioOutputCallback)
+ ' get the stream channel info
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ ' enable 1st output channel...(0=first)
+ BassAsio.BASS_ASIO_ChannelEnable(False, 0, _myAsioProc, stream)
+ ' and join the next channels to it
+ Dim a As Integer
+ For a = 1 To info.chans - 1
+ BassAsio.BASS_ASIO_ChannelJoin(False, a, 0)
+ Next a
+ ' since we joined the channels, the next commands will apply to all channles joined
+ ' so setting the values to the first channels changes them all automatically
+ ' set the source format (float, as the decoding channel is)
+ BassAsio.BASS_ASIO_ChannelSetFormat(False, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT)
+ ' set the source rate
+ BassAsio.BASS_ASIO_ChannelSetRate(False, 0, CDbl(info.freq))
+ ' try to set the device rate too (saves resampling)
+ BassAsio.BASS_ASIO_SetRate(CDbl(info.freq))
+ ' and start playing it...start output using default buffer/latency
+ _asio.Start(0)
+ End If
+
+
+ private BassAsioHandler _asio;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ // assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
+ // set the full-duplex option to the first ASIO output device and channel
+ // the ASIO output format will aways be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0);
+ // start ASIO
+ _asio.Start(0);
+ ...
+ // when you want to disbale all associated channels, call:
+ _asio.Dispose();
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ ' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
+ ' set the full-duplex option to the first ASIO output device and channel
+ ' the ASIO output format will aways be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0)
+ ' start ASIO
+ _asio.Start(0)
+ ...
+ ' when you want to disbale all associated channels, call:
+ _asio.Dispose()
+
+
+ private BassAsioHandler _asio;
+ ...
+ // not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
+ // setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD);
+ ...
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // assign ASIO output to the first device and channel
+ // and assume the ASIO format, samplerate and number of channels from the BASS stream
+ _asio = new BassAsioHandler(0, 0, stream);
+ // start ASIO
+ _asio.Start(0);
+ }
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' not playing anything via BASS, so don't need an update thread
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0)
+ ' setup BASS - "no sound" device but 48000 (default for ASIO)
+ Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_THREAD)
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' assign ASIO output to the first device and channel
+ ' and assume the ASIO format, samplerate and number of channels from the BASS stream
+ _asio = New BassAsioHandler(0, 0, stream)
+ ' start ASIO
+ _asio.Start(0)
+ End If
+
+
+ private BassAsioHandler _asio;
+ ...
+ int stream = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ if (stream != 0)
+ {
+ // assign ASIO output to the first device and channel
+ // and assume the ASIO format, samplerate and number of channels from the BASS stream
+ _asio = new BassAsioHandler(0, 0, stream);
+ // start ASIO
+ BassAsio.BASS_ASIO_Start(0);
+ }
+ ...
+ // assign a new channel to ASIO output
+ Bass.BASS_StreamFree(stream);
+ int newStream = Bass.BASS_StreamCreateFile(newFileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT );
+ _asio.AssignOutputChannel(newStream);
+
+
+ Private _asio As BassAsioHandler
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(fileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ If stream <> 0 Then
+ ' assign ASIO output to the first device and channel
+ ' and assume the ASIO format, samplerate and number of channels from the BASS stream
+ _asio = New BassAsioHandler(0, 0, stream)
+ ' start ASIO
+ BassAsio.BASS_ASIO_Start(0)
+ End If
+ ...
+ ' assign a new channel to ASIO output
+ Bass.BASS_StreamFree(stream)
+ Dim newStream As Integer = Bass.BASS_StreamCreateFile(newFileName, 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ _asio.AssignOutputChannel(newStream)
+
+
+ private BassAsioHandler _asio;
+ private DSP_PeakLevelMeter _plm;
+ ...
+ // assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
+ // set the full-duplex option to the first ASIO output device and channel
+ // the ASIO output format will always be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0);
+
+ // set up a ready-made DSP (here the PeakLevelMeter) on the full-duplex channel
+ _plm = new DSP_PeakLevelMeter(_asio.OutputChannel, 0);
+ _plm.UpdateTime = 0.1f; // 100ms
+ _plm.CalcRMS = true;
+ _plm.Notification += new EventHandler(OnPlmNotification);
+
+ // start ASIO
+ BassAsio.BASS_ASIO_Start(0);
+ ...
+ private void OnPlmNotification(object sender, EventArgs e)
+ {
+ if (_plm == null)
+ return;
+ // sender will be the DSP_PeakLevelMeter instance
+ // you could also access it via: DSP_PeakLevelMeter p = (DSP_PeakLevelMeter)sender;
+ this.progressBarPeak1Left.Value = _plm.LevelL;
+ this.progressBarPeak1Right.Value = _plm.LevelR;
+ this.labelLevel1.Text = String.Format( "RMS: {0:#00.0} dB AVG: {1:#00.0} dB Peak: {2:#00.0} dB",
+ _plm.RMS_dBV, _plm.AVG_dBV, Math.Max(_plm.PeakHoldLevelL_dBV, _plm.PeakHoldLevelR_dBV) );
+ }
+
+
+ Private _asio As BassAsioHandler
+ Private _plm As DSP_PeakLevelMeter
+ ...
+ ' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
+ ' set the full-duplex option to the first ASIO output device and channel
+ ' the ASIO output format will always be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0)
+
+ ' set up a ready-made DSP (here the PeakLevelMeter) on the full-duplex channel
+ _plm = New DSP_PeakLevelMeter(_asio.OutputChannel, 0)
+ _plm.UpdateTime = 0.1F ' 100ms
+ _plm.CalcRMS = True
+ AddHandler _plm.Notification, AddressOf OnPlmNotification
+
+ ' start ASIO
+ BassAsio.BASS_ASIO_Start(0)
+ ...
+ Private Sub OnPlmNotification(sender As Object, e As EventArgs)
+ If _plm Is Nothing Then
+ Return
+ End If
+ ' sender will be the DSP_PeakLevelMeter instance
+ ' you could also access it via:
+ ' Dim p As DSP_PeakLevelMeter = CType(sender, DSP_PeakLevelMeter)
+ Me.progressBarPeak1Left.Value = _plm.LevelL
+ Me.progressBarPeak1Right.Value = _plm.LevelR
+ Me.labelLevel1.Text = [String].Format("RMS: {0:#00.0} dB AVG: {1:#00.0} dB Peak: {2:#00.0} dB",
+ _plm.RMS_dBV, _plm.AVG_dBV, Math.Max(_plm.PeakHoldLevelL_dBV, _plm.PeakHoldLevelR_dBV))
+ End Sub
+
+
+ private BassAsioHandler _asio;
+ ...
+ // assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
+ // set the full-duplex option to the first BASS output device using the rear speakers
+ // the BASS output format will always be the same as the ASIO input for full-duplex
+ _asio.SetFullDuplex(1, BASSFlag.BASS_SPEAKER_REAR, true);
+
+ // start ASIO
+ BassAsio.BASS_ASIO_Start(0);
+ _asio.ResetFullDuplex();
+
+ // setup an FX on the full-duplex BASS output
+ BASS_FXECHO echo = new BASS_FXECHO();
+ int fxHandle = Bass.BASS_ChannelSetFX(_asio.OutputChannel, BASSFXType.BASS_FX_ECHO, 0);
+ echo.Preset_Long();
+ // apply the effect parameters
+ Bass.BASS_FXSetParameters(fxHandle, echo);
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
+ ' set the full-duplex option to the first BASS output device using the rear speakers
+ ' the BASS output format will always be the same as the ASIO input for full-duplex
+ _asio.SetFullDuplex(1, BASSFlag.BASS_SPEAKER_REAR, True)
+
+ ' start ASIO
+ BassAsio.BASS_ASIO_Start(0)
+ _asio.ResetFullDuplex()
+
+ ' setup an FX on the full-duplex BASS output
+ Dim echo As New BASS_FXECHO()
+ Dim fxHandle As Integer = Bass.BASS_ChannelSetFX(_asio.OutputChannel, BASSFXType.BASS_FX_ECHO, 0)
+ echo.Preset_Long()
+ ' apply the effect parameters
+ Bass.BASS_FXSetParameters(fxHandle, echo)
+
+
+ private BassAsioHandler _asio;
+ ...
+ // assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
+ // set the full-duplex option to the first ASIO output device and channel
+ // the ASIO output format will aways be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0); // first output device and channel
+ // start ASIO
+ _asio.Start(0);
+ ...
+ // remove the full-duplex option and leave the channel enabled
+ _asio.RemoveFullDuplex(false);
+ // but pause the unused output channel
+ BassAsio.BASS_ASIO_ChannelPause(false, 0);
+ ...
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
+ ' set the full-duplex option to the first ASIO output device and channel
+ ' the ASIO output format will aways be the same as the input for full-duplex
+ _asio.SetFullDuplex(0, 0) ' first output device and channel
+ ' start ASIO
+ _asio.Start(0)
+ ...
+ ' remove the full-duplex option and leave the channel enabled
+ _asio.RemoveFullDuplex(False)
+ ' but pause the unused output channel
+ BassAsio.BASS_ASIO_ChannelPause(False, 0)
+ ...
+
+
+ private BassAsioHandler _asio;
+ ...
+ // assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
+ // set the mirror option to the first ASIO output device and channel
+ _asio.SetMirror(0);
+ ...
+ // start ASIO
+ _asio.Start(0);
+ ...
+ // remove the mirror when not needed
+ _asio.RemoveMirror();
+ ...
+
+
+ Private _asio As BassAsioHandler
+ ...
+ ' assign ASIO input to the first device and channel (stereo, 32-bit float, 48kHz)
+ _asio = New BassAsioHandler(True, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000)
+ ' set the mirror option to the first ASIO output device and channel
+ _asio.SetMirror(0)
+ ...
+ ' start ASIO
+ _asio.Start(0)
+ ...
+ ' remove the mirror when not needed
+ _asio.RemoveMirror()
+ ...
+
+
+ public class MyAsioHandler : BassAsioHandler
+ {
+
+ public override int AsioOutputCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // buffer is not filled
+ // do your own stuff here...
+ int len = base.AsioOutputCallback(input, channel, buffer, length, user);
+ if (len > 0)
+ {
+ // buffer is already filled
+ // do your own stuff here...
+ }
+ return len;
+ }
+
+ }
+
+
+ Public Class MyAsioHandler
+ Inherits BassAsioHandler
+
+ Public Overrides Function AsioOutputCallback(input As Boolean, channel As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' buffer is already filled
+ ' do your own stuff here...
+ Dim len As Integer = MyBase.AsioOutputCallback(input, channel, buffer, length, user)
+ If len > 0 Then
+ ' buffer is already filled
+ ' do your own stuff here...
+ End If
+ Return len
+ End Function
+
+ End Class
+
+
+ public class MyAsioHandler : BassAsioHandler
+ {
+
+ public override int AsioInputCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // InputChannel not applied yet
+ // do your own stuff here...
+ int len = base.AsioInputCallback(input, channel, buffer, length, user);
+ // InputChannel already applied
+ // do your own stuff here...
+ return len;
+ }
+
+ }
+
+
+ Public Class MyAsioHandler
+ Inherits BassAsioHandler
+
+ Public Overrides Function AsioInputCallback(input As Boolean, channel As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' InputChannel not applied yet
+ ' do your own stuff here...
+ Dim len As Integer = MyBase.AsioInputCallback(input, channel, buffer, length, user)
+ ' InputChannel already applied
+ ' do your own stuff here...
+ Return len
+ End Function
+
+ End Class
+
+
+ public class MyAsioHandler : BassAsioHandler
+ {
+
+ public override int AsioToAsioFullDuplexCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // FullDuplex not applied yet
+ if (input)
+ {
+ // do your own input stuff here...
+ }
+ else
+ {
+ // do your own output stuff here...
+ }
+ int len = base.AsioToAsioFullDuplexCallback(input, channel, buffer, length, user);
+ // FullDuplex already applied
+ if (input)
+ {
+ // do your own input stuff here...
+ }
+ else
+ {
+ // do your own output stuff here...
+ }
+ return len;
+ }
+
+ }
+
+
+ Public Class MyAsioHandler
+ Inherits BassAsioHandler
+
+ Public Overrides Function AsioToAsioFullDuplexCallback(input As Boolean, channel As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' FullDuplex not applied yet
+ If input Then
+ ' do your own input stuff here...
+ Else
+ ' do your own output stuff here...
+ End If
+ Dim len As Integer = MyBase.AsioToAsioFullDuplexCallback(input, channel, buffer, length, user)
+ ' FullDuplex already applied
+ If input Then
+ ' do your own input stuff here...
+ Else
+ ' do your own output stuff here...
+ End If
+ Return len
+ End Function
+
+ End Class
+
+
+ public class MyAsioHandler : BassAsioHandler
+ {
+
+ public override int AsioToBassFullDuplexCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // FullDuplex not applied yet
+ if (input)
+ {
+ // do your own input stuff here...
+ }
+ else
+ {
+ // do your own output stuff here...
+ }
+ int len = base.AsioToBassFullDuplexCallback(input, channel, buffer, length, user);
+ // FullDuplex already applied
+ if (input)
+ {
+ // do your own input stuff here...
+ }
+ else
+ {
+ // do your own output stuff here...
+ }
+ return len;
+ }
+
+ }
+
+
+ Public Class MyAsioHandler
+ Inherits BassAsioHandler
+
+ Public Overrides Function AsioToBassFullDuplexCallback(input As Boolean, channel As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ ' FullDuplex not applied yet
+ If input Then
+ ' do your own input stuff here...
+ Else
+ ' do your own output stuff here...
+ End If
+ Dim len As Integer = MyBase.AsioToBassFullDuplexCallback(input, channel, buffer, length, user)
+ ' FullDuplex already applied
+ If input Then
+ ' do your own input stuff here...
+ Else
+ ' do your own output stuff here...
+ End If
+ Return len
+ End Function
+
+ End Class
+
+
+ if ( Utils.HighWord(BassFx.BASS_FX_GetVersion()) != BassFx.BASSFXVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassFx Version!");
+ }
+
+
+ If Utils.HighWord(BassFx.BASS_FX_GetVersion()) <> BassFx.BASSFXVERSION Then
+ MessageBox.Show(Me, "Wrong BassFx Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassFx.BASS_FX_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassFx Version!");
+ }
+
+
+ If BassFx.BASS_FX_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassFx Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassFx.BASS_FX_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassFx Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassFx.BASS_FX_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassFx Version!")
+ End If
+
+
+ // the source channel
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ // the tempo channel
+ int streamFX = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE);
+ ...
+ // change the sampling rate by 20%, the streamFX will be played faster
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, 0.2f);
+
+ // change the tempo by -15%, the streamFX will be slower
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_TEMPO, -0.15f);
+
+ // change the pitch (key) by one octave (12 semitones)
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_TEMPO, 12f);
+
+
+ ' the source channel
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ ' the tempo channel
+ Dim streamFX As Integer = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE)
+ ...
+ ' change the sampling rate by 20%, the streamFX will be played faster
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, 0.2F)
+
+ ' change the tempo by -15%, the streamFX will be slower
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_TEMPO, -0.15F)
+
+ ' change the pitch (key) by one octave (12 semitones)
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_TEMPO, 12F)
+
+
+ // the source channel
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ // the tempo channel
+ int streamFX = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE);
+ ...
+ // this will return 'stream'
+ int chan = BassFx.BASS_FX_TempoGetSource(streamFX);
+
+
+ ' the source channel
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ ' the tempo channel
+ Dim streamFX As Integer = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE)
+ ...
+ ' this will return 'stream'
+ Dim chan As Integer = BassFx.BASS_FX_TempoGetSource(streamFX);
+
+
+ float ratio = BassFx.BASS_FX_TempoGetRateRatio(streamFX);
+
+
+ Dim ratio As Single = BassFx.BASS_FX_TempoGetRateRatio(streamFX)
+
+
+ // the source channel
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE |
+ BASSFlag.BASS_STREAM_PRESCAN);
+ // the reverse channel
+ int streamFX = BassFx.BASS_FX_ReverseCreate(stream, 2f, BASSFlag.BASS_FX_FREESOURCE);
+ ...
+ // play the channel reverse
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, -1f);
+ // or
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, (float)BASSFXReverse.BASS_FX_RVS_REVERSE);
+
+ // play the channel forward
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, 1f);
+ // or
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, (float)BASSFXReverse.BASS_FX_RVS_FORWARD);
+
+
+ ' the source channel
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE Or
+ BASSFlag.BASS_STREAM_PRESCAN)
+ ' the tempo channel
+ Dim streamFX As Integer = BassFx.BASS_FX_ReverseCreate(stream, 2F, BASSFlag.BASS_FX_FREESOURCE)
+ ...
+ ' play the channel reverse
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, -1F)
+ ' or
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, CSng(BASSFXReverse.BASS_FX_RVS_REVERSE))
+
+ ' play the channel forward
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, 1F)
+ ' or
+ Bass.BASS_ChannelSetAttribute(streamFX, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, CSng(BASSFXReverse.BASS_FX_RVS_FORWARD))
+
+
+ // the source channel
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE |
+ BASSFlag.BASS_STREAM_PRESCAN);
+ // the reverse channel
+ int streamFX = BassFx.BASS_FX_ReverseCreate(stream, 2f, BASSFlag.BASS_FX_FREESOURCE);
+ ...
+ // this will return 'stream'
+ int chan = BassFx.BASS_FX_ReverseGetSource(streamFX);
+
+
+ ' the source channel
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE Or
+ BASSFlag.BASS_STREAM_PRESCAN)
+ ' the tempo channel
+ Dim streamFX As Integer = BassFx.BASS_FX_ReverseCreate(stream, 2F, BASSFlag.BASS_FX_FREESOURCE)
+ ...
+ ' this will return 'stream'
+ Dim chan As Integer = BassFx.BASS_FX_ReverseGetSource(streamFX);
+
+
+ private BPMPROCESSPROC _bpmProc;
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ _bpmProc = new BPMPROCESSPROC(MyBPMProc);
+ float bpm = BassFx.BASS_FX_BPM_DecodeGet(stream, 0.0, 120.0, 0, BASSFXBpm.BASS_FX_BPM_BKGRND |
+ BASSFXBpm.BASS_FX_FREESOURCE |
+ BASSFXBpm.BASS_FX_BPM_MULT2, _bpmProc);
+ BassFx.BASS_FX_BPM_Free(stream);
+ ...
+ private void MyBPMProc(int channel, float percent)
+ {
+ Console.Write("{0}%\r", percent);
+ }
+
+
+ Private _bpmProc As BPMPROCESSPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ _bpmProc = New BPMPROCESSPROC(AddressOf MyBPMProc)
+ Dim bpm As Single = BassFx.BASS_FX_BPM_DecodeGet(stream, 0.0, 120.0, 0, BASSFXBpm.BASS_FX_BPM_BKGRND Or
+ BASSFXBpm.BASS_FX_FREESOURCE Or
+ BASSFXBpm.BASS_FX_BPM_MULT2, _bpmProc)
+ BassFx.BASS_FX_BPM_Free(stream)
+ ...
+ Private Sub MyBPMProc(channel As Integer, percent As Single)
+ Console.Write("{0}%\r", percent)
+ End Sub
+
+
+ private BPMBEATPROC _beatProc;
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ _beatProc = new BPMBEATPROC(MyBeatProc);
+ BassFx.BASS_FX_BPM_BeatDecodeGet(stream, 0.0, 60.0, BASSFXBpm.BASS_FX_BPM_BKGRND, _beatProc, IntPtr.Zero);
+ BassFx.BASS_FX_BPM_BeatFree(stream);
+ ...
+ private void MyBeatProc(int channel, double beatpos, IntPtr user)
+ {
+ Console.WriteLine("Beat at: {0}", beatpos);
+ }
+
+
+ Private _beatProc As BPMBEATPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ _beatProc = New BPMBEATPROC(AddressOf MyBeatProc)
+ BassFx.BASS_FX_BPM_BeatDecodeGet(stream, 0.0, 60.0, BASSFXBpm.BASS_FX_BPM_BKGRND, _beatProc, IntPtr.Zero)
+ BassFx.BASS_FX_BPM_BeatFree(stream)
+ ...
+ Private Sub MyBeatProc(channel As Integer, beatpos As Double, user As IntPtr)
+ Console.WriteLine("Beat at: {0}", beatpos)
+ End Sub
+
+
+ private float GetNewBPM(int sourceChannel, int tempoChannel)
+ {
+ return BassFx.BASS_FX_BPM_Translate(sourceChannel,
+ BassFx.BASS_FX_TempoGetRateRatio(tempoChannel) * 100f,
+ BASSFXBpmTrans.BASS_FX_BPM_PERCENT2);
+ }
+
+
+ Private Function GetNewBPM(sourceChannel As Integer, tempoChannel As Integer) As Single
+ Return BassFx.BASS_FX_BPM_Translate(sourceChannel,
+ BassFx.BASS_FX_TempoGetRateRatio(tempoChannel) * 100F,
+ BASSFXBpmTrans.BASS_FX_BPM_PERCENT2)
+ End Function
+
+
+ private BPMPROC _bpmProc;
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ _bpmProc = new BPMPROC(MyBPMProc);
+ BassFx.BASS_FX_BPM_CallbackSet(stream, _bpmProc, 10.0, Utils.MakeLong(45,240),
+ BASSFXBpm.BASS_FX_BPM_MULT2, IntPtr.Zero);
+ ...
+ private void MyBPMProc(int handle, float bpm, IntPtr user)
+ {
+ Console.Write("BPM: {0}\r", bpm);
+ }
+
+
+ Private _bpmProc As BPMPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ _bpmProc = New BPMPROC(MyBPMProc)
+ BassFx.BASS_FX_BPM_CallbackSet(stream, _bpmProc, 10.0, Utils.MakeLong(45, 240),
+ BASSFXBpm.BASS_FX_BPM_MULT2, IntPtr.Zero)
+ ...
+ Private Sub MyBPMProc(handle As Integer, bpm As Single, user As IntPtr)
+ Console.Write("BPM: {0}" + ControlChars.Cr, bpm)
+ End Sub
+
+
+ private BPMBEATPROC _beatProc;
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ _beatProc = new BPMBEATPROC(MyBeatProc);
+ BassFx.BASS_FX_BPM_BeatCallbackSet(stream, _beatProc, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void MyBeatProc(int channel, double beatpos, IntPtr user)
+ {
+ Console.WriteLine("Beat at: {0}", beatpos);
+ }
+
+
+ Private _beatProc As BPMBEATPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT)
+ _beatProc = New BPMBEATPROC(AddressOf MyBeatProc)
+ BassFx.BASS_FX_BPM_BeatCallbackSet(stream, _beatProc, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub MyBeatProc(channel As Integer, beatpos As Double, user As IntPtr)
+ Console.WriteLine("Beat at: {0}", beatpos)
+ End Sub
+
+
+ private BPMBEATPROC _beatProc;
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ _beatProc = new BPMBEATPROC(MyBeatProc);
+ BassFx.BASS_FX_BPM_BeatCallbackSet(stream, _beatProc, IntPtr.Zero);
+ BassFx.BASS_FX_BPM_BeatSetParameters(stream, 20f, 110f, 24f);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void MyBeatProc(int channel, double beatpos, IntPtr user)
+ {
+ Console.WriteLine("Beat at: {0}", beatpos);
+ }
+
+
+ Private _beatProc As BPMBEATPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT)
+ _beatProc = New BPMBEATPROC(AddressOf MyBeatProc)
+ BassFx.BASS_FX_BPM_BeatCallbackSet(stream, _beatProc, IntPtr.Zero)
+ BassFx.BASS_FX_BPM_BeatSetParameters(stream, 20F, 240F, 24F)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub MyBeatProc(channel As Integer, beatpos As Double, user As IntPtr)
+ Console.WriteLine("Beat at: {0}", beatpos)
+ End Sub
+
+
+ float bandwidth = 0f;
+ float centerfreq = 0f;
+ float beat_rtime = 0f;
+ if (BassFx.BASS_FX_BPM_BeatGetParameters(stream, ref bandwidth, ref centerfreq, ref beat_rtime))
+ {
+ Console.WriteLine("Bandwidth={0}, Center-Freq={1}, Release-Time={2}", bandwidth, centerfreq, beat_rtime);
+ }
+
+
+ Dim bandwidth As Single = 0F
+ Dim centerfreq As Single = 0F
+ Dim beat_rtime As Single = 0F
+ If BassFx.BASS_FX_BPM_BeatGetParameters(stream, bandwidth, centerfreq, beat_rtime) Then
+ Console.WriteLine("Bandwidth={0}, Center-Freq={1}, Release-Time={2}", bandwidth, centerfreq, beat_rtime)
+ End If
+
+
+ object beat_rtime = 0f;
+ if (BassFx.BASS_FX_BPM_BeatGetParameters(stream, null, null, beat_rtime))
+ {
+ // beat_rtime must be casted back to a float
+ Console.WriteLine("Release-Time={0}", (float)beat_rtime);
+ }
+
+
+ Dim beat_rtime As Object = 0F
+ If BassFx.BASS_FX_BPM_BeatGetParameters(stream, Nothing, Nothing, beat_rtime) Then
+ ' beat_rtime must be casted back to a float
+ Console.WriteLine("Release-Time={0}", CSng(beat_rtime))
+ End If
+
+
+ Bass.LoadMe();
+ BassFx.LoadMe();
+ ...
+ // when not used anymore...
+ BassFx.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassFx.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassFx.FreeMe();
+ Bass.FreeMe();
+
+
+ lChannel[0] = BASSFXChan.BASS_BFX_CHAN1 | BASSFXChan.BASS_BFX_CHAN5
+
+
+ lChannel[0] = BASSFXChan.BASS_BFX_CHAN2
+ lChannel[1] = BASSFXChan.BASS_BFX_CHAN1
+
+
+ lChannel[0] = BASSFXChan.BASS_BFX_CHAN1
+ lChannel[1] = BASSFXChan.BASS_BFX_CHAN1
+
+
+ lChannel[0] = BASSFXChan.BASS_BFX_CHANNONE
+ lChannel[1] = BASSFXChan.BASS_BFX_CHAN1
+ lChannel[2] = BASSFXChan.BASS_BFX_CHAN1
+
+
+ lChannel[0] = BASSFXChan.BASS_BFX_CHAN1 | BASSFXChan.BASS_BFX_CHAN3 | BASSFXChan.BASS_BFX_CHAN5
+ lChannel[1] = BASSFXChan.BASS_BFX_CHAN2 | BASSFXChan.BASS_BFX_CHAN4 | BASSFXChan.BASS_BFX_CHAN6
+ lChannel[2] = BASSFXChan.BASS_BFX_CHANNONE
+ lChannel[3] = BASSFXChan.BASS_BFX_CHANNONE
+ lChannel[4] = BASSFXChan.BASS_BFX_CHANNONE
+ lChannel[5] = BASSFXChan.BASS_BFX_CHANNONE
+
+
+ BASS_BFX_MIX swap = new BASS_BFX_MIX(BASSFXChan.BASS_BFX_CHAN2, BASSFXChan.BASS_BFX_CHAN1);
+ int channel = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ int fxMix = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_MIX, 0);
+ Bass.BASS_FXSetParameters(fxMix, swap);
+
+
+ Dim swap As New BASS_BFX_MIX(BASSFXChan.BASS_BFX_CHAN2, BASSFXChan.BASS_BFX_CHAN1)
+ Dim channel As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim fxMix As Integer = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_MIX, 0)
+ Bass.BASS_FXSetParameters(fxMix, swap)
+
+ double linear = Math.Pow(10d, dB / 20.0);
+ double dB = 20.0 * Math.Log10(level / 1.0);
+ double linear = Math.Pow(10d, dB / 20.0);
+ double dB = 20.0 * Math.Log10(level / 1.0);
+
+ private int _fxEQ;
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT);
+ SetBFX_EQ(stream);
+ ...
+ // increase the treble by +6bB
+ UpdateFX(2, 6f);
+ ...
+
+ private void SetBFX_EQ(int channel)
+ {
+ // set peaking equalizer effect with no bands
+ _fxEQ = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_PEAKEQ, 0);
+
+ // setup the EQ bands
+ BASS_BFX_PEAKEQ eq = new BASS_BFX_PEAKEQ();
+ eq.fQ = 0f;
+ eq.fBandwidth = 2.5f;
+ eq.lChannel = BASSFXChan.BASS_BFX_CHANALL;
+
+ // create 1st band for bass
+ eq.lBand = 0;
+ eq.fCenter = 125f;
+ Bass.BASS_FXSetParameters(_fxEQ, eq);
+ UpdateFX(0, 0f);
+
+ // create 2nd band for mid
+ eq.lBand = 1;
+ eq.fCenter = 1000f;
+ Bass.BASS_FXSetParameters(_fxEQ, eq);
+ UpdateFX(1, 0f);
+
+ // create 3rd band for treble
+ eq.lBand = 2;
+ eq.fCenter = 8000f;
+ Bass.BASS_FXSetParameters(_fxEQ, eq);
+ UpdateFX(2, 0f);
+ }
+
+ private void UpdateFX(int band, float gain)
+ {
+ BASS_BFX_PEAKEQ eq = new BASS_BFX_PEAKEQ();
+ // get values of the selected band
+ eq.lBand = band;
+ Bass.BASS_FXGetParameters(_fxEQ, eq);
+ eq.fGain = gain;
+ Bass.BASS_FXSetParameters(_fxEQ, eq);
+ }
+
+
+ Private _fxEQ As Integer
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L.ToUInt32(), 0L.ToUInt32(), BASSFlag.BASS_SAMPLE_FLOAT)
+ SetBFX_EQ(stream)
+ ...
+ ' increase the treble by +6bB
+ UpdateFX(2, 6F)
+ ...
+
+ Private Sub SetBFX_EQ(channel As Integer)
+ ' set peaking equalizer effect with no bands
+ _fxEQ = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_BFX_PEAKEQ, 0)
+
+ ' setup the EQ bands
+ Dim eq As New BASS_BFX_PEAKEQ()
+ eq.fQ = 0F
+ eq.fBandwidth = 2.5F
+ eq.lChannel = BASSFXChan.BASS_BFX_CHANALL
+
+ ' create 1st band for bass
+ eq.lBand = 0
+ eq.fCenter = 125F
+ Bass.BASS_FXSetParameters(_fxEQ, eq)
+ UpdateFX(0, 0F)
+
+ ' create 2nd band for mid
+ eq.lBand = 1
+ eq.fCenter = 1000F
+ Bass.BASS_FXSetParameters(_fxEQ, eq)
+ UpdateFX(1, 0F)
+
+ ' create 3rd band for treble
+ eq.lBand = 2
+ eq.fCenter = 8000F
+ Bass.BASS_FXSetParameters(_fxEQ, eq)
+ UpdateFX(2, 0F)
+ End Sub
+
+ Private Sub UpdateFX(band As Integer, gain As Single)
+ Dim eq As New BASS_BFX_PEAKEQ()
+ ' get values of the selected band
+ eq.lBand = band
+ Bass.BASS_FXGetParameters(_fxEQ, eq)
+ eq.fGain = gain
+ Bass.BASS_FXSetParameters(_fxEQ, eq)
+ End Sub
+
+ double linear = Math.Pow(10d, dB / 20.0);
+ double dB = 20.0 * Math.Log10(level / 1.0);
+ double linear = Math.Pow(10d, dB / 20.0);
+ double dB = 20.0 * Math.Log10(level / 1.0);
+ double linear = Math.Pow(10d, dB / 20.0);
+ double dB = 20.0 * Math.Log10(level / 1.0);
+ double linear = Math.Pow(10d, dB / 20.0);
+ double dB = 20.0 * Math.Log10(level / 1.0);
+
+ int fx = Bass.BASS_ChannelSetFX(source, BASSFXType.BASS_FX_BFX_VOLUME_ENV, 0);
+ BASS_BFX_VOLUME_ENV ve = new BASS_BFX_VOLUME_ENV(
+ new BASS_BFX_ENV_NODE(0.0, 1f),
+ new BASS_BFX_ENV_NODE(5.0, 1f),
+ new BASS_BFX_ENV_NODE(7.0, 0.5f),
+ new BASS_BFX_ENV_NODE(12.0, 0.5f),
+ new BASS_BFX_ENV_NODE(14.0, 1f));
+ // which is the same as:
+ BASS_BFX_ENV_NODE[] en = new BASS_BFX_ENV_NODE[5];
+ en[0].pos = 0.0;
+ en[0].val = 1f;
+ en[1].pos = 5.0;
+ en[2].val = 1f;
+ en[3].pos = 7.0;
+ en[3].val = 0.5f;
+ en[4].pos = 12.0;
+ en[4].val = 0.5f;
+ en[5].pos = 14.0;
+ en[5].val = 1f;
+ ve = new BASS_BFX_VOLUME_ENV(en);
+
+ Bass.BASS_FXSetParameters(fx, ve);
+
+
+ Dim fx As Integer = Bass.BASS_ChannelSetFX(source, BASSFXType.BASS_FX_BFX_VOLUME_ENV, 0)
+ Dim ve As New BASS_BFX_VOLUME_ENV(
+ New BASS_BFX_ENV_NODE(0.0, 1F),
+ New BASS_BFX_ENV_NODE(5.0, 1F),
+ New BASS_BFX_ENV_NODE(7.0, 0.5F),
+ New BASS_BFX_ENV_NODE(12.0, 0.5F),
+ New BASS_BFX_ENV_NODE(14.0, 1F))
+ ' which is the same as:
+ Dim en As BASS_BFX_ENV_NODE() = New BASS_BFX_ENV_NODE(4) {}
+ en(0).pos = 0.0
+ en(0).val = 1F
+ en(1).pos = 5.0
+ en(2).val = 1F
+ en(3).pos = 7.0
+ en(3).val = 0.5F
+ en(4).pos = 12.0
+ en(4).val = 0.5F
+ en(5).pos = 14.0
+ en(5).val = 1F
+ ve = New BASS_BFX_VOLUME_ENV(en)
+
+ Bass.BASS_FXSetParameters(fx, ve)
+
+ Getting a volume envelope from a source channel:
+
+ BASS_BFX_VOLUME_ENV ve = new BASS_BFX_VOLUME_ENV();
+ if (Bass.BASS_FXGetParameters(fx, ve))
+ {
+ foreach (BASS_BFX_ENV_NODE node in ve.pNodes)
+ Console.WriteLine(node);
+ }
+
+
+ Dim ve As New BASS_BFX_VOLUME_ENV()
+ If Bass.BASS_FXGetParameters(fx, ve) Then
+ For Each node As BASS_BFX_ENV_NODE In ve.pNodes
+ Console.WriteLine(node)
+ Next
+ End If
+
+
+ BASS_CD_INFO info = new BASS_CD_INFO();
+ if ( BassCd.BASS_CD_GetInfo(0, info) )
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As New BASS_CD_INFO()
+ If BassCd.BASS_CD_GetInfo(0, info) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+ Check if the first drive can read CD-TEXT:
+
+ bool canReadCDText = false;
+ BASS_CD_INFO info = new BASS_CD_INFO();
+ if (BassCd.BASS_CD_GetInfo(0, info) && info.cdtext)
+ {
+ canReadCDText = true;
+ }
+
+
+ Dim canReadCDText As Boolean = False
+ Dim info As New BASS_CD_INFO()
+ If BassCd.BASS_CD_GetInfo(0, info) AndAlso info.cdtext Then
+ canReadCDText = True
+ End If
+
+
+ BASS_CD_INFO info = BassCd.BASS_CD_GetInfo(0);
+ if ( info != null )
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As BASS_CD_INFO = BassCd.BASS_CD_GetInfo(0)
+ If Not (info Is Nothing) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+
+ BASS_CD_INFO info = BassCd.BASS_CD_GetInfo(0);
+ if ( info != null )
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As BASS_CD_INFO = BassCd.BASS_CD_GetInfo(0)
+ If Not (info Is Nothing) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+
+ BassCd.BASS_CD_Door( 0, BASSCDDoor.BASS_CD_DOOR_OPEN );
+
+
+ BassCd.BASS_CD_Door( 0, BASSCDDoor.BASS_CD_DOOR_OPEN )
+
+
+ string cddb2 = BASS_CD_GetID(0, BASSCDId.BASS_CDID_CDDB2);
+
+
+ Dim cddb2 As String = BASS_CD_GetID(0, BASSCDId.BASS_CDID_CDDB2)
+
+
+ string[] cdText = BASS_CD_GetIDText(0);
+ if (cdText != null)
+ {
+ foreach (string tag in cdText)
+ Console.Writeln( tag );
+ }
+
+
+ Dim cdText As String() = BASS_CD_GetIDText(0)
+ If Not (cdText Is Nothing) Then
+ Dim tag As String
+ For Each tag In cdText
+ Console.Writeln(tag)
+ Next tag
+ End If
+
+
+ BASS_CD_TOC toc = new BASS_CD_TOC();
+ if (BassCd.BASS_CD_GetTOC(0, BASSCDTOCMode.BASS_CD_TOC_TIME, toc))
+ {
+ Console.WriteLine(toc.ToString());
+ // list the TOC_TRACKs
+ foreach (BASS_CD_TOC_TRACK track in toc.tracks)
+ {
+ Console.WriteLine(track.ToString());
+ }
+ }
+
+
+ Dim toc As New BASS_CD_TOC()
+ If BassCd.BASS_CD_GetTOC(0, BASSCDTOCMode.BASS_CD_TOC_TIME, toc) Then
+ Console.WriteLine(toc.ToString())
+ ' list the TOC_TRACKs
+ For Each track As BASS_CD_TOC_TRACK In toc.tracks
+ Console.WriteLine(track.ToString())
+ Next
+ End If
+
+
+ BASS_CD_TOC toc = BassCd.BASS_CD_GetTOC(0, BASSCDTOCMode.BASS_CD_TOC_TIME);
+ if (toc != null)
+ {
+ Console.WriteLine(toc.ToString());
+ // list the TOC_TRACKs
+ foreach (BASS_CD_TOC_TRACK track in toc.tracks)
+ {
+ Console.WriteLine(track.ToString());
+ }
+ }
+
+
+ Dim toc As BASS_CD_TOC = BassCd.BASS_CD_GetTOC(0, BASSCDTOCMode.BASS_CD_TOC_TIME)
+ If toc IsNot Nothing Then
+ Console.WriteLine(toc.ToString())
+ ' list the TOC_TRACKs
+ For Each track As BASS_CD_TOC_TRACK In toc.tracks
+ Console.WriteLine(track.ToString())
+ Next
+ End If
+
+
+ // get first track length
+ int len = BassCd.BASS_CD_GetTrackLength(0, 0);
+ // subtract the ending gap
+ len -= BassCd.BASS_CD_GetTrackPregap(0, 1);
+
+
+ ' get first track length
+ Dim len As Integer = BassCd.BASS_CD_GetTrackLength(0, 0)
+ ' subtract the ending gap
+ len -= BassCd.BASS_CD_GetTrackPregap(0, 1)
+
+
+ private SYNCPROC _mySync; // make it global, so that the GC can not collect it
+ ...
+ // create CD stream
+ int stream = BassCd.BASS_CD_StreamCreate(0, track, BASSFlag.BASS_DEFAULT | BASS_STREAM_AUTOFREE);
+ _mySync = new SYNCPROC(EndSync);
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero);
+ // start playing
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void EndSync(int handle, int channel, int data, IntPtr user)
+ {
+ // get current track
+ int track = Utils.LowWord32(BassCd.BASS_CD_StreamGetTrack(channel));
+ // jump to next track
+ BassCd.BASS_CD_StreamSetTrack(channel, track + 1);
+ }
+
+
+ Private _mySync As SYNCPROC ' make it global, so that the GC can not collect it
+ ...
+ ' create CD stream
+ Dim stream As Integer = BassCd.BASS_CD_StreamCreate(0, track, BASSFlag.BASS_DEFAULT Or BASS_STREAM_AUTOFREE)
+ _mySync = New SYNCPROC(AddressOf EndSync)
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_END Or BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero)
+ ' start playing
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub EndSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ ' get current track
+ Dim track As Integer = Utils.LowWord32(BassCd.BASS_CD_StreamGetTrack(channel))
+ ' jump to next track
+ BassCd.BASS_CD_StreamSetTrack(channel, track + 1)
+ End Sub
+
+
+ int track = BassCd.BASS_CD_StreamGetTrack(channel);
+ if (track != -1)
+ {
+ int drive = Utils.HighWord32(track);
+ track = Utils.LowWord32(track);
+ }
+
+
+ Dim track As Integer = BassCd.BASS_CD_StreamGetTrack(channel)
+ If track <> - 1 Then
+ Dim drive As Integer = Utils.HighWord32(track)
+ track = Utils.LowWord32(track)
+ End If
+
+
+ private SYNCPROC _mySync; // make it global, so that the GC can not collect it
+ ...
+ // create CD stream
+ int stream = BassCd.BASS_CD_StreamCreate(0, track, BASSFlag.BASS_DEFAULT | BASS_STREAM_AUTOFREE);
+ _mySync = new SYNCPROC(EndSync);
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero);
+ // start playing
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void EndSync(int handle, int channel, int data, IntPtr user)
+ {
+ // get current track
+ int track = Utils.LowWord32(BassCd.BASS_CD_StreamGetTrack(channel));
+ // jump to next track
+ BassCd.BASS_CD_StreamSetTrack(channel, track + 1);
+ }
+
+
+ Private _mySync As SYNCPROC ' make it global, so that the GC can not collect it
+ ...
+ ' create CD stream
+ Dim stream As Integer = BassCd.BASS_CD_StreamCreate(0, track, BASSFlag.BASS_DEFAULT Or BASS_STREAM_AUTOFREE)
+ _mySync = New SYNCPROC(AddressOf EndSync)
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_END Or BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero)
+ ' start playing
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub EndSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ ' get current track
+ Dim track As Integer = Utils.LowWord32(BassCd.BASS_CD_StreamGetTrack(channel))
+ ' jump to next track
+ BassCd.BASS_CD_StreamSetTrack(channel, track + 1)
+ End Sub
+
+
+ bool ok = BassCd.BASS_CD_Analog_Play(0, 3, 10 * 75);
+
+
+ Dim ok As Boolean = BassCd.BASS_CD_Analog_Play(0, 3, 10 * 75)
+
+
+ bool ok = BassCd.BASS_CD_Analog_Play(0, 3, 10.0);
+
+
+ Dim ok As Boolean = BassCd.BASS_CD_Analog_Play(0, 3, 10.0)
+
+
+ int drive = BassCd.BASS_CD_Analog_PlayFile("D:\\Track03.cda", 10 * 75);
+
+
+ Dim drive As Integer = BassCd.BASS_CD_Analog_PlayFile("D:\Track03.cda", 10 * 75)
+
+
+ int drive = BassCd.BASS_CD_Analog_PlayFile("D:\Track03.cda", 10.0);
+
+
+ Dim drive As Integer = BassCd.BASS_CD_Analog_PlayFile("D:\Track03.cda", 10.0)
+
+
+ // get the position
+ int pos = BassCd.BASS_CD_Analog_GetPosition(0);
+ int track = Utils.HighWord32(pos);
+ int frame = Utils.LowWord32(pos);
+ double sec = frame / 75.0;
+
+
+ ' get the position
+ Dim pos As Integer = BassCd.BASS_CD_Analog_GetPosition(0)
+ Dim track As Integer = Utils.HighWord32(pos)
+ Dim frame As Integer = Utils.LowWord32(pos)
+ Dim sec As Double = frame / 75.0
+
+
+ int track = 0;
+ double sec = BASS_CD_Analog_GetPosition(0, ref track);
+
+
+ Dim track As Integer = 0
+ Dim sec As Double = BASS_CD_Analog_GetPosition(0, track)
+
+
+ Bass.LoadMe();
+ BassCd.LoadMe();
+ ...
+ // when not used anymore...
+ BassCd.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassCd.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassCd.FreeMe();
+ Bass.FreeMe();
+
+
+ int count = Midi.MIDI_InGetNumDevs();
+ MIDI_INCAPS inCaps = new MIDI_INCAPS();
+ for (int i=0; i<count; i++)
+ {
+ Midi.MIDI_InGetDevCaps(i, inCaps);
+ Console.WriteLine( inCaps.name );
+ }
+
+
+ Dim count As Integer = Midi.MIDI_InGetNumDevs()
+ Dim inCaps As New MIDI_INCAPS()
+ Dim i As Integer
+ For i = 0 To count-1
+ Midi.MIDI_InGetDevCaps(i, inCaps)
+ Console.WriteLine(inCaps.name)
+ Next i
+
+
+ int count = Midi.MIDI_InGetNumDevs();
+ MIDI_INCAPS inCaps = new MIDI_INCAPS();
+ for (int i=0; i<count; i++)
+ {
+ Midi.MIDI_InGetDevCaps(i, inCaps);
+ Console.WriteLine( inCaps.name );
+ }
+
+
+ Dim count As Integer = Midi.MIDI_InGetNumDevs()
+ Dim inCaps As New MIDI_INCAPS()
+ Dim i As Integer
+ For i = 0 To count-1
+ Midi.MIDI_InGetDevCaps(i, inCaps)
+ Console.WriteLine(inCaps.name)
+ Next i
+
+
+ int count = Midi.MIDI_OutGetNumDevs();
+ MIDI_OUTCAPS outCaps = new MIDI_OUTCAPS();
+ for (int i=0; i<count; i++)
+ {
+ Midi.MIDI_OutGetDevCaps(i, outCaps);
+ if (outCaps.IsMidiPort)
+ Console.WriteLine( outCaps.name );
+ }
+
+
+ Dim count As Integer = Midi.MIDI_OutGetNumDevs()
+ Dim outCaps As New MIDI_OUTCAPS()
+ Dim i As Integer
+ For i = 0 To count-1
+ Midi.MIDI_OutGetDevCaps(i, outCaps)
+ If outCaps.IsMidiPort Then
+ Console.WriteLine(outCaps.name)
+ End If
+ Next i
+
+
+ int count = Midi.MIDI_OutGetNumDevs();
+ MIDI_OUTCAPS outCaps = new MIDI_OUTCAPS();
+ for (int i=0; i<count; i++)
+ {
+ Midi.MIDI_OutGetDevCaps(i, outCaps);
+ Console.WriteLine( outCaps.name );
+ }
+
+
+ Dim count As Integer = Midi.MIDI_OutGetNumDevs()
+ Dim outCaps As New MIDI_OUTCAPS()
+ Dim i As Integer
+ For i = 0 To count-1
+ Midi.MIDI_OutGetDevCaps(i, outCaps)
+ Console.WriteLine(outCaps.name)
+ Next i
+
+
+ private MIDIINPROC _midiProc;
+ private IntPtr _midiInHandle;
+ ...
+ // Open the Midi device #1
+ _midiProc = new MIDIINPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 1, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ ...
+ // when not needed anymore...stop the device
+ Midi.MIDI_InReset(_midiInHandle);
+ // and close the device
+ Midi.MIDI_InClose(_midiInHandle);
+ ...
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MIM_OPEN)
+ {
+ // nothing to do
+ }
+ else if (msg == MIDIMessage.MIM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the message...
+ int p1 = param1.ToInt32();
+ int p2 = param2.ToInt32();
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_MOREDATA)
+ {
+ // we are not fast enough in this callback to keep up...
+ // the input device is sending messages to fast
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_LONGDATA)
+ {
+ // process the message...
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_ERROR)
+ {
+ // process the invalid message...
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_LONGERROR)
+ {
+ // process the invalid message...
+ ...
+ }
+ }
+
+
+ Private _midiProc As MIDIINPROC
+ Private _midiInHandle As IntPtr
+ ...
+ ' Open the Midi device #1
+ _midiProc = New MIDIINPROC(AddressOf MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 1, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS)
+ If ret = MIDIError.MIDI_OK Then
+ ' Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle)
+ End If
+ ...
+ ' when not needed anymore...stop the device
+ Midi.MIDI_InReset(_midiInHandle)
+ ' and close the device
+ Midi.MIDI_InClose(_midiInHandle)
+ ...
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MIM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MIM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MIM_DATA Then
+ ' process the message...
+ Dim p1 As Integer = param1.ToInt32()
+ Dim p2 As Integer = param2.ToInt32()
+ ...
+ Else
+ If msg = MIDIMessage.MIM_MOREDATA Then
+ ' we are not fast enough in this callback to keep up...
+ ' the input device is sending messages to fast
+ ...
+ Else
+ If msg = MIDIMessage.MIM_LONGDATA Then
+ ' process the message...
+ ...
+ Else
+ If msg = MIDIMessage.MIM_ERROR Then
+ ' process the invalid message...
+ ...
+ Else
+ If msg = MIDIMessage.MIM_LONGERROR Then
+ ' process the invalid message...
+ ...
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End Sub
+
+
+ private MIDIOUTPROC _midiProc;
+ private IntPtr _midiOutHandle;
+ ...
+ // Open the Midi device #2
+ _midiProc = new MIDIOUTPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 2, _midiProc, 0);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // device opened and ready
+ }
+ ...
+ // When not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle);
+ // and close the device
+ Midi.MIDI_OutClose(_midiOutHandle);
+ ...
+ private void SendShortMessage(int message)
+ {
+ MIDI_OutShortMsg(_midiOutHandle, message);
+ }
+
+ private void SendSysExMessage(byte[] data)
+ {
+ MIDI_HEADER header = new MIDI_HEADER(data);
+ header.Prepare(false, _midiOutHandle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr);
+ }
+ }
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MOM_OPEN)
+ {
+ // nothing to do
+ }
+ else if (msg == MIDIMessage.MOM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if (msg == MIDIMessage.MOM_DONE)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ // process the header if needed
+ ...
+ // and finally unprepare the header
+ header.Unprepare(false, handle);
+ }
+ }
+
+
+ Private _midiProc As MIDIOUTPROC
+ Private _midiOutHandle As IntPtr
+ ...
+ ' Open the Midi device #2
+ _midiProc = New MIDIOUTPROC(MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_OutOpen(_midiOutHandle, 2, _midiProc, 0)
+ If ret = MIDIError.MIDI_OK Then
+ ' device opened and ready
+ End If
+ ...
+ ' when not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle)
+ ' and close the device
+ Midi.MIDI_OutClose(_midiOutHandle)
+ ...
+ Private Sub SendShortMessage(message As Integer)
+ MIDI_OutShortMsg(_midiOutHandle, message)
+ End Sub
+
+ Private Sub SendSysExMessage(data() As Byte)
+ Dim header As New MIDI_HEADER(data)
+ header.Prepare(False, _midiOutHandle)
+ ' If the header was perpared successfully.
+ If header.HeaderPtr <> IntPtr.Zero Then
+ ' send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr)
+ End If
+ End Sub
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MOM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MOM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MOM_DONE Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim header As New MIDI_HEADER(param1)
+ ' process the header if needed
+ ...
+ ' and finally unprepare the header
+ header.Unprepare(False, handle)
+ End If
+ End If
+ End If
+ End Sub
+
+
+ private MIDIOUTPROC _midiProc;
+ private IntPtr _midiOutHandle;
+ ...
+ // Open the Midi device #2
+ _midiProc = new MIDIOUTPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 2, _midiProc, 0);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // device opened and ready
+ }
+ ...
+ // When not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle);
+ // and close the device
+ Midi.MIDI_OutClose(_midiOutHandle);
+ ...
+ private void SendShortMessage(int message)
+ {
+ MIDI_OutShortMsg(_midiOutHandle, message);
+ }
+
+ private void SendSysExMessage(byte[] data)
+ {
+ MIDI_HEADER header = new MIDI_HEADER(data);
+ header.Prepare(false, _midiOutHandle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr);
+ }
+ }
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MOM_OPEN)
+ {
+ // nothing to do
+ }
+ else if (msg == MIDIMessage.MOM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if (msg == MIDIMessage.MOM_DONE)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ // process the header if needed
+ ...
+ // and finally unprepare the header
+ header.Unprepare(false, handle);
+ }
+ }
+
+
+ Private _midiProc As MIDIOUTPROC
+ Private _midiOutHandle As IntPtr
+ ...
+ ' Open the Midi device #2
+ _midiProc = New MIDIOUTPROC(MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_OutOpen(_midiOutHandle, 2, _midiProc, 0)
+ If ret = MIDIError.MIDI_OK Then
+ ' device opened and ready
+ End If
+ ...
+ ' when not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle)
+ ' and close the device
+ Midi.MIDI_OutClose(_midiOutHandle)
+ ...
+ Private Sub SendShortMessage(message As Integer)
+ MIDI_OutShortMsg(_midiOutHandle, message)
+ End Sub
+
+ Private Sub SendSysExMessage(data() As Byte)
+ Dim header As New MIDI_HEADER(data)
+ header.Prepare(False, _midiOutHandle)
+ ' If the header was perpared successfully.
+ If header.HeaderPtr <> IntPtr.Zero Then
+ ' send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr)
+ End If
+ End Sub
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MOM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MOM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MOM_DONE Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim header As New MIDI_HEADER(param1)
+ ' process the header if needed
+ ...
+ ' and finally unprepare the header
+ header.Unprepare(False, handle)
+ End If
+ End If
+ End If
+ End Sub
+
+
+ private MIDIOUTPROC _midiProc;
+ private IntPtr _midiOutHandle;
+ ...
+ // Open the Midi device #2
+ _midiProc = new MIDIOUTPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 2, _midiProc, 0);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // device opened and ready
+ }
+ ...
+ // When not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle);
+ // and close the device
+ Midi.MIDI_OutClose(_midiOutHandle);
+ ...
+ private void SendShortMessage(int message)
+ {
+ MIDI_OutShortMsg(_midiOutHandle, message);
+ }
+
+ private void SendSysExMessage(byte[] data)
+ {
+ MIDI_HEADER header = new MIDI_HEADER(data);
+ header.Prepare(false, _midiOutHandle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr);
+ }
+ }
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MOM_OPEN)
+ {
+ // nothing to do
+ }
+ else if (msg == MIDIMessage.MOM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if (msg == MIDIMessage.MOM_DONE)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ // process the header if needed
+ ...
+ // and finally unprepare the header
+ header.Unprepare(false, handle);
+ }
+ }
+
+
+ Private _midiProc As MIDIOUTPROC
+ Private _midiOutHandle As IntPtr
+ ...
+ ' Open the Midi device #2
+ _midiProc = New MIDIOUTPROC(MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_OutOpen(_midiOutHandle, 2, _midiProc, 0)
+ If ret = MIDIError.MIDI_OK Then
+ ' device opened and ready
+ End If
+ ...
+ ' when not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle)
+ ' and close the device
+ Midi.MIDI_OutClose(_midiOutHandle)
+ ...
+ Private Sub SendShortMessage(message As Integer)
+ MIDI_OutShortMsg(_midiOutHandle, message)
+ End Sub
+
+ Private Sub SendSysExMessage(data() As Byte)
+ Dim header As New MIDI_HEADER(data)
+ header.Prepare(False, _midiOutHandle)
+ ' If the header was perpared successfully.
+ If header.HeaderPtr <> IntPtr.Zero Then
+ ' send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(_midiOutHandle, header.HeaderPtr)
+ End If
+ End Sub
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MOM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MOM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MOM_DONE Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim header As New MIDI_HEADER(param1)
+ ' process the header if needed
+ ...
+ ' and finally unprepare the header
+ header.Unprepare(False, handle)
+ End If
+ End If
+ End If
+ End Sub
+
+
+ private MIDIINPROC _midiInProc;
+ private IntPtr _midiInHandle;
+ ...
+ private void StartRecording()
+ {
+ _midiInProc = new MIDIINPROC(MyMidiInProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 1, _midiInProc, 0, MIDIFlags.MIDI_IO_STATUS);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024);
+ AddSysExBuffer(_midiInHandle, 1024);
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ }
+
+ // prepare receiving system-exclusive messages
+ private void AddSysExBuffer(IntPtr handle, int size)
+ {
+ // prepare a empty midi header
+ MIDI_HEADER header = new MIDI_HEADER(size);
+ header.Prepare(true, handle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr);
+ }
+ }
+
+ private void MyMidiInProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the short message...
+ int p1 = param1.ToInt32();
+ int p2 = param2.ToInt32();
+ ...
+ Console.WriteLine("Msg={0}\r\nParam1={1}\r\nParam2={2}" , msg, p1, p2);
+ }
+ else if (msg == MIDIMessage.MIM_LONGDATA)
+ {
+ // process the system-exclusive message...
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ if (header.IsDone)
+ {
+ byte[] data = header.Data;
+ ...
+ Console.WriteLine(header.ToString());
+ }
+ // must unprepare the processed header
+ header.Unprepare(true, handle);
+ // add a new buffer
+ // we must constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ ...
+ }
+
+
+ Private _midiInProc As MIDIINPROC
+ Private _midiInHandle As IntPtr
+ ...
+ Private Sub StartRecording()
+ _midiInProc = New MIDIINPROC(AddressOf MyMidiInProc)
+ Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 1, _midiInProc, 0, MIDIFlags.MIDI_IO_STATUS)
+ If ret = MIDIError.MIDI_OK Then
+ ' supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024)
+ AddSysExBuffer(_midiInHandle, 1024)
+ ret = Midi.MIDI_InStart(_midiInHandle)
+ End If
+ End Sub
+
+ ' prepare receiving system-exclusive messages
+ Private Sub AddSysExBuffer(handle As IntPtr, size As Integer)
+ ' prepare a empty midi header
+ Dim header As New MIDI_HEADER(size)
+ header.Prepare(True, handle)
+ ' If the header was perpared successfully.
+ If header.HeaderPtr <> IntPtr.Zero Then
+ ' Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr)
+ End If
+ End Sub
+
+ Private Sub MyMidiInProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MIM_DATA Then
+ ' process the short message...
+ Dim p1 As Integer = param1.ToInt32()
+ Dim p2 As Integer = param2.ToInt32()
+ ...
+ Console.WriteLine("Msg={0}" + ControlChars.Cr + ControlChars.Lf + "Param1={1}" + ControlChars.Cr + ControlChars.Lf + "Param2={2}", msg, p1, p2)
+ Else
+ If msg = MIDIMessage.MIM_LONGDATA Then
+ ' process the system-exclusive message...
+ Dim header As New MIDI_HEADER(param1)
+ If header.IsDone Then
+ Dim data As Byte() = header.Data
+ ...
+ Console.WriteLine(header.ToString())
+ End If
+ ' must unprepare the processed header
+ header.Unprepare(True, handle)
+ ' add a new buffer
+ ' we must constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024)
+ End If
+ ...
+ End If
+ End Sub
+
+
+ private MIDIINPROC _midiInProc;
+ private IntPtr _midiInHandle;
+ ...
+ private void StartRecording()
+ {
+ _midiInProc = new MIDIINPROC(MyMidiInProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 1, _midiInProc, 0, MIDIFlags.MIDI_IO_STATUS);
+
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024);
+ AddSysExBuffer(_midiInHandle, 1024);
+
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ }
+
+ // prepare receiving system-exclusive messages
+ public void AddSysExBuffer(IntPtr handle, int size)
+ {
+ // prepare a empty midi header
+ MIDI_HEADER header = new MIDI_HEADER(size);
+ header.Prepare(true, handle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr);
+ }
+ }
+
+ private void MyMidiInProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the short message...
+ // on Win32 system the param1 and param2 values might be converted like this:
+ int p1 = param1.ToInt32();
+ int p2 = param2.ToInt32();
+ Console.WriteLine( "Msg={0}\r\nParam1={1}\r\nParam2={2}" , msg, p1, p2);
+ }
+ else if (msg == MIDIMessage.MIM_LONGDATA)
+ {
+ // process the system-exclusive message...
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ if (header.IsDone)
+ {
+ byte[] data = header.Data;
+ ...
+ Console.WriteLine( header.ToString() );
+ }
+ header.Unprepare(true, handle);
+
+ // add a new buffer
+ // since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ ...
+ }
+
+
+ private MIDIINPROC _midiInProc;
+ private IntPtr _midiInHandle;
+ ...
+ private void StartRecording()
+ {
+ _midiInProc = new MIDIINPROC(MyMidiInProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 1, _midiInProc, 0, MIDIFlags.MIDI_IO_STATUS);
+
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024);
+ AddSysExBuffer(_midiInHandle, 1024);
+
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ }
+
+ // prepare receiving system-exclusive messages
+ public void AddSysExBuffer(IntPtr handle, int size)
+ {
+ // prepare a empty midi header
+ MIDI_HEADER header = new MIDI_HEADER(size);
+ header.Prepare(true, handle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr);
+ }
+ }
+
+ private void MyMidiInProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the short message...
+ // on Win32 system the param1 and param2 values might be converted like this:
+ int p1 = param1.ToInt32();
+ int p2 = param2.ToInt32();
+ Console.WriteLine( "Msg={0}\r\nParam1={1}\r\nParam2={2}" , msg, p1, p2);
+ }
+ else if (msg == MIDIMessage.MIM_LONGDATA)
+ {
+ // process the system-exclusive message...
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ if (header.IsDone)
+ {
+ byte[] data = header.Data;
+ ...
+ Console.WriteLine( header.ToString() );
+ }
+ header.Unprepare(true, handle);
+
+ // add a new buffer
+ // since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ ...
+ }
+
+
+ // the following code will return 440Hz for the C
+ int freq = Utils.NoteToFrequency(69);
+
+
+ ' the following code will return 440Hz for the C
+ Dim freq As Integer = Utils.NoteToFrequency(69)
+
+
+ private MIDIINPROC _midiProc;
+ private int _midiInHandle;
+ ...
+ // Open the Midi device #2
+ _midiProc = new MIDIINPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 2, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024);
+ AddSysExBuffer(_midiInHandle, 1024);
+ // Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ ...
+ // when not needed anymore...stop the device
+ Midi.MIDI_InReset(_midiInHandle);
+ // and close the device
+ Midi.MIDI_InClose(_midiInHandle);
+ ...
+ // prepare receiving system-exclusive messages
+ private void AddSysExBuffer(IntPtr handle, int size)
+ {
+ // prepare a empty midi header
+ MIDI_HEADER header = new MIDI_HEADER(size);
+ header.Prepare(true, handle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr);
+ }
+ }
+ ...
+ private MidiShortMessage _shortMsg = null;
+ private MidiSysExMessage _sysExMsg = null;
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if(msg == MIDIMessage.MIM_OPEN)
+ {
+ // nothing to do
+ }
+ else if(msg == MIDIMessage.MIM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if(msg == MIDIMessage.MIM_DATA)
+ {
+ // process the message...
+ _shortMsg = new MidiShortMessage(param1, param2, _shortMsg);
+ Console.WriteLine(_shortMsg.ToString());
+ }
+ else if(msg == MIDIMessage.MIM_MOREDATA)
+ {
+ // we are not fast enough in this callback to keep up...
+ // the input device is sending messages to fast
+ ...
+ }
+ else if(msg == MIDIMessage.MIM_LONGDATA)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ _sysExMsg = new MidiSysExMessage(true, handle, param1, _sysExMsg);
+ if (_sysExMsg.IsDone)
+ {
+ Console.WriteLine(_sysExMsg.ToString());
+ }
+ // add a new buffer
+ // since we must constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ else if(msg == MIDIMessage.MIM_ERROR)
+ {
+ // process the invalid message...
+ ...
+ }
+ else if(msg == MIDIMessage.MIM_LONGERROR)
+ {
+ // process the invalid message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ header.Unprepare(true, handle);
+ // add a new buffer
+ // since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ }
+
+
+ Private _midiInProc As MIDIINPROC
+ Private _midiInHandle As IntPtr
+ ...
+ ' Open the Midi device #2
+ _midiProc = New MIDIINPROC(AddressOf MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 2, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS)
+ If ret = MIDIError.MIDI_OK Then
+ ' supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024)
+ AddSysExBuffer(_midiInHandle, 1024)
+ ' Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle)
+ End If
+ ...
+ ' when not needed anymore...stop the device
+ Midi.MIDI_InReset(_midiInHandle)
+ ' and close the device
+ Midi.MIDI_InClose(_midiInHandle)
+ ...
+ Private _shortMsg As MidiShortMessage = Nothing
+ Private _sysExMsg As MidiSysExMessage = Nothing
+ ...
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MIM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MIM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MIM_DATA Then
+ ' process the message...
+ _shortMsg = New MidiShortMessage(param1, param2, _shortMsg)
+ Console.WriteLine(_shortMsg.ToString())
+ Else
+ If msg = MIDIMessage.MIM_MOREDATA Then
+ ' we are not fast enough in this callback to keep up...
+ ' the input device is sending messages to fast
+ ...
+ Else
+ If msg = MIDIMessage.MIM_LONGDATA Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ _sysExMsg = New MidiSysExMessage(True, handle, param1, _sysExMsg)
+ If _sysExMsg.IsDone Then
+ Console.WriteLine(_sysExMsg.ToString())
+ End If
+ ' add a new buffer
+ ' since we must constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024)
+ Else
+ If msg = MIDIMessage.MIM_ERROR Then
+ ' process the invalid message...
+ ...
+ Else
+ If msg = MIDIMessage.MIM_LONGERROR Then
+ ' process the invalid message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim header As New MIDI_HEADER(param1)
+ header.Unprepare(True, handle)
+ ' add a new buffer
+ ' since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024)
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End Sub
+
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the message...
+ MidiShortMessage shortMsg = new MidiShortMessage(param1, param2);
+ if (shortMsg.MessageType == MIDIMessageType.Channel)
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Chan={C}, Status={S}, {D}"));
+ else if (shortMsg.MessageType == MIDIMessageType.SystemCommon)
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Status={S}, {D}"));
+ else
+ Console.WriteLine(shortMsg.ToString("G"));
+ ...
+ }
+ ...
+ }
+
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ If msg = MIDIMessage.MIM_DATA Then
+ ' process the message...
+ Dim shortMsg As New MidiShortMessage(param1, param2)
+ If shortMsg.MessageType = MIDIMessageType.Channel Then
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Chan={C}, Status={S}, {D}"))
+ Else
+ If shortMsg.MessageType = MIDIMessageType.SystemCommon Then
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Status={S}, {D}"))
+ Else
+ Console.WriteLine(shortMsg.ToString("G"))
+ End If
+ End If
+ ...
+ End If
+ ...
+ End Sub
+
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the message...
+ MidiShortMessage shortMsg = new MidiShortMessage(param1, param2);
+ if (shortMsg.MessageType == MIDIMessageType.Channel)
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Chan={C}, Status={S}, {D}"));
+ else if (shortMsg.MessageType == MIDIMessageType.SystemCommon)
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Status={S}, {D}"));
+ else
+ Console.WriteLine(shortMsg.ToString("G"));
+ ...
+ }
+ ...
+ }
+
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ If msg = MIDIMessage.MIM_DATA Then
+ ' process the message...
+ Dim shortMsg As New MidiShortMessage(param1, param2)
+ If shortMsg.MessageType = MIDIMessageType.Channel Then
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Chan={C}, Status={S}, {D}"))
+ Else
+ If shortMsg.MessageType = MIDIMessageType.SystemCommon Then
+ Console.WriteLine(shortMsg.ToString("Time={T}: Msg={M}, Status={S}, {D}"))
+ Else
+ Console.WriteLine(shortMsg.ToString("G"))
+ End If
+ End If
+ ...
+ End If
+ ...
+ End Sub
+
+
+ // construct a message
+ MidiShortMessage msg = new MidiShortMessage(MIDIStatus.NoteOn, channel, note, velocity, 0, 0);
+ // send the message
+ int result = MIDI_OutShortMsg(handle, msg.Message);
+
+
+ ' construct a message
+ Dim msg As New MidiShortMessage(MIDIStatus.NoteOn, channel, note, velocity, 0, 0)
+ ' send the message
+ Dim result As Integer = MIDI_OutShortMsg(handle, msg.Message)
+
+
+ private MIDIOUTPROC _midiProc;
+ private IntPtr _midiOutHandle;
+ ...
+ // Open the Midi device #0
+ _midiProc = new MIDIOUTPROC(MyMidiOutProc);
+ MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 0, _midiProc, 0);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // output ready
+ }
+ ...
+ private void SendSysExBuffer(IntPtr handle, byte[] data)
+ {
+ MidiSysExMessage msg = new MidiSysExMessage(false, handle);
+ msg.CreateBuffer(data);
+ if (msg.Prepare())
+ {
+ // if the message was perpared successfully
+ // send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(handle, msg.MessageAsIntPtr);
+ }
+ }
+
+ public void MyMidiOutProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MOM_DONE)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MidiSysExMessage sysexMsg = new MidiSysExMessage(false, handle, param1);
+ // the internal header is already unprepared here
+ // so you can still use the data...
+ Console.WriteLine( sysexMsg.ToString() );
+ }
+ ...
+ }
+
+
+ Private _midiProc As MIDIOUTPROC
+ Private _midiOutHandle As IntPtr
+ ...
+ ' Open the Midi device #0
+ _midiProc = New MIDIOUTPROC(AddressOf MyMidiOutProc)
+ Dim ret As MIDIError = Midi.MIDI_OutOpen(_midiOutHandle, 0, _midiProc, 0)
+ If ret = MIDIError.MIDI_OK Then
+ ' output ready
+ End If
+ ...
+ Private Sub SendSysExBuffer(handle As IntPtr, data() As Byte)
+ Dim msg As New MidiSysExMessage(False, handle)
+ msg.CreateBuffer(data)
+ If msg.Prepare() Then
+ ' if the message was perpared successfully
+ ' send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(handle, msg.MessageAsIntPtr)
+ End If
+ End Sub
+
+ Public Sub MyMidiOutProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MOM_DONE Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim sysexMsg As New MidiSysExMessage(False, handle, param1)
+ ' the internal header is already unprepared here
+ ' so you can still use the data...
+ Console.WriteLine(sysexMsg.ToString())
+ End If
+ End Sub
+
+ Receiving system-exclusive messages at an input device:
+
+ private MIDIINPROC _midiProc;
+ private IntPtr _midiInHandle;
+ ...
+ // Open the Midi device #0
+ _midiProc = new MIDIINPROC(MyMidiInProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 0, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // already supply the device with 2 buffers (each 1K)
+ AddSysExBuffer(_midiInHandle, 1024);
+ AddSysExBuffer(_midiInHandle, 1024);
+ // Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ ...
+ // prepare receiving system-exclusive messages
+ private void AddSysExBuffer(IntPtr handle, int size)
+ {
+ MidiSysExMessage msg = new MidiSysExMessage(true, handle);
+ msg.CreateBuffer(size);
+ if (msg.Prepare())
+ {
+ // Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, msg.MessageAsIntPtr);
+ }
+ }
+
+ MidiSysExMessage _sysexMsg = null;
+ public void MyMidiInProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ if (msg == MIDIMessage.MIM_LONGDATA || msg == MIDIMessage.MIM_LONGERROR)
+ {
+ // process the sysex message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ _sysexMsg = new MidiSysExMessage(true, handle, param1, _sysexMsg);
+ if (_sysexMsg.IsDone)
+ {
+ // use it...
+ Console.WriteLine( sysexMsg.ToString() );
+ }
+ ...
+ // add a new buffer
+ // since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ ...
+ }
+
+
+ Private _midiProc As MIDIINPROC
+ Private _midiInHandle As IntPtr
+ ...
+ ' Open the Midi device #0
+ _midiProc = New MIDIINPROC(AddressOf MyMidiInProc)
+ Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 0, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS)
+ If ret = MIDIError.MIDI_OK Then
+ ' already supply the device with 2 buffers (each 1K)
+ AddSysExBuffer(_midiInHandle, 1024)
+ AddSysExBuffer(_midiInHandle, 1024)
+ ' Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle)
+ End If
+ ...
+ ' prepare receiving system-exclusive messages
+ Private Sub AddSysExBuffer(handle As IntPtr, size As Integer)
+ Dim msg As New MidiSysExMessage(True, handle)
+ msg.CreateBuffer(size)
+ If msg.Prepare() Then
+ ' Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, msg.MessageAsIntPtr)
+ End If
+ End Sub
+
+ ' prepare sending system-exclusive messages
+ Dim _sysexMsg As MidiSysExMessage = Nothing
+ Public Sub MyMidiInProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ If msg = MIDIMessage.MIM_LONGDATA OrElse msg = MIDIMessage.MIM_LONGERROR Then
+ ' process the sysex message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ _sysexMsg = New MidiSysExMessage(True, handle, param1, _sysexMsg)
+ If _sysexMsg.IsDone Then
+ ' use it...
+ Console.WriteLine(sysexMsg.ToString())
+ End If
+ ...
+ ' add a new buffer
+ ' since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024)
+ End If
+ ...
+ End Sub
+
+
+ private MIDIOUTPROC _midiOutProc;
+ private IntPtr _midiOutHandle;
+ ...
+ _midiOutProc = new MIDIOUTPROC(MyMidiOutProc);
+ Midi.MIDI_OutOpen(ref _midiOutHandle, 0, _midiOutProc, 0);
+ ...
+ // create a new system-exclusive message
+ MidiSysExMessage sysex = new MidiSysExMessage(false, _midiOutHandle);
+ // message will be 8 byte (incl. SoX and EoX)
+ sysex.CreateBuffer(8);
+ // write start-of-system-exclusive
+ sysex.MessageWriteSoX();
+ int offset = 1;
+ // write 6 more bytes...
+ sysex.MessageWrite8(ref offset, 65);
+ sysex.MessageWrite16(ref offset, 1023);
+ sysex.MessageWrite16(ref offset, 13);
+ sysex.MessageWrite8(ref offset, 1);
+ // write end-of-system-exclusive
+ sysex.MessageWriteEoX();
+ ...
+
+
+ Private _midiOutProc As MIDIOUTPROC
+ Private _midiOutHandle As IntPtr
+ ...
+ _midiOutProc = New MIDIOUTPROC(AddressOf MyMidiOutProc)
+ Midi.MIDI_OutOpen(_midiOutHandle, 0, _midiOutProc, 0)
+ ...
+ ' create a new system-exclusive message
+ Dim sysex As New MidiSysExMessage(False, _midiOutHandle)
+ ' message will be 8 byte (incl. SoX and EoX)
+ sysex.CreateBuffer(8)
+ ' write start-of-system-exclusive
+ sysex.MessageWriteSoX()
+ Dim offset As Integer = 1
+ ' write 6 more bytes...
+ sysex.MessageWrite8(offset, 65)
+ sysex.MessageWrite16(offset, 1023)
+ sysex.MessageWrite16(offset, 13)
+ sysex.MessageWrite8(offset, 1)
+ ' write end-of-system-exclusive
+ sysex.MessageWriteEoX()
+
+
+ using radio42.Multimedia.Midi;
+ ...
+ private MidiInputDevice _inDevice;
+ ...
+ // open and start a certain Midi input device
+ private void OpenAndStartDevice(int device)
+ {
+ _inDevice = new MidiInputDevice(device);
+ _inDevice.AutoPairController = true;
+ _inDevice.MessageFilter = MIDIMessageType.SystemRealtime | MIDIMessageType.SystemExclusive;
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if (_inDevice.Open())
+ {
+ if (!_inDevice.Start())
+ MessageBox.Show(this, "Midi device could not be started! Error: " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ else
+ MessageBox.Show(this, "Midi device could not be opened! Error: " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+
+ // stop and close the Midi input device
+ private void StopAndCloseDevice()
+ {
+ if (_inDevice != null && _inDevice.IsStarted)
+ {
+ _inDevice.Stop();
+ _inDevice.Close();
+ _inDevice.MessageReceived -= new MidiMessageEventHandler(InDevice_MessageReceived);
+ }
+ }
+
+ private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.IsShortMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString());
+ }
+ else if (e.IsSysExMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString());
+ }
+ else if (e.EventType == MidiMessageEventType.Opened)
+ {
+ Console.WriteLine("Midi device {0} opened.", e.DeviceID);
+ }
+ else if (e.EventType == MidiMessageEventType.Closed)
+ {
+ Console.WriteLine("Midi device {0} closed.", e.DeviceID);
+ }
+ else if (e.EventType == MidiMessageEventType.Started)
+ {
+ Console.WriteLine("Midi device {0} started.", e.DeviceID);
+ }
+ else if (e.EventType == MidiMessageEventType.Stopped)
+ {
+ Console.WriteLine("Midi device {0} stopped.", e.DeviceID);
+ }
+ }
+
+
+ Imports radio42.Multimedia.Midi
+ ...
+ Private _inDevice As MidiInputDevice
+ ...
+ ' open and start a certain Midi input device
+ Private Sub OpenAndStartDevice(device As Integer)
+ _inDevice = New MidiInputDevice(device)
+ _inDevice.AutoPairController = True
+ _inDevice.MessageFilter = MIDIMessageType.SystemRealtime Or MIDIMessageType.SystemExclusive
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ If Not _inDevice.Start() Then
+ MessageBox.Show(Me, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ Else
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ End Sub
+
+ ' stop and close the Midi input device
+ Private Sub StopAndCloseDevice()
+ If Not (_inDevice Is Nothing) AndAlso _inDevice.IsStarted Then
+ _inDevice.Stop()
+ _inDevice.Close()
+ _inDevice.MessageReceived -= New MidiMessageEventHandler(InDevice_MessageReceived)
+ End If
+ End Sub
+
+ Private Sub InDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.IsShortMessage Then
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString())
+ Else
+ If e.IsSysExMessage Then
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString())
+ Else
+ If e.EventType = MidiMessageEventType.Opened Then
+ Console.WriteLine("Midi device {0} opened.", e.DeviceID)
+ Else
+ If e.EventType = MidiMessageEventType.Closed Then
+ Console.WriteLine("Midi device {0} closed.", e.DeviceID)
+ Else
+ If e.EventType = MidiMessageEventType.Started Then
+ Console.WriteLine("Midi device {0} started.", e.DeviceID)
+ Else
+ If e.EventType = MidiMessageEventType.Stopped Then
+ Console.WriteLine("Midi device {0} stopped.", e.DeviceID)
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End Sub
+
+
+ int[] inPorts = MidiInputDevice.GetMidiPorts();
+ foreach (int port in inPorts)
+ {
+ string name = MidiInputDevice.GetDeviceDescription(port);
+ Console.WriteLine("{0}={1}", port, name);
+ }
+
+
+ Dim inPorts As Integer() = MidiInputDevice.GetMidiPorts()
+ Dim port As Integer
+ For Each port In inPorts
+ Dim name As String = MidiInputDevice.GetDeviceDescription(port)
+ Console.WriteLine("{0}={1}", port, name)
+ Next port
+
+
+ private MidiInputDevice _inDevice;
+ ...
+ _inDevice = new MidiInputDevice(0);
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if (_inDevice.Open())
+ {
+ if (!_inDevice.Start())
+ MessageBox.Show(this, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ else
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ ...
+ // when done
+ if (_inDevice.IsStarted)
+ _inDevice.Stop();
+ if (_inDevice.IsOpened)
+ _inDevice.Close();
+ ...
+ private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.IsShortMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString());
+ }
+ else if (e.IsSysExMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString());
+ }
+ }
+
+
+ Private _inDevice As MidiInputDevice
+ ...
+ _inDevice = New MidiInputDevice(0)
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ If Not _inDevice.Start() Then
+ MessageBox.Show(Me, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ Else
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ ...
+ ' when done
+ If _inDevice.IsStarted Then
+ _inDevice.Stop()
+ End If
+ If _inDevice.IsOpened Then
+ _inDevice.Close()
+ End If
+ ...
+ Private Sub InDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.IsShortMessage Then
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString())
+ Else
+ If e.IsSysExMessage Then
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString())
+ End If
+ End If
+ End Sub
+
+
+ private MidiInputDevice _inDevice;
+ ...
+ _inDevice = new MidiInputDevice(0);
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if (_inDevice.Open())
+ {
+ if (!_inDevice.Start())
+ MessageBox.Show(this, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ else
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ ...
+ // when done
+ if (_inDevice.IsStarted)
+ _inDevice.Stop();
+ if (_inDevice.IsOpened)
+ _inDevice.Close();
+ ...
+ private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.IsShortMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString());
+ }
+ else if (e.IsSysExMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString());
+ }
+ }
+
+
+ Private _inDevice As MidiInputDevice
+ ...
+ _inDevice = New MidiInputDevice(0)
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ If Not _inDevice.Start() Then
+ MessageBox.Show(Me, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ Else
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ ...
+ ' when done
+ If _inDevice.IsStarted Then
+ _inDevice.Stop()
+ End If
+ If _inDevice.IsOpened Then
+ _inDevice.Close()
+ End If
+ ...
+ Private Sub InDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.IsShortMessage Then
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString())
+ Else
+ If e.IsSysExMessage Then
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString())
+ End If
+ End If
+ End Sub
+
+
+ private MidiInputDevice _inDevice;
+ ...
+ _inDevice = new MidiInputDevice(0);
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if (_inDevice.Open())
+ {
+ if (!_inDevice.Start())
+ MessageBox.Show(this, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ else
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ ...
+ // when done
+ if (_inDevice.IsStarted)
+ _inDevice.Stop();
+ if (_inDevice.IsOpened)
+ _inDevice.Close();
+ ...
+ private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.IsShortMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString());
+ }
+ else if (e.IsSysExMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString());
+ }
+ }
+
+
+ Private _inDevice As MidiInputDevice
+ ...
+ _inDevice = New MidiInputDevice(0)
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ If Not _inDevice.Start() Then
+ MessageBox.Show(Me, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ Else
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ ...
+ ' when done
+ If _inDevice.IsStarted Then
+ _inDevice.Stop()
+ End If
+ If _inDevice.IsOpened Then
+ _inDevice.Close()
+ End If
+ ...
+ Private Sub InDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.IsShortMessage Then
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString())
+ Else
+ If e.IsSysExMessage Then
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString())
+ End If
+ End If
+ End Sub
+
+
+ private MidiInputDevice _inDevice;
+ ...
+ _inDevice = new MidiInputDevice(0);
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if (_inDevice.Open())
+ {
+ if (!_inDevice.Start())
+ MessageBox.Show(this, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ else
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error");
+ ...
+ // when done
+ if (_inDevice.IsStarted)
+ _inDevice.Stop();
+ if (_inDevice.IsOpened)
+ _inDevice.Close();
+ ...
+ private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.IsShortMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString());
+ }
+ else if (e.IsSysExMessage)
+ {
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString());
+ }
+ }
+
+
+ Private _inDevice As MidiInputDevice
+ ...
+ _inDevice = New MidiInputDevice(0)
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ If Not _inDevice.Start() Then
+ MessageBox.Show(Me, "Midi device could not be started! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ Else
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _inDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ ...
+ ' when done
+ If _inDevice.IsStarted Then
+ _inDevice.Stop()
+ End If
+ If _inDevice.IsOpened Then
+ _inDevice.Close()
+ End If
+ ...
+ Private Sub InDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.IsShortMessage Then
+ Console.WriteLine("{0} : {1}", e.ShortMessage.ID, e.ShortMessage.ToString())
+ Else
+ If e.IsSysExMessage Then
+ Console.WriteLine("{0} : {1}", e.SysExMessage.ID, e.SysExMessage.ToString())
+ End If
+ End If
+ End Sub
+
+
+ --MSB-LSB--SWAP-> (definition)
+ | 0, 32, 255
+ | 1, 33, 255
+ | 2, 34, 255
+ | ... ... ...
+ | 99, 98, 254
+ | 101, 100, 254
+ v
+ (Pairs)
+
+
+
+ byte[,] ColtrollerPairMatrix = new byte[34,3]
+ {
+ { 0, 32, 255},
+ { 1, 33, 255},
+ { 2, 34, 255},
+ { 3, 35, 255},
+ { 4, 36, 255},
+ { 5, 37, 255},
+ { 6, 38, 255},
+ { 7, 39, 255},
+ { 8, 40, 255},
+ { 9, 41, 255},
+ { 10, 42, 255},
+ { 11, 43, 255},
+ { 12, 44, 255},
+ { 13, 45, 255},
+ { 14, 46, 255},
+ { 15, 47, 255},
+ { 16, 48, 255},
+ { 17, 49, 255},
+ { 18, 50, 255},
+ { 19, 51, 255},
+ { 20, 52, 255},
+ { 21, 53, 255},
+ { 22, 54, 255},
+ { 23, 55, 255},
+ { 24, 56, 255},
+ { 25, 57, 255},
+ { 26, 58, 255},
+ { 27, 59, 255},
+ { 28, 60, 255},
+ { 29, 61, 255},
+ { 30, 62, 255},
+ { 31, 63, 255},
+ { 99, 98, 255},
+ {101, 100, 255}
+ };
+
+
+ private MidiInputDevice _inDevice = null;
+ ...
+ _inDevice = new MidiInputDevice(0);
+ _inDevice.AutoPairController = true;
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if ( _inDevice.Open() )
+ _inDevice.Start();
+ ...
+ private void InDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.IsShortMessage)
+ {
+ if (e.ShortMessage.IsSetAsContinuousController)
+ {
+ Console.WriteLine("Continuous Controller {0}: Value={1}",
+ e.ShortMessage.Controller,
+ e.ShortMessage.ControllerValue);
+ Console.WriteLine("MSB ControllerType={0}, LSB ControllerType={1}",
+ e.ShortMessage.ThisIsMSB ? e.ShortMessage.ControllerType :
+ e.ShortMessage.PreviousShortMessage.ControllerType,
+ e.ShortMessage.PreviousIsMSB ? e.ShortMessage.ControllerType :
+ e.ShortMessage.PreviousShortMessage.ControllerType);
+ }
+ else
+ Console.WriteLine(e.ShortMessage.ToString());
+ }
+ ...
+ }
+
+
+ Private _inDevice As MidiInputDevice = Nothing
+ ...
+ _inDevice = New MidiInputDevice(0)
+ _inDevice.AutoPairController = True
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ _inDevice.Start()
+ End If
+ ...
+ Private Sub InDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.IsShortMessage Then
+ If e.ShortMessage.IsSetAsContinuousController Then
+ Console.WriteLine("Continuous Controller {0}: Value={1}",
+ e.ShortMessage.Controller,
+ e.ShortMessage.ControllerValue)
+ If e.ShortMessage.ThisIsMSB Then
+ Console.WriteLine("MSB ControllerType={0}", e.ShortMessage.ControllerType)
+ Else
+ Console.WriteLine("MSB ControllerType={0}", e.ShortMessage.PreviousShortMessage.ControllerType)
+ End If
+ If e.ShortMessage.PreviousIsMSB Then
+ Console.WriteLine("LSB ControllerType={0}", e.ShortMessage.ControllerType)
+ Else
+ Console.WriteLine("LSB ControllerType={0}", e.ShortMessage.PreviousShortMessage.ControllerType)
+ End If
+ Else
+ Console.WriteLine(e.ShortMessage.ToString())
+ End If
+ End If
+ End Sub
+
+
+ private MidiInputDevice _inDevice = null;
+ ...
+ _inDevice = new MidiInputDevice(0);
+ _inDevice.AutoPairController = true;
+ _inDevice.MessageFilter = MIDIMessageType.SystemRealtime | MIDIMessageType.SystemExclusive;
+ _inDevice.MessageReceived += new MidiMessageEventHandler(InDevice_MessageReceived);
+ if ( _inDevice.Open() )
+ _inDevice.Start();
+ ...
+
+
+ Private _inDevice As MidiInputDevice = Nothing
+ ...
+ _inDevice = New MidiInputDevice(0)
+ _inDevice.AutoPairController = True
+ _inDevice.MessageFilter = MIDIMessageType.SystemRealtime Or MIDIMessageType.SystemExclusive
+ AddHandler _inDevice.MessageReceived, AddressOf InDevice_MessageReceived
+ If _inDevice.Open() Then
+ _inDevice.Start()
+ End If
+
+
+ using radio42.Multimedia.Midi;
+ ...
+ private MidiOutputDevice _outDevice;
+ ...
+ // open a certain Midi output device
+ private void OpenDevice(int device)
+ {
+ _outDevice = new MidiOutputDevice(device);
+ if (!_outDevice.Open())
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ }
+
+ // close the Midi output device
+ private void StopAndCloseDevice()
+ {
+ if (_outDevice != null && _outDevice.IsOpened)
+ {
+ _outDevice.Close();
+ }
+ }
+ ...
+ // create and send a new short message to the output device
+ MidiShortMessage msg = new MidiShortMessage(MIDIStatus.NoteOn, 0, 64, 65, 0);
+ if ( _outDevice.Send(msg) )
+ Console.WriteLine("Error sending short message!");
+ ...
+ // create a new system-exclusive message for the output device
+ MidiSysExMessage sysex = new MidiSysExMessage(false, _outDevice.Device);
+ sysex.CreateBuffer( new byte[7] {0xF0, 0x43, 0x75, 0x73, 0x12, 0x00, 0xF7} );
+ // send it
+ if ( _outDevice.Send(sysex) )
+ Console.WriteLine("Error sending system-exclusive message!");
+ ...
+
+
+ Imports radio42.Multimedia.Midi
+ ...
+ Private _outDevice As MidiOutputDevice
+ ...
+ ' open a certain Midi output device
+ Private Sub OpenDevice(device As Integer)
+ _outDevice = New MidiOutputDevice(device)
+ If Not _outDevice.Open() Then
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ End Sub
+
+ ' close the Midi output device
+ Private Sub StopAndCloseDevice()
+ If Not (_outDevice Is Nothing) AndAlso _outDevice.IsOpened Then
+ _outDevice.Close()
+ End If
+ End Sub
+ ...
+ ' create and send a new short message to the output device
+ Dim msg As New MidiShortMessage(MIDIStatus.NoteOn, 0, 64, 65, 0)
+ If _outDevice.Send(msg) Then
+ Console.WriteLine("Error sending short message!")
+ End If
+ ...
+ ' create a new system-exclusive message for the output device
+ Dim sysex As New MidiSysExMessage(False, _outDevice.Device)
+ sysex.CreateBuffer(New Byte(7) {&HF0, &H43, &H75, &H73, &H12, &H0, &HF7})
+ ' send it
+ If _outDevice.Send(sysex) Then
+ Console.WriteLine("Error sending system-exclusive message!")
+ End If
+
+
+ int[] outPorts = MidiOutputDevice.GetMidiPorts();
+ foreach (int port in outPorts)
+ {
+ string name = MidiOutputDevice.GetDeviceDescription(port);
+ Console.WriteLine("{0}={1}", port, name);
+ }
+
+
+ Dim outPorts As Integer() = MidiOutputDevice.GetMidiPorts()
+ Dim port As Integer
+ For Each port In outPorts
+ Dim name As String = MidiOutputDevice.GetDeviceDescription(port)
+ Console.WriteLine("{0}={1}", port, name)
+ Next port
+
+
+ private MidiOutputDevice _outDevice;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ _outDevice.MessageReceived += new MidiMessageEventHandler(OutDevice_MessageReceived);
+ if (!_outDevice.Open())
+ {
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ ...
+ // when done
+ if (_outDevice.IsOpened)
+ _outDevice.Close();
+ ...
+ private void OutDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.EventType == MidiMessageEventType.Opened)
+ {
+ Console.WriteLine("Midi device {0} opened.", e.DeviceID);
+ }
+ else if (e.EventType == MidiMessageEventType.Closed)
+ {
+ Console.WriteLine("Midi device {0} closed.", e.DeviceID);
+ }
+ }
+
+
+ Private _outDevice As MidiOutputDevice
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ AddHandler _outDevice.MessageReceived, AddressOf OutDevice_MessageReceived
+ If Not _outDevice.Open() Then
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ ...
+ ' when done
+ If _outDevice.IsOpened Then
+ _outDevice.Close()
+ End If
+ ...
+ Private Sub OutDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.EventType = MidiMessageEventType.Opened Then
+ Console.WriteLine("Midi device {0} opened.", e.DeviceID)
+ Else
+ If e.EventType = MidiMessageEventType.Closed Then
+ Console.WriteLine("Midi device {0} closed.", e.DeviceID)
+ End If
+ End If
+ End Sub
+
+
+ private MidiOutputDevice _outDevice;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ _outDevice.MessageReceived += new MidiMessageEventHandler(OutDevice_MessageReceived);
+ if (!_outDevice.Open())
+ {
+ MessageBox.Show(this, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error");
+ }
+ ...
+ // when done
+ if (_outDevice.IsOpened)
+ _outDevice.Close();
+ ...
+ private void OutDevice_MessageReceived(object sender, MidiMessageEventArgs e)
+ {
+ if (e.EventType == MidiMessageEventType.Opened)
+ {
+ Console.WriteLine("Midi device {0} opened.", e.DeviceID);
+ }
+ else if (e.EventType == MidiMessageEventType.Closed)
+ {
+ Console.WriteLine("Midi device {0} closed.", e.DeviceID);
+ }
+ }
+
+
+ Private _outDevice As MidiOutputDevice
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ AddHandler _outDevice.MessageReceived, AddressOf OutDevice_MessageReceived
+ If Not _outDevice.Open() Then
+ MessageBox.Show(Me, "Midi device could not be opened! Error " + _outDevice.LastErrorCode.ToString(), "Midi Error")
+ End If
+ ...
+ ' when done
+ If _outDevice.IsOpened Then
+ _outDevice.Close()
+ End If
+ ...
+ Private Sub OutDevice_MessageReceived(sender As Object, e As MidiMessageEventArgs)
+ If e.EventType = MidiMessageEventType.Opened Then
+ Console.WriteLine("Midi device {0} opened.", e.DeviceID)
+ Else
+ If e.EventType = MidiMessageEventType.Closed Then
+ Console.WriteLine("Midi device {0} closed.", e.DeviceID)
+ End If
+ End If
+ End Sub
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ if (!_outDevice.Open())
+ Console.WriteLine( "Could not open Midi device!" );
+
+ // create and send a new short message to the output device
+ MidiShortMessage msg = new MidiShortMessage(MIDIStatus.NoteOn, 0, 64, 65, 0);
+ if (_outDevice.Send(msg))
+ Console.WriteLine("Error sending short message!");
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ If Not _outDevice.Open() Then
+ Console.WriteLine("Could not open Midi device!")
+ End If
+
+ ' create and send a new short message to the output device
+ Dim msg As New MidiShortMessage(MIDIStatus.NoteOn, 0, 64, 65, 0)
+ If _outDevice.Send(msg) Then
+ Console.WriteLine("Error sending short message!")
+ End If
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ if ( !_outDevice.Open() )
+ Console.WriteLine( "Could not open Midi device!" );
+
+ // send a new short message to the output device
+ if ( _outDevice.Send(0x414090) )
+ Console.WriteLine("Error sending short message!");
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ If Not _outDevice.Open() Then
+ Console.WriteLine("Could not open Midi device!")
+ End If
+
+ ' send a new short message to the output device
+ If _outDevice.Send(&H414090) Then
+ Console.WriteLine("Error sending short message!")
+ End If
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ if ( !_outDevice.Open() )
+ Console.WriteLine("Could not open Midi device!");
+
+ // send a new short message to the output device
+ if ( _outDevice.Send((byte)MIDIStatus.NoteOn, 1, 64, 65) )
+ Console.WriteLine("Error sending short message!");
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ If Not _outDevice.Open() Then
+ Console.WriteLine("Could not open Midi device!")
+ End If
+
+ ' send a new short message to the output device
+ If _outDevice.Send(CByte(MIDIStatus.NoteOn), 1, 64, 65) Then
+ Console.WriteLine("Error sending short message!")
+ End If
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ if ( !_outDevice.Open() )
+ Console.WriteLine("Could not open Midi device!");
+
+ // send a new short message to the output device
+ if ( _outDevice.Send(0x90, 40, 41) )
+ Console.WriteLine("Error sending short message!");
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ If Not _outDevice.Open() Then
+ Console.WriteLine("Could not open Midi device!")
+ End If
+
+ ' send a new short message to the output device
+ If _outDevice.Send(&H90, 40, 41) Then
+ Console.WriteLine("Error sending short message!")
+ End If
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ if ( !_outDevice.Open() )
+ Console.WriteLine("Could not open Midi device!");
+
+ // create a new system-exclusive message for the output device
+ MidiSysExMessage sysex = new MidiSysExMessage(false, _outDevice.Device);
+ sysex.CreateBuffer(new byte[7] {0xF0, 0x43, 0x75, 0x73, 0x12, 0x00, 0xF7});
+ // send it
+ if ( _outDevice.Send(sysex) )
+ Console.WriteLine("Error sending system-exclusive message!");
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ If Not _outDevice.Open() Then
+ Console.WriteLine("Could not open Midi device!")
+ End If
+
+ ' create a new system-exclusive message for the output device
+ Dim sysex As New MidiSysExMessage(False, _outDevice.Device)
+ sysex.CreateBuffer(New Byte(7) {&HF0, &H43, &H75, &H73, &H12, &H0, &HF7})
+ ' send it
+ If _outDevice.Send(sysex) Then
+ Console.WriteLine("Error sending system-exclusive message!")
+ End If
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = new MidiOutputDevice(0);
+ if ( !_outDevice.Open() )
+ Console.WriteLine( "Could not open Midi device!" );
+
+ // send a new system-exclusive message to the output device
+ if (_outDevice.Send(new byte[7] {0xF0, 0x43, 0x75, 0x73, 0x12, 0x00, 0xF7}))
+ Console.WriteLine("Error sending system-exclusive message!");
+
+
+ private MidiOutputDevice _outDevice = null;
+ ...
+ _outDevice = New MidiOutputDevice(0)
+ If Not _outDevice.Open() Then
+ Console.WriteLine("Could not open Midi device!")
+ End If
+
+ ' send a new system-exclusive message to the output device
+ If _outDevice.Send(New Byte(7) {&HF0, &H43, &H75, &H73, &H12, &H0, &HF7}) Then
+ Console.WriteLine("Error sending system-exclusive message!")
+ End If
+
+
+ private MIDIOUTPROC _midiProc;
+ private IntPtr _midiOutHandle;
+ ...
+ // Open the Midi device #2
+ _midiProc = new MIDIOUTPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_OutOpen(ref _midiOutHandle, 2, _midiProc, 0);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // output ready
+ }
+ ...
+ // when not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle);
+ // and close the device
+ Midi.MIDI_OutClose(_midiOutHandle);
+ ...
+
+ private void Send(int handle, int message)
+ {
+ int result = MIDI_OutShortMsg(handle, message);
+ }
+
+ private void SendSysExBuffer(IntPtr handle, byte[] data)
+ {
+ MIDI_HEADER header = new MIDI_HEADER(data);
+ header.Prepare(false, handle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(handle, header.HeaderPtr);
+ }
+ }
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if(msg == MIDIMessage.MOM_OPEN)
+ {
+ // nothing to do
+ }
+ else if (msg == MIDIMessage.MOM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if (msg == MIDIMessage.MOM_DONE)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MIDI_HEADER header = new MIDI_HEADER(param1);
+ byte[] data = header.Data;
+ header.Unprepare(false, handle);
+ ...
+ // or
+ MidiSysExMessage sysExMsg = new MidiSysExMessage(false, handle, param1);
+ ...
+ }
+ }
+
+
+ Private _midiProc As MIDIOUTPROC
+ Private _midiOutHandle As IntPtr
+ ...
+ ' Open the Midi device #2
+ _midiProc = New MIDIOUTPROC(AddressOf MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_OutOpen(_midiOutHandle, 2, _midiProc, 0)
+ If ret = MIDIError.MIDI_OK Then
+ ' output ready
+ End If
+ ...
+ ' when not needed anymore...stop the device
+ Midi.MIDI_OutReset(_midiOutHandle)
+ ' and close the device
+ Midi.MIDI_OutClose(_midiOutHandle)
+ ...
+
+ Private Sub Send(handle As Integer, message As Integer)
+ Dim result As Integer = MIDI_OutShortMsg(handle, message)
+ End Sub
+
+ Private Sub SendSysExBuffer(handle As IntPtr, data() As Byte)
+ Dim header As New MIDI_HEADER(data)
+ header.Prepare(False, handle)
+ ' If the header was perpared successfully.
+ If header.HeaderPtr <> IntPtr.Zero Then
+ ' send a system-exclusive message to the output device
+ Midi.MIDI_OutLongMsg(handle, header.HeaderPtr)
+ End If
+ End Sub
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MOM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MOM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MOM_DONE Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim header As New MIDI_HEADER(param1)
+ Dim data As Byte() = header.Data
+ header.Unprepare(False, handle)
+ ...
+ ' or
+ Dim sysExMsg As New MidiSysExMessage(False, handle, param1)
+ ...
+ End If
+ End If
+ End If
+ End Sub
+
+
+ private MIDIINPROC _midiProc;
+ private IntPtr _midiInHandle;
+ ...
+ // Open the Midi device #2
+ _midiProc = new MIDIINPROC(MyMidiProc);
+ MIDIError ret = Midi.MIDI_InOpen(ref _midiInHandle, 2, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS);
+ if (ret == MIDIError.MIDI_OK)
+ {
+ // supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024);
+ AddSysExBuffer(_midiInHandle, 1024);
+ // Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle);
+ }
+ ...
+ // Stop the device
+ Midi.MIDI_InReset(_midiInHandle);
+ // when not needed anymore...close the device
+ Midi.MIDI_InClose(_midiInHandle);
+ ...
+ // prepare receiving system-exclusive messages
+ private void AddSysExBuffer(IntPtr handle, int size)
+ {
+ // prepare a empty midi header
+ MIDI_HEADER header = new MIDI_HEADER(size);
+ header.Prepare(true, handle);
+ // If the header was perpared successfully.
+ if (header.HeaderPtr != IntPtr.Zero)
+ {
+ // Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr);
+ }
+ }
+
+ public void MyMidiProc(IntPtr handle, MIDIMessage msg, IntPtr instance, IntPtr param1, IntPtr param2)
+ {
+ // handle all Midi messages here
+ if (msg == MIDIMessage.MIM_OPEN)
+ {
+ // nothing to do
+ }
+ else if (msg == MIDIMessage.MIM_CLOSE)
+ {
+ // handle is from now on invalid
+ }
+ else if (msg == MIDIMessage.MIM_DATA)
+ {
+ // process the message...
+ int p1 = param1.ToInt32();
+ int p2 = param2.ToInt32();
+ ...
+ // or
+ MidiShortMessage shortMsg = new MidiShortMessage(param1, param2);
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_MOREDATA)
+ {
+ // we are not fast enough in this callback to keep up
+ // the input device is sending messages to fast
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_LONGDATA)
+ {
+ // process the message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MIDI_HEADER header = MIDI_HEADER(param1);
+ byte[] data = header.Data;
+ ...
+ header.Unprepare(true, handle);
+ // add a new buffer
+ // since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ else if (msg == MIDIMessage.MIM_ERROR)
+ {
+ // process the invalid message...
+ MidiShortMessage errorMsg = new MidiShortMessage(param1, param2);
+ ...
+ }
+ else if (msg == MIDIMessage.MIM_LONGERROR)
+ {
+ // process the invalid message...
+ // param1 will contain the pointer to the MIDI_HEADER
+ MidiSysExMessage errorSysExMsg = new MidiSysExMessage(true, handle, param1);
+ ...
+ // add a new buffer
+ // since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024);
+ }
+ }
+
+
+ Private _midiProc As MIDIINPROC
+ Private _midiInHandle As IntPtr
+ ...
+ ' Open the Midi device #2
+ _midiProc = New MIDIINPROC(AddressOf MyMidiProc)
+ Dim ret As MIDIError = Midi.MIDI_InOpen(_midiInHandle, 2, _midiProc, IntPtr.Zero, MIDIFlags.MIDI_IO_STATUS)
+ If ret = MIDIError.MIDI_OK Then
+ ' supply the device with 2 buffers
+ AddSysExBuffer(_midiInHandle, 1024)
+ AddSysExBuffer(_midiInHandle, 1024)
+ ' Start the device
+ ret = Midi.MIDI_InStart(_midiInHandle)
+ End If
+ ...
+ ' Stop the device
+ Midi.MIDI_InReset(_midiInHandle)
+ ' when not needed anymore...close the device
+ Midi.MIDI_InClose(_midiInHandle)
+ ...
+ ' prepare receiving system-exclusive messages
+ Private Sub AddSysExBuffer(handle As IntPtr, size As Integer)
+ ' prepare a empty midi header
+ Dim header As New MIDI_HEADER(size)
+ header.Prepare(True, handle)
+ ' If the header was perpared successfully.
+ If header.HeaderPtr <> IntPtr.Zero Then
+ ' Add the buffer to the InputDevice.
+ Midi.MIDI_InAddBuffer(handle, header.HeaderPtr)
+ End If
+ End Sub
+
+ Public Sub MyMidiProc(handle As IntPtr, msg As MIDIMessage, instance As IntPtr, param1 As IntPtr, param2 As IntPtr)
+ ' handle all Midi messages here
+ If msg = MIDIMessage.MIM_OPEN Then
+ ' nothing to do
+ Else
+ If msg = MIDIMessage.MIM_CLOSE Then
+ ' handle is from now on invalid
+ Else
+ If msg = MIDIMessage.MIM_DATA Then
+ ' process the message...
+ Dim p1 As Integer = param1.ToInt32()
+ Dim p2 As Integer = param2.ToInt32()
+ ...
+ ' or
+ Dim shortMsg As New MidiShortMessage(param1, param2)
+ ...
+ Else
+ If msg = MIDIMessage.MIM_MOREDATA Then
+ ' we are not fast enough in this callback to keep up
+ ' the input device is sending messages to fast
+ ...
+ Else
+ If msg = MIDIMessage.MIM_LONGDATA Then
+ ' process the message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim header As MIDI_HEADER = MIDI_HEADER(param1)
+ Dim data As Byte() = header.Data
+ ...
+ header.Unprepare(True, handle)
+ ' add a new buffer
+ ' since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024)
+ Else
+ If msg = MIDIMessage.MIM_ERROR Then
+ ' process the invalid message...
+ Dim errorMsg As New MidiShortMessage(param1, param2)
+ ...
+ Else
+ If msg = MIDIMessage.MIM_LONGERROR Then
+ ' process the invalid message...
+ ' param1 will contain the pointer to the MIDI_HEADER
+ Dim errorSysExMsg As New MidiSysExMessage(True, handle, param1)
+ ...
+ ' add a new buffer
+ ' since we should constantly provide new buffers until we finished recording
+ AddSysExBuffer(handle, 1024)
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End If
+ End Sub
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE);
+ WaveWriter WW = new WaveWriter("test.wav", stream, true);
+ short[] data = new short[32768];
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ int length = Bass.BASS_ChannelGetData(stream, data, 32768);
+ if (length > 0)
+ WW.Write(data, length);
+ }
+ // finilize the wave file!
+ WW.Close();
+ Bass.BASS_StreamFree(stream);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE)
+ Dim WW As New WaveWriter("test.wav", stream, True)
+ Dim data(32768 - 1) As Short
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ Dim length As Integer = Bass.BASS_ChannelGetData(stream, data, 32768)
+ If length > 0 Then
+ WW.Write(data, length)
+ End If
+ End While
+ ' finilize the wave file!
+ WW.Close()
+ Bass.BASS_StreamFree(stream)
+
+ Using a WaveWriter in a RECORDPROC to record 24-bit at 44.1kHz, stereo:
+
+ private WaveWriter _waveWriter = null; // make it global, so that the GC can not remove it
+ private RECORDPROC _myRecProc;
+ private int _recHandle = 0;
+ ...
+ // start recording
+ _myRecProc = new RECORDPROC(MyRecording);
+ _recHandle = Bass.BASS_RecordStart(44100, 2,
+ BASSFlag.BASS_RECORD_PAUSE | BASSFlag.BASS_SAMPLE_FLOAT, _myRecProc, IntPtr.Zero);
+ // create a WaveWriter using the _recHandle to set the freq. and channels, but write the wave at 24-bit
+ _waveWriter = new WaveWriter( "test.wav", _recHandle, 24, true);
+ Bass.BASS_ChannelPlay(_recHandle, false);
+ ...
+ // when finished recording call this!
+ if (_waveWriter != null)
+ {
+ // finilize the wave file!
+ _waveWriter.Close();
+ }
+ ...
+ // the recording callback
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ // we will get float sample data here
+ // so make sure the _waveWriter.OrigResolution property is set to 32
+ // this was automatically done, since we started recording with BASSFlag.BASS_SAMPLE_FLOAT
+ _waveWriter.Write( buffer, length );
+ return true; // always continue recording
+ }
+
+
+ Private _waveWriter As WaveWriter = Nothing ' make it global, so that the GC can not remove it
+ Private _myRecProc As RECORDPROC
+ Private _recHandle As Integer = 0
+ ...
+ ' start recording
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ _recHandle = Bass.BASS_RecordStart(44100, 2,
+ BASSFlag.BASS_RECORD_PAUSE Or BASSFlag.BASS_SAMPLE_FLOAT, _myRecProc, IntPtr.Zero)
+ ' create a WaveWriter using the _recHandle to set the freq. and channels, but write the wave at 24-bit
+ _waveWriter = New WaveWriter("test.wav", _recHandle, 24, True)
+ Bass.BASS_ChannelPlay(_recHandle, False)
+ ...
+ ' when finished recording call this!
+ If Not (_waveWriter Is Nothing) Then
+ ' finilize the wave file!
+ _waveWriter.Close()
+ End If
+ ...
+ ' the recording callback
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ ' we will get float sample data here
+ ' so make sure the _waveWriter.OrigResolution property is set to 32
+ ' this was automatically done, since we started recording with BASSFlag.BASS_SAMPLE_FLOAT
+ _waveWriter.Write(buffer, length)
+ Return True ' always continue recording
+ End Function
+
+
+ private WaveWriter _waveWriter = null; // make it global, so that the GC can not remove it
+ private RECORDPROC _myRecProc;
+ private int _recHandle = 0;
+ ...
+ // start recording
+ _myRecProc = new RECORDPROC(MyRecording);
+ _recHandle = Bass.BASS_RecordStart(44100, 2,
+ BASSFlag.BASS_RECORD_PAUSE | BASSFlag.BASS_SAMPLE_FLOAT, _myRecProc, IntPtr.Zero);
+ // create a WaveWriter using the _recHandle to set the freq. and channels, but write the wave at 24-bit
+ _waveWriter = new WaveWriter( "test.wav", _recHandle, 24, true);
+ Bass.BASS_ChannelPlay(_recHandle, false);
+ ...
+ // when finished recording call this!
+ if (_waveWriter != null)
+ {
+ // finilize the wave file!
+ _waveWriter.Close();
+ }
+ ...
+ // the recording callback
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ // we will get float sample data here
+ // so make sure the _waveWriter.OrigResolution property is set to 32
+ // this was automatically done, since we started recording with BASSFlag.BASS_SAMPLE_FLOAT
+ _waveWriter.Write( buffer, length );
+ return true; // always continue recording
+ }
+
+
+ Private _waveWriter As WaveWriter = Nothing ' make it global, so that the GC can not remove it
+ Private _myRecProc As RECORDPROC
+ Private _recHandle As Integer = 0
+ ...
+ ' start recording
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ _recHandle = Bass.BASS_RecordStart(44100, 2,
+ BASSFlag.BASS_RECORD_PAUSE Or BASSFlag.BASS_SAMPLE_FLOAT, _myRecProc, IntPtr.Zero)
+ ' create a WaveWriter using the _recHandle to set the freq. and channels, but write the wave at 24-bit
+ _waveWriter = New WaveWriter("test.wav", _recHandle, 24, True)
+ Bass.BASS_ChannelPlay(_recHandle, False)
+ ...
+ ' when finished recording call this!
+ If Not (_waveWriter Is Nothing) Then
+ ' finilize the wave file!
+ _waveWriter.Close()
+ End If
+ ...
+ ' the recording callback
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ ' we will get float sample data here
+ ' so make sure the _waveWriter.OrigResolution property is set to 32
+ ' this was automatically done, since we started recording with BASSFlag.BASS_SAMPLE_FLOAT
+ _waveWriter.Write(buffer, length)
+ Return True ' always continue recording
+ End Function
+
+
+ // create a stream with the float option
+ int stream = Bass.BASS_StreamCreateFile("test.ogg", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ // set the target bit resolution to 32
+ WaveWriter WW = new WaveWriter("test.wav", stream, 32, true);
+ float[] data = new float[32768];
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ // get the sample data as float values as well
+ int length = Bass.BASS_ChannelGetData(stream, data, 32768);
+ // and write the data to the wave file
+ if (length > 0)
+ WW.Write(data, length);
+ }
+ // finilize the wave file!
+ WW.Close();
+ Bass.BASS_StreamFree(stream);
+
+
+ ' create a stream with the float option
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.ogg", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ ' set the target bit resolution to 32
+ Dim WW As New WaveWriter("test.wav", stream, 32, True)
+ Dim data(32768 - 1) As Single
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ ' get the sample data as float values as well
+ Dim length As Integer = Bass.BASS_ChannelGetData(stream, data, 32768)
+ ' and write the data to the wave file
+ If length > 0 Then
+ WW.Write(data, length)
+ End If
+ End While
+ ' finilize the wave file!
+ WW.Close()
+ Bass.BASS_StreamFree(stream)
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE);
+ WaveWriter WW = new WaveWriter("test.wav", stream, true);
+ short[] data = new short[32768];
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ int length = Bass.BASS_ChannelGetData(stream, data, 32768);
+ if (length > 0)
+ WW.Write(data, length);
+ }
+ // finilize the wave file!
+ WW.Close();
+ Bass.BASS_StreamFree(stream);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE)
+ Dim WW As New WaveWriter("test.wav", stream, True)
+ Dim data(32768 - 1) As Short
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ Dim length As Integer = Bass.BASS_ChannelGetData(stream, data, 32768)
+ If length > 0 Then
+ WW.Write(data, length)
+ End If
+ End While
+ ' finilize the wave file!
+ WW.Close()
+ Bass.BASS_StreamFree(stream)
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_8BITS);
+ WaveWriter WW = new WaveWriter("test.wav", stream, true);
+ byte[] data = new byte[32768];
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ int length = Bass.BASS_ChannelGetData(stream, data, 32768);
+ if (length > 0)
+ WW.Write(data, length);
+ }
+ // finilize the wave file!
+ WW.Close();
+ Bass.BASS_StreamFree(stream);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_8BITS)
+ Dim WW As New WaveWriter("test.wav", stream, True)
+ Dim data(32768 - 1) As Byte
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ Dim length As Integer = Bass.BASS_ChannelGetData(stream, data, 32768)
+ If length > 0 Then
+ WW.Write(data, length)
+ End If
+ End While
+ ' finilize the wave file!
+ WW.Close()
+ Bass.BASS_StreamFree(stream)
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_8BITS);
+ WaveWriter WW = new WaveWriter("test.wav", stream, true);
+ byte[] data = new byte[32768];
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ int length = Bass.BASS_ChannelGetData(stream, data, 32768);
+ if (length > 0)
+ WW.WriteNoConvert(data, length);
+ }
+ // finilize the wave file!
+ WW.Close();
+ Bass.BASS_StreamFree(stream);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_8BITS)
+ Dim WW As New WaveWriter("test.wav", stream, True)
+ Dim data(32768 - 1) As Byte
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ Dim length As Integer = Bass.BASS_ChannelGetData(stream, data, 32768)
+ If length > 0 Then
+ WW.WriteNoConvert(data, length)
+ End If
+ End While
+ ' finilize the wave file!
+ WW.Close()
+ Bass.BASS_StreamFree(stream)
+
+
+ private WaveForm WF = null;
+ private RECORDPROC _myRecProc; // make it global, so that the GC can not remove it
+ private int _recHandle = 0;
+ ...
+ _myRecProc = new RECORDPROC(MyRecording);
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero);
+ // create a live recording WaveForm
+ WF = new WaveForm();
+ WF.FrameResolution = 0.01f; // 10ms are nice
+ // start a live recording waveform with 10sec. init size and 5sec. next size
+ WF.RenderStartRecording(_recHandle, 10, 5);
+ // really start recording
+ Bass.BASS_ChannelPlay(_recHandle, false);
+ ...
+ // stops recording
+ Bass.BASS_ChannelStop(_recHandle);
+ // stop the live recording waveform
+ if (WF != null)
+ {
+ WF.RenderStopRecording();
+ DrawWave();
+ }
+ ...
+ // the recording callback in which we will render the WaveForm
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // get and draw our live recording waveform
+ WF.RenderRecording(buffer, length);
+ DrawWave();
+ }
+ return true; // always continue recording
+ }
+ ...
+ // draws a rendered WaveForm to a PictureBox
+ private void DrawWave()
+ {
+ if (WF != null)
+ this.pictureBoxLiveWave.BackgroundImage = WF.CreateBitmap(this.pictureBoxLiveWave.Width,
+ this.pictureBoxLiveWave.Height,
+ -1, -1, false);
+ else
+ this.pictureBoxLiveWave.BackgroundImage = null;
+ }
+
+
+ Private WF As WaveForm = Nothing
+ Private _myRecProc As RECORDPROC ' make it global, so that the GC can not remove it
+ Private _recHandle As Integer = 0
+ ...
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero)
+ ' create a live recording WaveForm
+ WF = New WaveForm()
+ WF.FrameResolution = 0.01F ' 10ms are nice
+ ' start a live recording waveform with 10sec. init size and 5sec. next size
+ WF.RenderStartRecording(_recHandle, 10, 5)
+ ' really start recording
+ Bass.BASS_ChannelPlay(_recHandle, False)
+ ...
+ ' stops recording
+ Bass.BASS_ChannelStop(_recHandle)
+ ' stop the live recording waveform
+ If Not (WF Is Nothing) Then
+ WF.RenderStopRecording()
+ DrawWave()
+ End If
+ ...
+ ' the recording callback in which we will render the WaveForm
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ If length > 0 AndAlso buffer <> IntPtr.Zero Then
+ ' get and draw our live recording waveform
+ WF.RenderRecording(buffer, length)
+ DrawWave()
+ End If
+ Return True ' always continue recording
+ End Function
+
+ ' draws a rendered WaveForm to a PictureBox
+ Private Sub DrawWave()
+ If Not (WF Is Nothing) Then
+ Me.pictureBoxLiveWave.BackgroundImage = WF.CreateBitmap(Me.pictureBoxLiveWave.Width,
+ Me.pictureBoxLiveWave.Height,
+ -1, -1, False)
+ Else
+ Me.pictureBoxLiveWave.BackgroundImage = Nothing
+ End If
+ End Sub
+
+
+ private WaveForm WF = null;
+ private RECORDPROC _myRecProc; // make it global, so that the GC can not remove it
+ private int _recHandle = 0;
+ ...
+ _myRecProc = new RECORDPROC(MyRecording);
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero);
+ // create a live recording WaveForm
+ WF = new WaveForm();
+ WF.FrameResolution = 0.01f; // 10ms are nice
+ // start a live recording waveform with 10sec. init size and 5sec. next size
+ WF.RenderStartRecording(_recHandle, 10, 5);
+ // really start recording
+ Bass.BASS_ChannelPlay(_recHandle, false);
+ ...
+ // stops recording
+ Bass.BASS_ChannelStop(_recHandle);
+ // stop the live recording waveform
+ if (WF != null)
+ {
+ WF.RenderStopRecording();
+ DrawWave();
+ }
+ ...
+ // the recording callback in which we will render the WaveForm
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // get and draw our live recording waveform
+ WF.RenderRecording(buffer, length);
+ DrawWave();
+ }
+ return true; // always continue recording
+ }
+
+ // draws a rendered WaveForm to a PictureBox
+ private void DrawWave()
+ {
+ if (WF != null)
+ this.pictureBoxLiveWave.BackgroundImage = WF.CreateBitmap(this.pictureBoxLiveWave.Width,
+ this.pictureBoxLiveWave.Height,
+ -1, -1, false);
+ else
+ this.pictureBoxLiveWave.BackgroundImage = null;
+ }
+
+
+ Private WF As WaveForm = Nothing
+ Private _myRecProc As RECORDPROC ' make it global, so that the GC can not remove it
+ Private _recHandle As Integer = 0
+ ...
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero)
+ ' create a live recording WaveForm
+ WF = New WaveForm()
+ WF.FrameResolution = 0.01F ' 10ms are nice
+ ' start a live recording waveform with 10sec. init size and 5sec. next size
+ WF.RenderStartRecording(_recHandle, 10, 5)
+ ' really start recording
+ Bass.BASS_ChannelPlay(_recHandle, False)
+ ...
+ ' stops recording
+ Bass.BASS_ChannelStop(_recHandle)
+ ' stop the live recording waveform
+ If Not (WF Is Nothing) Then
+ WF.RenderStopRecording()
+ DrawWave()
+ End If
+ ...
+ ' the recording callback in which we will render the WaveForm
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ If length > 0 AndAlso buffer <> IntPtr.Zero Then
+ ' get and draw our live recording waveform
+ WF.RenderRecording(buffer, length)
+ DrawWave()
+ End If
+ Return True ' always continue recording
+ End Function
+
+ ' draws a rendered WaveForm to a PictureBox
+ Private Sub DrawWave()
+ If Not (WF Is Nothing) Then
+ Me.pictureBoxLiveWave.BackgroundImage = WF.CreateBitmap(Me.pictureBoxLiveWave.Width,
+ Me.pictureBoxLiveWave.Height,
+ -1, -1, False)
+ Else
+ Me.pictureBoxLiveWave.BackgroundImage = Nothing
+ End If
+ End Sub
+
+
+ private Un4seen.Bass.Misc.WaveForm WF = null;
+ ...
+ // render a wave form
+ WF = new WaveForm(_fileName, new WAVEFORMPROC(MyWaveFormCallback), this);
+ WF.FrameResolution = 0.01f; // 10ms are nice
+ WF.CallbackFrequency = 500; // every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line |
+ WaveForm.MARKERDRAWTYPE.Name |
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ // it is important to use the same resolution flags as for the playing stream!
+ // our already playing stream is 32-bit float - so this one will also need to be...
+ WF.RenderStart( false, BASSFlag.BASS_SAMPLE_FLOAT );
+ // from here on we might add markers...just examples here...
+ WF.AddMarker( "CueIn", Bass.BASS_ChannelSeconds2Bytes(_stream, 2.0) );
+ WF.AddMarker( "RampUp", Bass.BASS_ChannelSeconds2Bytes(_stream, 17.5));
+ WF.AddMarker( "Outro", Bass.BASS_ChannelSeconds2Bytes(_stream, 100.7));
+ WF.AddMarker( "Mix", Bass.BASS_ChannelSeconds2Bytes(_stream, 130.3));
+ WF.AddMarker( "End", Bass.BASS_ChannelSeconds2Bytes(_stream, 136.9));
+ ...
+ // this will replace the 'RampUp' marker
+ WF.AddMarker( "RampUp", Bass.BASS_ChannelSeconds2Bytes(_stream, 19.2));
+
+
+ Private WF As Un4seen.Bass.Misc.WaveForm = Nothing
+ ...
+ ' render a wave form
+ WF = New WaveForm(_fileName, New WAVEFORMPROC(MyWaveFormCallback), Me)
+ WF.FrameResolution = 0.01F ' 10ms are nice
+ WF.CallbackFrequency = 500 ' every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line Or
+ WaveForm.MARKERDRAWTYPE.Name Or
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate
+ ' it is important to use the same resolution flags as for the playing stream!
+ ' our already playing stream is 32-bit float - so this one will also need to be...
+ WF.RenderStart(False, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' from here on we might add markers...just examples here...
+ WF.AddMarker("CueIn", Bass.BASS_ChannelSeconds2Bytes(_stream, 2.0))
+ WF.AddMarker("RampUp", Bass.BASS_ChannelSeconds2Bytes(_stream, 17.5))
+ WF.AddMarker("Outro", Bass.BASS_ChannelSeconds2Bytes(_stream, 100.7))
+ WF.AddMarker("Mix", Bass.BASS_ChannelSeconds2Bytes(_stream, 130.3))
+ WF.AddMarker("End", Bass.BASS_ChannelSeconds2Bytes(_stream, 136.9))
+ ...
+ ' this will replace the 'RampUp' marker
+ WF.AddMarker("RampUp", Bass.BASS_ChannelSeconds2Bytes(_stream, 19.2))
+
+
+ private Un4seen.Bass.Misc.WaveForm WF = null;
+ ...
+ // render a wave form
+ WF = new WaveForm(_fileName, new WAVEFORMPROC(MyWaveFormCallback), this);
+ WF.FrameResolution = 0.01f; // 10ms are nice
+ WF.CallbackFrequency = 500; // every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line |
+ WaveForm.MARKERDRAWTYPE.Name |
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ // it is important to use the same resolution flags as for the playing stream!
+ // our already playing stream is 32-bit float - so this one will also need to be...
+ WF.RenderStart( false, BASSFlag.BASS_SAMPLE_FLOAT );
+ // from here on we might add markers...just examples here...
+ WF.AddMarker( "CueIn", 2.0 );
+ WF.AddMarker( "RampUp", 17.5);
+ WF.AddMarker( "Outro", 100.7);
+ WF.AddMarker( "Mix", 130.3);
+ WF.AddMarker( "End", 136.9);
+ ...
+ // this will replace the 'RampUp' marker
+ WF.AddMarker( "RampUp", 19.2);
+
+
+ Private WF As Un4seen.Bass.Misc.WaveForm = Nothing
+ ...
+ ' render a wave form
+ WF = New WaveForm(_fileName, New WAVEFORMPROC(MyWaveFormCallback), Me)
+ WF.FrameResolution = 0.01F ' 10ms are nice
+ WF.CallbackFrequency = 500 ' every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line Or
+ WaveForm.MARKERDRAWTYPE.Name Or
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate
+ ' it is important to use the same resolution flags as for the playing stream!
+ ' our already playing stream is 32-bit float - so this one will also need to be...
+ WF.RenderStart(False, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' from here on we might add markers...just examples here...
+ WF.AddMarker("CueIn", 2.0)
+ WF.AddMarker("RampUp", 17.5)
+ WF.AddMarker("Outro", 100.7)
+ WF.AddMarker("Mix", 130.3)
+ WF.AddMarker("End", 136.9)
+ ...
+ ' this will replace the 'RampUp' marker
+ WF.AddMarker("RampUp", 19.2)
+
+
+ private Un4seen.Bass.Misc.WaveForm WF = null;
+ ...
+ // render a wave form
+ WF = new WaveForm(_fileName, new WAVEFORMPROC(MyWaveFormCallback), this);
+ WF.FrameResolution = 0.01f; // 10ms are nice
+ WF.CallbackFrequency = 500; // every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line |
+ WaveForm.MARKERDRAWTYPE.Name |
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ WF.RenderStart( false, BASSFlag.BASS_SAMPLE_FLOAT );
+ // from here on we might add markers...just examples here...
+ WF.AddMarker( "CueIn", Bass.BASS_ChannelSeconds2Bytes(_stream, 2.0) );
+ ...
+ // this will get the 'CueIn' marker
+ long position = WF.GetMarker( "CueIn" );
+
+
+ Private WF As Un4seen.Bass.Misc.WaveForm = Nothing
+ ...
+ ' render a wave form
+ WF = New WaveForm(_fileName, New WAVEFORMPROC(MyWaveFormCallback), Me)
+ WF.FrameResolution = 0.01F ' 10ms are nice
+ WF.CallbackFrequency = 500 ' every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line Or
+ WaveForm.MARKERDRAWTYPE.Name Or
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate
+ WF.RenderStart(False, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' from here on we might add markers...just examples here...
+ WF.AddMarker("CueIn", Bass.BASS_ChannelSeconds2Bytes(_stream, 2.0))
+ ...
+ ' this will get the 'CueIn' marker
+ Dim position As Long = WF.GetMarker("CueIn")
+
+
+ private Un4seen.Bass.Misc.WaveForm WF = null;
+ ...
+ // render a wave form
+ WF = new WaveForm(_fileName, new WAVEFORMPROC(MyWaveFormCallback), this);
+ WF.FrameResolution = 0.01f; // 10ms are nice
+ WF.CallbackFrequency = 500; // every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line |
+ WaveForm.MARKERDRAWTYPE.Name |
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ WF.RenderStart( false, BASSFlag.BASS_SAMPLE_FLOAT );
+ // from here on we might add markers...just examples here...
+ WF.AddMarker( "CueIn", 2.0 );
+ ...
+ // this will get the 'CueIn' marker
+ double position = WF.GetMarkerSec( "CueIn" );
+
+
+ Private WF As Un4seen.Bass.Misc.WaveForm = Nothing
+ ...
+ ' render a wave form
+ WF = New WaveForm(_fileName, New WAVEFORMPROC(MyWaveFormCallback), Me)
+ WF.FrameResolution = 0.01F ' 10ms are nice
+ WF.CallbackFrequency = 500 ' every 5 seconds rendered (500*10ms=5sec)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line Or
+ WaveForm.MARKERDRAWTYPE.Name Or
+ WaveForm.MARKERDRAWTYPE.NamePositionAlternate
+ WF.RenderStart(False, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' from here on we might add markers...just examples here...
+ WF.AddMarker("CueIn", 2.0)
+ ...
+ ' this will get the 'CueIn' marker
+ Dim position As Double = WF.GetMarkerSec("CueIn")
+
+
+ private Un4seen.Bass.Misc.WaveForm WF = null;
+ ...
+ // render a wave form
+ WF = new WaveForm(this._fileName, new WAVEFORMPROC(MyWaveFormCallback), this);
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line;
+ WF.RenderStart( true, BASSFlag.BASS_SAMPLE_FLOAT );
+ // from here on we might add markers...just examples here...
+ WF.AddMarker( "CueIn", Bass.BASS_ChannelSeconds2Bytes(_stream, 2.0) );
+ WF.AddMarker( "RampUp", Bass.BASS_ChannelSeconds2Bytes(_stream, 17.5));
+ WF.AddMarker( "Outro", Bass.BASS_ChannelSeconds2Bytes(_stream, 100.7));
+ WF.AddMarker( "Mix", Bass.BASS_ChannelSeconds2Bytes(_stream, 130.3));
+ WF.AddMarker( "End", Bass.BASS_ChannelSeconds2Bytes(_stream, 136.9));
+ ...
+ // this will remove the 'CueIn' marker
+ WF.RemoveMarker( "CueIn" );
+
+
+ Private WF As Un4seen.Bass.Misc.WaveForm = Nothing
+ ...
+ ' render a wave form
+ WF = New WaveForm(Me._fileName, New WAVEFORMPROC(MyWaveFormCallback), Me)
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line
+ WF.RenderStart(True, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' from here on we might add markers...just examples here...
+ WF.AddMarker("CueIn", Bass.BASS_ChannelSeconds2Bytes(_stream, 2.0))
+ WF.AddMarker("RampUp", Bass.BASS_ChannelSeconds2Bytes(_stream, 17.5))
+ WF.AddMarker("Outro", Bass.BASS_ChannelSeconds2Bytes(_stream, 100.7))
+ WF.AddMarker("Mix", Bass.BASS_ChannelSeconds2Bytes(_stream, 130.3))
+ WF.AddMarker("End", Bass.BASS_ChannelSeconds2Bytes(_stream, 136.9))
+ ...
+ ' this will remove the 'CueIn' marker
+ WF.RemoveMarker("CueIn")
+
+
+ private Un4seen.Bass.Misc.WaveForm WF = null;
+
+ private void GetWaveForm()
+ {
+ // render a wave form
+ WF = new Un4seen.Bass.Misc.WaveForm("test.mp3",
+ new Un4seen.Bass.Misc.WAVEFORMPROC(MyWaveFormCallback), this);
+ WF.CallbackFrequency = 500; // every 10 seconds rendered
+ WF.ColorBackground = Color.Black;
+ WF.ColorBase = Color.Lime;
+ WF.ColorPeak = Color.Red;
+ // it is important to use the same resolution flags as for the playing stream
+ // e.g. if an already playing stream is 32-bit float, so this should also be
+ // or use 'SyncPlayback' as shown below
+ WF.RenderStart(true, BASSFlag.BASS_DEFAULT);
+ }
+
+ private void MyWaveFormCallback(int framesDone, int framesTotal, TimeSpan elapsedTime, bool finished)
+ {
+ // will be called during rendering...
+ DrawWave();
+ if (finished)
+ {
+ Console.WriteLine("Finished rendering in {0}sec.", elapsedTime);
+ Console.WriteLine("FramesRendered={0} of {1}", WF.FramesRendered, WF.FramesToRender);
+ // if your playback stream uses a different resolution than the WF
+ // use this to sync them
+ WF.SyncPlayback(_stream);
+ }
+ }
+
+ private void DrawWave()
+ {
+ if (WF != null)
+ this.pictureBox1.BackgroundImage = WF.CreateBitmap(this.pictureBox1.Width,
+ this.pictureBox1.Height,
+ -1, -1, false);
+ else
+ this.pictureBox1.BackgroundImage = null;
+ }
+
+
+ Private WF As Un4seen.Bass.Misc.WaveForm = Nothing
+ ...
+ Private Sub GetWaveForm()
+ ' render a wave form
+ WF = New Un4seen.Bass.Misc.WaveForm("test.mp3", New Un4seen.Bass.Misc.WAVEFORMPROC(MyWaveFormCallback), Me)
+ WF.CallbackFrequency = 500 ' every 10 seconds rendered
+ WF.ColorBackground = Color.Black
+ WF.ColorBase = Color.Lime
+ WF.ColorPeak = Color.Red
+ ' it is important to use the same resolution flags as for the playing stream
+ ' e.g. if an already playing stream is 32-bit float, so this should also be
+ ' or use 'SyncPlayback' as shown below
+ WF.RenderStart(True, BASSFlag.BASS_SAMPLE_FLOAT)
+ End Sub
+
+ Private Sub MyWaveFormCallback(framesDone As Integer, framesTotal As Integer,
+ elapsedTime As TimeSpan, finished As Boolean)
+ ' will be called during rendering...
+ DrawWave()
+ If finished Then
+ Console.WriteLine("Finished rendering in {0}sec.", elapsedTime)
+ Console.WriteLine("FramesRendered={0} of {1}", WF.FramesRendered, WF.FramesToRender)
+ ' if your playback stream uses a different resolution than the WF
+ ' use this to sync them
+ WF.SyncPlayback(_stream)
+ End If
+ End Sub
+
+ Private Sub DrawWave()
+ If Not (WF Is Nothing) Then
+ Me.pictureBox1.BackgroundImage = WF.CreateBitmap(Me.pictureBox1.Width,
+ Me.pictureBox1.Height,
+ -1, -1, False)
+ Else
+ Me.pictureBox1.BackgroundImage = Nothing
+ End If
+ End Sub
+
+
+ // assuming the WaveForm is fully displayed in the pictureBox...
+ private void DrawWave()
+ {
+ if (WF != null)
+ this.pictureBox1.BackgroundImage = WF.CreateBitmap(this.pictureBox1.Width,
+ this.pictureBox1.Height,
+ -1, -1, false);
+ else
+ this.pictureBox1.BackgroundImage = null;
+ }
+
+ private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
+ {
+ if (WF == null)
+ return;
+ long pos = WF.GetBytePositionFromX(e.X, this.pictureBox1.Width, -1, -1);
+ Console.WriteLine("Position = {0}, Seconds = {1}", pos, Bass.BASS_ChannelBytes2Seconds(_stream, pos));
+ Bass.BASS_ChannelSetPosition(_stream, pos);
+ }
+
+
+ ' assuming the WaveForm is fully displayed in the pictureBox...
+ Private Sub DrawWave()
+ If Not (WF Is Nothing) Then
+ Me.pictureBox1.BackgroundImage = WF.CreateBitmap(Me.pictureBox1.Width,
+ Me.pictureBox1.Height,
+ -1, -1, False)
+ Else
+ Me.pictureBox1.BackgroundImage = Nothing
+ End If
+ End Sub
+
+ Private Sub pictureBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
+ If WF Is Nothing Then
+ Return
+ End If
+ Dim pos As Long = WF.GetBytePositionFromX(e.X, Me.pictureBox1.Width, - 1, - 1)
+ Console.WriteLine("Position = {0}, Seconds = {1}", pos, Bass.BASS_ChannelBytes2Seconds(_stream, pos))
+ Bass.BASS_ChannelSetPosition(_stream, pos)
+ End Sub
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -30.0);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Long = 0
+ Dim endpos As Long = 0
+ WF.GetCuePoints(startpos, endpos, -30.0)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -30.0, -50.0);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Long = 0
+ Dim endpos As Long = 0
+ WF.GetCuePoints(startpos, endpos, -30.0, -50.0)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -24.0, -42.0, true);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Long = 0
+ Dim endpos As Long = 0
+ WF.GetCuePoints(startpos, endpos, -24.0, -42.0, True)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -40.0, -1, -1);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Long = 0
+ Dim endpos As Long = 0
+ WF.GetCuePoints(startpos, endpos, -40.0, -1, -1)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -42.0, -1, -1, true);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Long = 0
+ Dim endpos As Long = 0
+ WF.GetCuePoints(startpos, endpos, -42.0, -1, -1, True)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -24.0, -50.0, -1, -1);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ long startpos = 0;
+ long endpos = 0;
+ WF.GetCuePoints(ref startpos, ref endpos, -30.0, -50.0, -1, -1, true);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Long = 0
+ Dim endpos As Long = 0
+ WF.GetCuePoints(startpos, endpos, -30.0, -50.0, -1, -1, True)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -30.0);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -30.0)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -30.0, -50.0);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -30.0, -50.0)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -24.0, -42.0, true);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -24.0, -42.0, True)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -40.0, -1, -1);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -40.0, -1, -1)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -42.0, -1, -1, true);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -42.0, -1, -1, True)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -24.0, -50.0, -1, -1);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -24.0, -50.0, -1, -1)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ double startpos = 0.0;
+ double endpos = 0.0;
+ WF.GetCuePoints(ref startpos, ref endpos, -30.0, -50.0, -1, -1, true);
+ WF.AddMarker( "CUE", startpos );
+ WF.AddMarker( "END", endpos );
+ ...
+
+
+ Dim startpos As Double = 0.0
+ Dim endpos As Double = 0.0
+ WF.GetCuePoints(startpos, endpos, -30.0, -50.0, -1, -1, True)
+ WF.AddMarker("CUE", startpos)
+ WF.AddMarker("END", endpos)
+ ...
+
+
+ private byte[] waveformSave;
+ ...
+ // save the wave form to a byte array
+ waveformSave = WF.WaveFormSaveToMemory();
+ ..
+ // load the wave form to a byte array
+ WF = new Un4seen.Bass.Misc.WaveForm();
+ WF.WaveFormLoadFromMemory( waveformSave );
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line | WaveForm.MARKERDRAWTYPE.Name | WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ this.pictureBox1.BackgroundImage = WF.CreateBitmap( this.pictureBox1.Width, this.pictureBox1.Height, -1, -1, true);
+
+
+ private byte[] waveformSave;
+ ...
+ // save the wave form to a byte array
+ waveformSave = WF.WaveFormSaveToMemory(true);
+ ..
+ // load the wave form to a byte array
+ WF = new Un4seen.Bass.Misc.WaveForm();
+ WF.WaveFormLoadFromMemory( waveformSave, true );
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line | WaveForm.MARKERDRAWTYPE.Name | WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ this.pictureBox1.BackgroundImage = WF.CreateBitmap( this.pictureBox1.Width, this.pictureBox1.Height, -1, -1, true);
+
+
+ private byte[] waveformSave;
+ ...
+ // save the wave form to a byte array
+ waveformSave = WF.WaveFormSaveToMemory();
+ ..
+ // load the wave form to a byte array
+ WF = new Un4seen.Bass.Misc.WaveForm();
+ WF.WaveFormLoadFromMemory( waveformSave );
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line | WaveForm.MARKERDRAWTYPE.Name | WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ this.pictureBox1.BackgroundImage = WF.CreateBitmap( this.pictureBox1.Width, this.pictureBox1.Height, -1, -1, true);
+
+
+ private byte[] waveformSave;
+ ...
+ // save the wave form to a byte array
+ waveformSave = WF.WaveFormSaveToMemory();
+ ..
+ // load the wave form to a byte array
+ WF = new Un4seen.Bass.Misc.WaveForm();
+ WF.WaveFormLoadFromMemory( waveformSave );
+ WF.DrawMarker = WaveForm.MARKERDRAWTYPE.Line | WaveForm.MARKERDRAWTYPE.Name | WaveForm.MARKERDRAWTYPE.NamePositionAlternate;
+ this.pictureBox1.BackgroundImage = WF.CreateBitmap( this.pictureBox1.Width, this.pictureBox1.Height, -1, -1, true);
+
+
+ | 32-bit |
+ | left | right |
+
+
+ private void pictureBoxSpectrum_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
+ {
+ if (_vis == null)
+ return;
+ int freq = _vis.GetFrequencyFromPosX(e.X, 44100);
+ float amp = _vis.GetAmplitudeFromPosY(e.Y, this.pictureBoxSpectrum.Height);
+ this.labelVis.Text = String.Format( "Freq={0}Hz, Amp={1}", freq, amp );
+ }
+
+
+ Private Sub pictureBoxSpectrum_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs)
+ If _vis Is Nothing Then
+ Return
+ End If
+ Dim freq As Integer = _vis.GetFrequencyFromPosX(e.X, 44100)
+ Dim amp As Single = _vis.GetAmplitudeFromPosY(e.Y, Me.pictureBoxSpectrum.Height)
+ Me.labelVis.Text = [String].Format("Freq={0}Hz, Amp={1}", freq, amp)
+ End Sub
+
+
+ private void pictureBoxSpectrum_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
+ {
+ if (_vis == null)
+ return;
+ int freq = _vis.GetFrequencyFromPosX(e.X, 44100);
+ float amp = _vis.GetAmplitudeFromPosY(e.Y, this.pictureBoxSpectrum.Height);
+ this.labelVis.Text = String.Format( "Freq={0}Hz, Amp={1}", freq, amp );
+ }
+
+
+ Private Sub pictureBoxSpectrum_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs)
+ If _vis Is Nothing Then
+ Return
+ End If
+ Dim freq As Integer = _vis.GetFrequencyFromPosX(e.X, 44100)
+ Dim amp As Single = _vis.GetAmplitudeFromPosY(e.Y, Me.pictureBoxSpectrum.Height)
+ Me.labelVis.Text = [String].Format("Freq={0}Hz, Amp={1}", freq, amp)
+ End Sub
+
+
+ this.pictureBoxSpectrum.Image = Un4seen.Bass.Misc.Visuals.CreateSpectrum(_stream,
+ this.pictureBoxSpectrum.Width,
+ this.pictureBoxSpectrum.Height,
+ Color.Lime, Color.Red, Color.Black,
+ false, false, false);
+
+
+ Me.pictureBoxSpectrum.Image = Un4seen.Bass.Misc.Visuals.CreateSpectrum(_stream,
+ Me.pictureBoxSpectrum.Width,
+ Me.pictureBoxSpectrum.Height,
+ Color.Lime, Color.Red, Color.Black,
+ False, False, False)
+
+
+ IntPtr pUnk = Un4seen.Bass.AddOn.Wma.BassWma.BASS_WMA_GetWMObject(stream);
+ IWMHeaderInfo3 headerInfo3 = (IWMHeaderInfo3)Marshal.GetObjectForIUnknown( pUnk );
+ if (headerInfo3 != null)
+ {
+ ...
+ }
+
+
+ Dim pUnk As IntPtr = Un4seen.Bass.AddOn.Wma.BassWma.BASS_WMA_GetWMObject(stream)
+ Dim headerInfo3 As IWMHeaderInfo3 = CType(Marshal.GetObjectForIUnknown(pUnk), IWMHeaderInfo3)
+ If Not (headerInfo3 Is Nothing) Then
+ ...
+ End If
+
+
+ int[] bitrates = BassWma.BASS_WMA_EncodeGetRates(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_RATES_CBR );
+ if (bitrates != null)
+ {
+ foreach (int bitrate in bitrates)
+ Console.WriteLine( bitrate );
+ }
+
+
+ Dim bitrates As Integer() = BassWma.BASS_WMA_EncodeGetRates(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_RATES_CBR)
+ If Not (bitrates Is Nothing) Then
+ Dim bitrate As Integer
+ For Each bitrate In bitrates
+ Console.WriteLine(bitrate)
+ Next bitrate
+ End If
+
+
+ // the encoding callback
+ private WMENCODEPROC _myEndoderProc;
+ private FileStream _fs;
+ private byte[] _encbuffer = new byte[1048510]; // 1MB buffer, should be enough
+ ...
+ // open a wma file
+ _fs = File.OpenRead("test.wma");
+ // create the encoder (44kHz, stereo at 64kbps, no tags)
+ _myEndoderProc = new WMENCODEPROC(MyEncodingWriter);
+ int encoder = BassWma.BASS_WMA_EncodeOpen(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 64000, _myEndoderProc, IntPtr.Zero);
+ ...
+ private bool MyEncodingWriter(int handle, BASSWMAEncodeCallback type, IntPtr buffer, int length, IntPtr user)
+ {
+ if (type == BASSWMAEncodeCallback.BASS_WMA_ENCODE_HEAD)
+ {
+ // rewind to start of file to write the header
+ _fs.Position = 0L;
+ }
+
+ if (type == BASSWMAEncodeCallback.BASS_WMA_ENCODE_DONE)
+ {
+ // done encoding - close the file
+ _fs.Flush();
+ _fs.Close();
+ }
+ else
+ {
+ // copy the unmanaged buffer content to out managed buffer
+ Marshal.Copy(buffer, _encbuffer, 0, length);
+ // process the data in _encbuffer
+ _fs.Write(_encbuffer, 0, length);
+ }
+ }
+
+
+ Private _myEndoderProc As WMENCODEPROC
+ Private _fs As FileStream
+ Private _encbuffer(1048510) As Byte ' 1MB buffer, should be enough
+ ...
+ ' open a wma file
+ _fs = File.OpenRead("test.wma")
+ ' create the encoder (44kHz, stereo at 64kbps, no tags)
+ _myEndoderProc = New WMENCODEPROC(AddressOf MyEncodingWriter)
+ Dim encoder As Integer = BassWma.BASS_WMA_EncodeOpen(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 64000, _myEndoderProc, IntPtr.Zero)
+ ...
+ Private Function MyEncodingWriter(handle As Integer, type As BASSWMAEncodeCallback,
+ buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ If type = BASSWMAEncodeCallback.BASS_WMA_ENCODE_HEAD Then
+ ' rewind to start of file to write the header
+ _fs.Position = 0L.ToUInt32()
+ End If
+
+ If type = BASSWMAEncodeCallback.BASS_WMA_ENCODE_DONE Then
+ ' done encoding - close the file
+ _fs.Flush()
+ _fs.Close()
+ Else
+ ' copy the unmanaged buffer content to out managed buffer
+ Marshal.Copy(buffer, _encbuffer, 0, length)
+ ' process the data in _encbuffer
+ _fs.Write(_encbuffer, 0, length)
+ End If
+ End Function
+
+ NOTE: This is just an example. It's obviously simpler to use
+ int stream = Bass.BASS_StreamCreateFile("input.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ if (stream != 0)
+ {
+ byte[] buffer = new byte[16384]; // 16KB decode buffer
+ int enc = BassWma.BASS_WMA_EncodeOpenFile(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, "output.wma");
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ int len = Bass.BASS_ChannelGetData(stream, buffer, 16384);
+ if (len > 0)
+ BassWma.BASS_WMA_EncodeWrite(enc, buffer, len);
+ }
+ BassWma.BASS_WMA_EncodeClose(enc);
+ }
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("input.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ If stream <> 0 Then
+ Dim buffer(16384 - 1) As Byte ' 16KB decode buffer
+ Dim enc As Integer = BassWma.BASS_WMA_EncodeOpenFile(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, "output.wma")
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ Dim len As Integer = Bass.BASS_ChannelGetData(stream, buffer, 16384)
+ If len > 0 Then
+ BassWma.BASS_WMA_EncodeWrite(enc, buffer, len)
+ End If
+ End While
+ BassWma.BASS_WMA_EncodeClose(enc)
+ End If
+
+
+ private RECORDPROC _myRecProc;
+ ...
+ if ( Bass.BASS_RecordInit(-1) )
+ {
+ int enc = BassWma.BASS_WMA_EncodeOpenNetwork(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, 0, 5);
+ _myRecProc = new RECORDPROC(MyRecording);
+ int recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, _myRecProc, new IntPtr(enc));
+ }
+ ...
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // write the recorded data to the encoder
+ BassWma.BASS_WMA_EncodeWrite(user.ToInt32(), buffer, length);
+ }
+ return true;
+ }
+
+
+ Private _myRecProc As RECORDPROC
+ ...
+ If Bass.BASS_RecordInit(-1) Then
+ Dim enc As Integer = BassWma.BASS_WMA_EncodeOpenNetwork(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, 0, 5)
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ Dim recHandle As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, _myRecProc, New IntPtr(enc))
+ End If
+ ...
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ If length > 0 AndAlso buffer <> IntPtr.Zero Then
+ ' write the recorded data to the encoder
+ BassWma.BASS_WMA_EncodeWrite(user.ToInt32(), buffer, length)
+ End If
+ Return True
+ End Function
+
+
+ int[] bitrates = {128000, 64000, 0}; // the bitrates
+ int encoder = BassWma.BASS_WMA_EncodeOpenNetworkMulti( 44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, bitrates, 4711, 5);
+
+
+ Dim bitrates As Integer() = {128000, 64000, 0} ' the bitrates
+ Dim encoder As Integer = BassWma.BASS_WMA_EncodeOpenNetworkMulti(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, bitrates, 4711, 5)
+
+
+ private CLIENTCONNECTPROC _myClientConnectProc;
+ ...
+ // set the notification callback
+ _myClientConnectProc = new CLIENTCONNECTPROC(MyClientConnectNotify);
+ BassWma.BASS_WMA_EncodeSetNotify(encoder, _myClientConnectProc, IntPtr.Zero);
+ ...
+ // the recording callback
+ private void MyClientConnectNotify(int handle, bool connect, string ip, IntPtr user)
+ {
+ if (connect)
+ Console.Writeln( "Connected: {0} at {1}", ip, DateTime.Now );
+ else
+ Console.Writeln( "Disconnected: {0} at {1}", ip, DateTime.Now );
+ }
+
+
+ Private _myClientConnectProc As CLIENTCONNECTPROC
+ ...
+ ' set the notification callback
+ _myClientConnectProc = New CLIENTCONNECTPROC(AddressOf MyClientConnectNotify)
+ BassWma.BASS_WMA_EncodeSetNotify(encoder, _myClientConnectProc, IntPtr.Zero)
+ ...
+ ' the recording callback
+ Private Sub MyClientConnectNotify(handle As Integer, connect As Boolean, ip As String, user As IntPtr)
+ If connect Then
+ Console.Writeln("Connected: {0} at {1}", ip, DateTime.Now)
+ Else
+ Console.Writeln("Disconnected: {0} at {1}", ip, DateTime.Now)
+ End If
+ End Sub
+
+
+ int encoder = BassWma.BASS_WMA_EncodeOpenFile(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, 128000, "out.wma");
+ // set the title tag
+ BassWma.BASS_WMA_EncodeSetTag(encoder, "Title", "Something", BASSWMATag.BASS_WMA_TAG_UNICODE);
+
+
+ Dim encoder As Integer = BassWma.BASS_WMA_EncodeOpenFile(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, 128000, "out.wma")
+ ' set the title tag
+ BassWma.BASS_WMA_EncodeSetTag(encoder, "Title", "Something", BASSWMATag.BASS_WMA_TAG_UNICODE)
+
+
+ int encoder = BassWma.BASS_WMA_EncodeOpenFile(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, 128000, "out.wma");
+ // set the title tag
+ BassWma.BASS_WMA_EncodeSetTag(encoder, "Title", "Something", BASSWMATag.BASS_WMA_TAG_UTF8);
+
+
+ Dim encoder As Integer = BassWma.BASS_WMA_EncodeOpenFile(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, 128000, "out.wma")
+ ' set the title tag
+ BassWma.BASS_WMA_EncodeSetTag(encoder, "Title", "Something", BASSWMATag.BASS_WMA_TAG_UTF8)
+
+
+ int encoder = BassWma.BASS_WMA_EncodeOpenFile(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, 128000, "out.wma");
+ // set the title tag
+ BassWma.BASS_WMA_EncodeSetTag(encoder, "Title", "Something");
+
+
+ Dim encoder As Integer = BassWma.BASS_WMA_EncodeOpenFile(44100, 2,
+ BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, 128000, "out.wma")
+ ' set the title tag
+ BassWma.BASS_WMA_EncodeSetTag(encoder, "Title", "Something")
+
+
+ private RECORDPROC _myRecProc;
+ ...
+ if ( Bass.BASS_RecordInit(-1) )
+ {
+ int enc = BassWma.BASS_WMA_EncodeOpenNetwork(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, 0, 5);
+ _myRecProc = new RECORDPROC(MyRecording);
+ int recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, _myRecProc, new IntPtr(enc));
+ }
+ ...
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // write the recorded data to the encoder
+ BassWma.BASS_WMA_EncodeWrite(user.ToInt32(), buffer, length);
+ }
+ return true;
+ }
+
+
+ Private _myRecProc As RECORDPROC
+ ...
+ If Bass.BASS_RecordInit(-1) Then
+ Dim enc As Integer = BassWma.BASS_WMA_EncodeOpenNetwork(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, 0, 5)
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ Dim recHandle As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, _myRecProc, New IntPtr(enc))
+ End If
+ ...
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ If length > 0 AndAlso buffer <> IntPtr.Zero Then
+ ' write the recorded data to the encoder
+ BassWma.BASS_WMA_EncodeWrite(user.ToInt32(), buffer, length)
+ End If
+ Return True
+ End Function
+
+
+ int stream = Bass.BASS_StreamCreateFile("input.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE);
+ if (stream != 0)
+ {
+ byte[] buffer = new byte[16384]; // 16KB decode buffer
+ int enc = BassWma.BASS_WMA_EncodeOpenFile(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, "output.wma");
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ int len = Bass.BASS_ChannelGetData(stream, buffer, 16384);
+ if (len > 0)
+ BassWma.BASS_WMA_EncodeWrite(enc, buffer, len);
+ }
+ BassWma.BASS_WMA_EncodeClose(enc);
+ }
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("input.mp3", 0L, 0L, BASSFlag.BASS_STREAM_DECODE)
+ If stream <> 0 Then
+ Dim buffer(16384 - 1) As Byte ' 16KB decode buffer
+ Dim enc As Integer = BassWma.BASS_WMA_EncodeOpenFile(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 128000, "output.wma")
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ Dim len As Integer = Bass.BASS_ChannelGetData(stream, buffer, 16384)
+ If len > 0 Then
+ BassWma.BASS_WMA_EncodeWrite(enc, buffer, len)
+ End If
+ End While
+ BassWma.BASS_WMA_EncodeClose(enc)
+ End If
+
+
+ Bass.LoadMe();
+ BassWma.LoadMe();
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassWma.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ private CLIENTCONNECTPROC _myClientConnectProc;
+ ...
+ // set the notification callback
+ _myClientConnectProc = new CLIENTCONNECTPROC(MyClientConnectNotify);
+ BassWma.BASS_WMA_EncodeSetNotify(encoder, _myClientConnectProc, IntPtr.Zero);
+ ...
+ // the recording callback
+ private void MyClientConnectNotify(int handle, bool connect, string ip, IntPtr user)
+ {
+ if (connect)
+ Console.Writeln( "Connected: {0} at {1}", ip, DateTime.Now );
+ else
+ Console.Writeln( "Disconnected: {0} at {1}", ip, DateTime.Now );
+ }
+
+
+ Private _myClientConnectProc As CLIENTCONNECTPROC
+ ...
+ ' set the notification callback
+ _myClientConnectProc = New CLIENTCONNECTPROC(AddressOf MyClientConnectNotify)
+ BassWma.BASS_WMA_EncodeSetNotify(encoder, _myClientConnectProc, IntPtr.Zero)
+ ...
+ ' the recording callback
+ Private Sub MyClientConnectNotify(handle As Integer, connect As Boolean, ip As String, user As IntPtr)
+ If connect Then
+ Console.Writeln("Connected: {0} at {1}", ip, DateTime.Now)
+ Else
+ Console.Writeln("Disconnected: {0} at {1}", ip, DateTime.Now)
+ End If
+ End Sub
+
+
+ // the encoding callback
+ private WMENCODEPROC _myEndoderProc;
+ private FileStream _fs;
+ private byte[] _encbuffer = new byte[1048510]; // 1MB buffer, should be enough
+ ...
+ // open a wma file
+ _fs = File.OpenRead("test.wma");
+ // create the encoder (44kHz, stereo at 64kbps, no tags)
+ _myEndoderProc = new WMENCODEPROC(MyEncodingWriter);
+ int encoder = BassWma.BASS_WMA_EncodeOpen(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 64000, _myEndoderProc, IntPtr.Zero);
+ ...
+ private bool MyEncodingWriter(int handle, BASSWMAEncodeCallback type, IntPtr buffer, int length, IntPtr user)
+ {
+ if (type == BASSWMAEncodeCallback.BASS_WMA_ENCODE_HEAD)
+ {
+ // rewind to start of file to write the header
+ _fs.Position = 0L;
+ }
+
+ if (type == BASSWMAEncodeCallback.BASS_WMA_ENCODE_DONE)
+ {
+ // done encoding - close the file
+ _fs.Flush();
+ _fs.Close();
+ }
+ else
+ {
+ // copy the unmanaged buffer content to out managed buffer
+ Marshal.Copy(buffer, _encbuffer, 0, length);
+ // process the data in _encbuffer
+ _fs.Write(_encbuffer, 0, length);
+ }
+ }
+
+
+ Private _myEndoderProc As WMENCODEPROC
+ Private _fs As FileStream
+ Private _encbuffer(1048510) As Byte ' 1MB buffer, should be enough
+ ...
+ ' open a wma file
+ _fs = File.OpenRead("test.wma")
+ ' create the encoder (44kHz, stereo at 64kbps, no tags)
+ _myEndoderProc = New WMENCODEPROC(AddressOf MyEncodingWriter)
+ Dim encoder As Integer = BassWma.BASS_WMA_EncodeOpen(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT,
+ 64000, _myEndoderProc, IntPtr.Zero)
+ ...
+ Private Function MyEncodingWriter(handle As Integer, type As BASSWMAEncodeCallback,
+ buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ If type = BASSWMAEncodeCallback.BASS_WMA_ENCODE_HEAD Then
+ ' rewind to start of file to write the header
+ _fs.Position = 0L.ToUInt32()
+ End If
+
+ If type = BASSWMAEncodeCallback.BASS_WMA_ENCODE_DONE Then
+ ' done encoding - close the file
+ _fs.Flush()
+ _fs.Close()
+ Else
+ ' copy the unmanaged buffer content to out managed buffer
+ Marshal.Copy(buffer, _encbuffer, 0, length)
+ ' process the data in _encbuffer
+ _fs.Write(_encbuffer, 0, length)
+ End If
+ End Function
+
+ NOTE: This is just an example. It's obviously simpler to use
+ if ( Utils.HighWord(BassMix.BASS_Mixer_GetVersion()) != BassMix.BASSMIXVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassMix Version!");
+ }
+
+
+ If Utils.HighWord(BassMix.BASS_Mixer_GetVersion()) <> BassFx.BASSMIXVERSION Then
+ MessageBox.Show(Me, "Wrong BassMix Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassMix.BASS_Mixer_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassMix Version!");
+ }
+
+
+ If BassMix.BASS_Mixer_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassMix Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassMix.BASS_Mixer_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassMix Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassMix.BASS_Mixer_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassMix Version!")
+ End If
+
+
+ // this will be the final mixer output stream being played
+ int mixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT );
+ // now we need some channels to plug them in...create two decoding sources
+ int streamA = Bass.BASS_StreamCreateFile("testA.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ int streamB = Bass.BASS_StreamCreateFile("testB.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ // finally we plug them into the mixer (no downmix, since we assume the sources to be stereo)
+ bool okA = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_DEFAULT);
+ bool okB = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamB, BASSFlag.BASS_DEFAULT);
+ // and play it...
+ Bass.BASS_ChannelPlay(mixer, false);
+
+
+ ' this will be the final mixer output stream being played
+ Dim mixer As Integer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' now we need some channels to plug them in...create two decoding sources
+ Dim streamA As Integer = Bass.BASS_StreamCreateFile("testA.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ Dim streamB As Integer = Bass.BASS_StreamCreateFile("testB.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ ' finally we plug them into the mixer (no downmix, since we assume the sources to be stereo)
+ Dim okA As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_DEFAULT)
+ Dim okB As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamB, BASSFlag.BASS_DEFAULT)
+ ' and play it...
+ Bass.BASS_ChannelPlay(mixer, False)
+
+
+ // this will be the final mixer output stream being played
+ int mixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT );
+ // now we need some channels to plug them in...create two decoding sources
+ int streamA = Bass.BASS_StreamCreateFile("testA.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ int streamB = Bass.BASS_StreamCreateFile("testB.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ // finally we plug them into the mixer (no downmix, since we assume the sources to be stereo)
+ bool okA = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_DEFAULT);
+ bool okB = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamB, BASSFlag.BASS_DEFAULT);
+ // and play it...
+ Bass.BASS_ChannelPlay(mixer, false);
+
+
+ ' this will be the final mixer output stream being played
+ Dim mixer As Integer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' now we need some channels to plug them in...create two decoding sources
+ Dim streamA As Integer = Bass.BASS_StreamCreateFile("testA.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ Dim streamB As Integer = Bass.BASS_StreamCreateFile("testB.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ ' finally we plug them into the mixer (no downmix, since we assume the sources to be stereo)
+ Dim okA As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_DEFAULT)
+ Dim okB As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamB, BASSFlag.BASS_DEFAULT)
+ ' and play it...
+ Bass.BASS_ChannelPlay(mixer, False)
+
+
+ long start = Bass.BASS_ChannelSeconds2Bytes(mixer, 1.0); // delay
+ long length = Bass.BASS_ChannelSeconds2Bytes(mixer, 2.0); // duration
+ // add the channel
+ BassMix.BASS_Mixer_StreamAddChannelEx(mixer, channel, 0, start, length);
+
+
+ Dim start As Long = Bass.BASS_ChannelSeconds2Bytes(mixer, 1.0) ' delay
+ Dim length As Long = Bass.BASS_ChannelSeconds2Bytes(mixer, 2.0) ' duration
+ ' add the channel
+ BassMix.BASS_Mixer_StreamAddChannelEx(mixer, channel, 0, start, length)
+
+
+ BassMix.BASS_Mixer_StreamAddChannel(mixer, channel, BASSFlag.BASS_MIXER_BUFFER);
+ int level = BassMix.BASS_Mixer_ChannelGetLevel(channel);
+ int left = Utils.LowWord32(level); // the left level
+ int right = Utils.HighWord32(level); // the right level
+
+
+ BassMix.BASS_Mixer_StreamAddChannel(mixer, channel, BASSFlag.BASS_MIXER_BUFFER)
+ Dim level As Integer = BassMix.BASS_Mixer_ChannelGetLevel(channel)
+ Dim left As Integer = Utils.LowWord32(level) ' the left level
+ Dim right As Integer = Utils.HighWord32(level) ' the right level
+
+
+ float[] level = new float[2]; // dealing with stereo
+ if (BassMix.BASS_Mixer_ChannelGetLevel(channel, level))
+ {
+ float left = level[0]; // the left level
+ float right = level[1]; // the right level
+ }
+
+
+ Dim level(2) As Single ' dealing with stereo
+ If BassMix.BASS_Mixer_ChannelGetLevel(channel, level) Then
+ Dim left As Single = level(0) ' the left level
+ Dim right As Single = level(1) ' the right level
+ End If
+
+
+ // Disable ramping-in of a channel:
+ BassMix.BASS_Mixer_ChannelFlags(channel, BASSFlag.BASS_MIXER_NORAMPIN, BASSFlag.BASS_MIXER_NORAMPIN);
+
+ // Enable ramping-in of a channel:
+ BassMix.BASS_Mixer_ChannelFlags(channel, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_MIXER_NORAMPIN);
+
+
+ ' Disable ramping-in of a channel:
+ BassMix.BASS_Mixer_ChannelFlags(channel, BASSFlag.BASS_MIXER_NORAMPIN, BASSFlag.BASS_MIXER_NORAMPIN)
+
+ ' Enable ramping-in of a channel:
+ BassMix.BASS_Mixer_ChannelFlags(channel, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_MIXER_NORAMPIN)
+
+
+ BassMix.BASS_Mixer_ChannelSetPosition(streamA, Bass.BASS_ChannelSeconds2Bytes(streamA, 35.0));
+
+
+ BassMix.BASS_Mixer_ChannelSetPosition(streamA, Bass.BASS_ChannelSeconds2Bytes(streamA, 35.0));
+
+ Reset the playback buffer of the mixer:
+
+ BassMix.BASS_Mixer_ChannelSetPosition(mixer, 0L);
+
+
+ BassMix.BASS_Mixer_ChannelSetPosition(mixer, 0L)
+
+
+ BassMix.BASS_Mixer_ChannelSetPosition(streamA, Bass.BASS_ChannelSeconds2Bytes(streamA, 35.0));
+
+
+ BassMix.BASS_Mixer_ChannelSetPosition(streamA, Bass.BASS_ChannelSeconds2Bytes(streamA, 35.0));
+
+ Reset the playback buffer of the mixer:
+
+ BassMix.BASS_Mixer_ChannelSetPosition(mixer, 0L);
+
+
+ BassMix.BASS_Mixer_ChannelSetPosition(mixer, 0L)
+
+
+ ---------> (Input) ---------> (Input)
+ | L R | L R
+ | L 1 0 |LF 1 0
+ | R 0 1 |RF 0 1
+ v |LR 1 0
+ (Output) |RR 0 1
+ v
+ (Output)
+
+
+ // the source stream
+ int streamA = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE);
+ // create a 4-channel mixer stream
+ BASS_CHANNELINFO i = Bass.BASS_ChannelGetInfo(streamA);
+ int mixer = BassMix.BASS_Mixer_StreamCreate(i.freq, 4, BASSFlag.BASS_DEFAULT );
+ // add the source stream to the mixer with the matrix option
+ BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_MIXER_MATRIX);
+ // define a mixing matrix for the source stream
+ float[,] matrix = { // stereo to quad matrix
+ {1, 0}, // left in = left front out
+ {0, 1}, // right in = right front out
+ {1, 0}, // left in = left rear out
+ {0, 1} // right in = right rear out
+ };
+ // apply the matrix
+ BassMix.BASS_Mixer_ChannelSetMatrix(streamA, matrix);
+ // and play it
+ Bass.BASS_ChannelPlay(mixer, false);
+
+
+ ' the source stream
+ Dim streamA As Integer = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE)
+ ' create a 4-channel mixer stream
+ Dim i As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(streamA)
+ Dim mixer As Integer = BassMix.BASS_Mixer_StreamCreate(i.freq, 4, BASSFlag.BASS_DEFAULT)
+ ' add the source stream to the mixer with the matrix option
+ BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_MIXER_MATRIX)
+ ' define a mixing matrix for the source stream
+ Dim matrix(,) As Single = { ' stereo to quad matrix
+ {1, 0}, ' left in = left front out
+ {0, 1}, ' right in = right front out
+ {1, 0}, ' left in = left rear out
+ {0, 1} ' right in = right rear out
+ }
+ BassMix.BASS_Mixer_ChannelSetMatrix(streamA, matrix)
+ ' and play it
+ Bass.BASS_ChannelPlay(mixer, False)
+
+ Here are some more matrix examples...
+
+ // In = stereo, Out = stereo
+ float[,] matrix = {
+ {1, 0}, // left out = left in
+ {0, 1}, // right out = right in
+ };
+
+ // In = stereo, Out = swapped stereo
+ float[,] matrix = {
+ {0, 1}, // left out = right in
+ {1, 0}, // right out = left in
+ };
+
+ // In = stereo, Out = mono
+ float[,] matrix = {
+ {0.5f, 0.5f} // mono out = half left + right in
+ };
+
+ // In = stereo, Out = quadraphonic (4 channels)
+ float[,] matrix = { // stereo to quad matrix
+ {1, 0}, // left-front out = left in
+ {0, 1}, // right-front out = right in
+ {1, 0}, // left rear out = left in
+ {0, 1} // right rear out = right in
+ };
+
+ // In = mono, Out = quadraphonic (4 channels)
+ float[,] matrix = { // mono to quad matrix
+ {1}, // left-front out = mono in
+ {1}, // right-front out = mono in
+ {1}, // left rear out = mono in
+ {1} // right rear out = mono in
+ };
+
+
+ // you must initialize the array size correctly before getting the matrix!
+ float[,] matrixGet = new float[4,2];
+ BassMix.BASS_Mixer_ChannelGetMatrix(streamA, matrixGet);
+
+
+ ' you must initialize the array size correctly before getting the matrix!
+ Dim matrixGet(4, 2) As Single
+ BassMix.BASS_Mixer_ChannelGetMatrix(streamA, matrixGet)
+
+
+ float val = 0f;
+ int pos = BassMix.BASS_Mixer_ChannelGetEnvelope(source,
+ BASSMIXEnvelope.BASS_MIXER_ENV_VOL, ref val);
+ Console.WriteLine("Pos={0}, Val={1}", pos, val);
+
+
+ Dim val As Single = 0F
+ Dim pos As Integer = BassMix.BASS_Mixer_ChannelGetEnvelope(source,
+ BASSMIXEnvelope.BASS_MIXER_ENV_VOL, val)
+ Console.WriteLine("Pos={0}, Val={1}", pos, val)
+
+
+ int pos = BassMix.BASS_Mixer_ChannelGetEnvelope(source,
+ BASSMIXEnvelope.BASS_MIXER_ENV_VOL, null);
+ Console.WriteLine("Pos={0}", val);
+
+
+ Dim pos As Integer = BassMix.BASS_Mixer_ChannelGetEnvelope(source,
+ BASSMIXEnvelope.BASS_MIXER_ENV_VOL, Nothing)
+ Console.WriteLine("Pos={0}", pos)
+
+
+ // set a volume envelope on a source mixer channel (do this just once)
+ BASS_MIXER_NODE[] nodes =
+ {
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 3d), 1f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 5d), 0f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 7d), 0f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 9d), 1f)
+ };
+ BassMix.BASS_Mixer_ChannelSetEnvelope(source, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes);
+ ...
+
+ // change the source position and align the envelope position to it
+ // pause mixer
+ Bass.BASS_ChannelLock(mixer, true);
+ BassMix.BASS_Mixer_ChannelSetPosition(source, newPos);
+ // convert source pos to mixer pos
+ long envPos = Bass.BASS_ChannelSeconds2Bytes(mixer, Bass.BASS_ChannelBytes2Seconds(source, newPos));
+ BassMix.BASS_Mixer_ChannelSetEnvelopePos(source, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, envPos);
+ // resume mixer
+ Bass.BASS_ChannelLock(mixer, false);
+ ...
+
+
+ Dim nodes As BASS_MIXER_NODE() =
+ {
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 3.0), 1F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 5.0), 0F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 7.0), 0F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 9.0), 1F)
+ }
+ BassMix.BASS_Mixer_ChannelSetEnvelope(source, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes)
+ ...
+
+ ' change the source position and align the envelope position to it
+ ' pause mixer
+ Bass.BASS_ChannelLock(mixer, True)
+ BassMix.BASS_Mixer_ChannelSetPosition([source], newPos)
+ ' convert source pos to mixer pos
+ Dim envPos As Long = Bass.BASS_ChannelSeconds2Bytes(mixer, Bass.BASS_ChannelBytes2Seconds([source], newPos))
+ BassMix.BASS_Mixer_ChannelSetEnvelopePos([source], BASSMIXEnvelope.BASS_MIXER_ENV_VOL, envPos)
+ ' resume mixer
+ Bass.BASS_ChannelLock(mixer, False)
+ ...
+
+
+ BASS_MIXER_NODE[] nodes =
+ {
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 0d), 0f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 1d), -1f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 3d), 1f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 4d), 0f)
+ };
+ BassMix.BASS_Mixer_ChannelSetEnvelope(_channel, BASSMIXEnvelope.BASS_MIXER_ENV_PAN | BASSMIXEnvelope.BASS_MIXER_ENV_LOOP, nodes, 4);
+
+
+ Dim nodes As BASS_MIXER_NODE() =
+ {
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 0.0), 0F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 1.0), -1F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 3.0), 1F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 4.0), 0F)
+ }
+ BassMix.BASS_Mixer_ChannelSetEnvelope(_channel, BASSMIXEnvelope.BASS_MIXER_ENV_PAN | BASSMIXEnvelope.BASS_MIXER_ENV_LOOP, nodes, 4)
+
+ Remove any still available envelope nodes:
+
+ BassMix.BASS_Mixer_ChannelSetEnvelope(_channel, BASSMIXEnvelope.BASS_MIXER_ENV_PAN, null, 0);
+
+
+ BassMix.BASS_Mixer_ChannelSetEnvelope(_channel, BASSMIXEnvelope.BASS_MIXER_ENV_PAN, Nothing, 0)
+
+
+ BASS_MIXER_NODE[] nodes =
+ {
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 3d), 1f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 5d), 0.3f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 7d), 0.5f),
+ new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 9d), 1f)
+ };
+ BassMix.BASS_Mixer_ChannelSetEnvelope(_channel, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes);
+
+
+ Dim nodes As BASS_MIXER_NODE() =
+ {
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 3.0), 1F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 5.0), 0.3F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 7.0), 0.5F),
+ New BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 9.0), 1F)
+ }
+ BassMix.BASS_Mixer_ChannelSetEnvelope(_channel, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes)
+
+
+ int source = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE);
+ int reader1 = BassMix.BASS_Split_StreamCreate(source, BASSFlag.BASS_SAMPLE_FLOAT, null);
+ int reader2 = BassMix.BASS_Split_StreamCreate(source, BASSFlag.BASS_SAMPLE_FLOAT, null);
+ ...
+
+
+ Dim source As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE)
+ Dim reader1 As Integer = BassMix.BASS_Split_StreamCreate(source, BASSFlag.BASS_SAMPLE_FLOAT, Nothing)
+ Dim reader2 As Integer = BassMix.BASS_Split_StreamCreate(source, BASSFlag.BASS_SAMPLE_FLOAT, Nothing)
+ ...
+
+ Here are some more channel mapping examples...
+
+ // create a mono reader containing only the right channel based on a stereo source
+ int[] mapping = {1,-1};
+
+ // create a stereo reader which swaps the left and right channel of the stereo source
+ int[] mapping = {1,0,-1};
+
+ // create a quad-channel reader based on a stereo source
+ int[] mapping = {0,1,0,1,-1};
+
+ // create a sterao reader based on a mono source
+ int[] mapping = {0,0,-1};
+
+
+ // create a new splitter
+ int newsplit = BassMix.BASS_Split_StreamCreate(source, ...);
+ // get the amount of data an existing splitter has buffered
+ int offset = BassMix.BASS_Split_StreamGetAvailable(oldsplit);
+ // add the amount in its playback buffer
+ offset += BASS_ChannelGetData(oldsplit, null, BASSData.BASS_DATA_AVAILABLE);
+ // reset the new splitter to that far back in the source buffer
+ BassMix.BASS_Split_StreamResetEx(newsplit, offset);
+ // start playing it
+ Bass.BASS_ChannelPlay(newsplit, false);
+
+
+ ' create a new splitter
+ Dim newsplit As Integer = BassMix.BASS_Split_StreamCreate(source, 0)
+ ' get the amount of data an existing splitter has buffered
+ Dim offset As Integer = BassMix.BASS_Split_StreamGetAvailable(oldsplit)
+ ' add the amount in its playback buffer
+ offset += BASS_ChannelGetData(oldsplit, Nothing, BASSData.BASS_DATA_AVAILABLE)
+ ' reset the new splitter to that far back in the source buffer
+ BassMix.BASS_Split_StreamResetEx(newsplit, offset)
+ ' start playing it
+ Bass.BASS_ChannelPlay(newsplit, False)
+
+
+ Bass.LoadMe();
+ BassMix.LoadMe();
+ ...
+ // when not used anymore...
+ BassMix.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassMix.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassMix.FreeMe();
+ Bass.FreeMe();
+
+
+ BASS_MIDI_MARK mark = new BASS_MIDI_MARK();
+ int idx = 0;
+ while (BassMidi.BASS_MIDI_StreamGetMark(handle, BASSMIDIMarker.BASS_MIDI_MARK_MARKER, idx, mark))
+ {
+ idx++;
+ Console.WriteLine("{0}.Marker: {1}", idx, mark);
+ }
+
+
+ Dim mark As New BASS_MIDI_MARK()
+ Dim idx As Integer = 0
+ While BassMidi.BASS_MIDI_StreamGetMark(handle, BASSMIDIMarker.BASS_MIDI_MARK_MARKER, idx, mark)
+ idx += 1
+ Console.WriteLine("{0}.Marker: {1}", idx, mark)
+ End While
+
+
+ int idx = 0;
+ BASS_MIDI_MARK mark;
+ while ((mark = BassMidi.BASS_MIDI_StreamGetMark(handle, BASSMIDIMarker.BASS_MIDI_MARK_MARKER, idx)) != null)
+ {
+ idx++;
+ Console.WriteLine("{0}.Marker: {1}", idx, mark);
+ }
+
+
+ Dim idx As Integer = 0
+ Dim mark As BASS_MIDI_MARK
+ While True
+ mark = BassMidi.BASS_MIDI_StreamGetMark(stream, BASSMIDIMarker.BASS_MIDI_MARK_MARKER, idx)
+ If mark Is Nothing Then
+ Exit While
+ End If
+ idx += 1
+ Console.WriteLine("{0}.Marker: {1}", idx, mark)
+ End While
+
+
+ // press the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60, 100);
+ // wait 2 seconds
+ Thread.Sleep(2000);
+ // release the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60);
+
+
+ ' press the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60, 100)
+ ' wait 2 seconds
+ Thread.Sleep(2000)
+ ' release the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60)
+
+
+ // press the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60, 100);
+ // wait 2 seconds
+ Thread.Sleep(2000);
+ // release the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60);
+
+
+ ' press the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60, 100)
+ ' wait 2 seconds
+ Thread.Sleep(2000)
+ ' release the key
+ BassMidi.BASS_MIDI_StreamEvent(handle, 0, BASSMIDIEvent.MIDI_EVENT_NOTE, 60)
+
+
+ int eventCount = BassMidi.BASS_MIDI_StreamGetEvents(_stream, 0, BASSMIDIEvent.MIDI_EVENT_NONE);
+ BASS_MIDI_EVENT[] events = new BASS_MIDI_EVENT[eventCount];
+ int count = BassMidi.BASS_MIDI_StreamGetEvents(_stream, 0, BASSMIDIEvent.MIDI_EVENT_NONE, events);
+
+
+ Dim eventCount = BassMidi.BASS_MIDI_StreamGetEvents(_stream, 0, BASSMIDIEvent.MIDI_EVENT_NONE)
+ Dim events(eventCount) As BASS_MIDI_EVENT
+ Dim count As Integer = BassMidi.BASS_MIDI_StreamGetEvents(_stream, 0, BASSMIDIEvent.MIDI_EVENT_NONE, events)
+
+
+ BASS_MIDI_EVENT[] events = BassMidi.BASS_MIDI_StreamGetEvents(_stream, 1, BASSMIDIEvent.MIDI_EVENT_NOTE);
+
+
+ Dim events As BASS_MIDI_EVENT() = BassMidi.BASS_MIDI_StreamGetEvents(_stream, 1, BASSMIDIEvent.MIDI_EVENT_NOTE)
+
+
+ // first initialize the fonts
+ int font1 = BassMidi.BASS_MIDI_FontInit("afont.sf2");
+ int font2 = BassMidi.BASS_MIDI_FontInit("bfont.sf2");
+ BASS_MIDI_FONT[] newfonts = { new BASS_MIDI_FONT(font1, -1, 0), new BASS_MIDI_FONT(font2, -1, 0) };
+ // now set them
+ BassMidi.BASS_MIDI_StreamSetFonts(_stream, newfonts, newfonts.Length);
+
+
+ ' first initialize the fonts
+ Dim font1 As Integer = BassMidi.BASS_MIDI_FontInit("afont.sf2")
+ Dim font2 As Integer = BassMidi.BASS_MIDI_FontInit("bfont.sf2")
+ Dim newFonts() As BASS_MIDI_FONT = {New BASS_MIDI_FONT(font1, -1, 0), New BASS_MIDI_FONT(font2, -1, 0)}
+ ' now set them
+ BassMidi.BASS_MIDI_StreamSetFonts(_stream, newFonts, newFonts.Length)
+
+
+ int fontCount = BassMidi.BASS_MIDI_StreamGetFontsCount(_stream);
+ BASS_MIDI_FONT[] fonts = new BASS_MIDI_FONT[fontCount];
+ int count = BassMidi.BASS_MIDI_StreamGetFonts(_stream, fonts, fontCount);
+
+
+ Dim fontCount As Integer = BassMidi.BASS_MIDI_StreamGetFontsCount(_stream)
+ Dim fonts(fontCount) As BASS_MIDI_FONT
+ Dim count As Integer = BassMidi.BASS_MIDI_StreamGetFonts(_stream, fonts, fontCount)
+
+
+ BASS_MIDI_FONT[] fonts = BassMidi.BASS_MIDI_StreamGetFonts(_stream);
+
+
+ Dim fonts As BASS_MIDI_FONT() = BassMidi.BASS_MIDI_StreamGetFonts(_stream)
+
+
+ // get a stream for MIDI channel 1
+ int chan1 = BassMidi.BASS_MIDI_StreamGetChannel(midi, 0);
+ // set the DX8 distortion effect on it
+ int fx = Bass.BASS_ChannelSetFX(chan1, BASSFXType.BASS_FX_DX8_DISTORTION, 0);
+
+
+ ' get a stream for MIDI channel 1
+ Dim chan1 As Integer = BassMidi.BASS_MIDI_StreamGetChannel(midi, 0)
+ ' set the DX8 distortion effect on it
+ Dim chan1 As Integer = Bass.BASS_ChannelSetFX(chan1, BASSFXType.BASS_FX_DX8_DISTORTION, 0)
+
+
+ // first initialize the fonts
+ int font1 = BassMidi.BASS_MIDI_FontInit("afont.sf2");
+ int font2 = BassMidi.BASS_MIDI_FontInit("bfont.sf2");
+ BASS_MIDI_FONT[] newfonts = new BASS_MIDI_FONT[2];
+ newfonts[0] = new BASS_MIDI_FONT(font1, 10, 0);
+ newfonts[1] = new BASS_MIDI_FONT(font2, -1, 0);
+ // now set them
+ BassMidi.BASS_MIDI_StreamSetFonts(_stream, newfonts, 2);
+
+
+ ' first initialize the fonts
+ Dim font1 As Integer = BassMidi.BASS_MIDI_FontInit("afont.sf2")
+ Dim font2 As Integer = BassMidi.BASS_MIDI_FontInit("bfont.sf2")
+ Dim newfonts(2) As BASS_MIDI_FONT
+ newfonts(0) = New BASS_MIDI_FONT(font1, 10, 0)
+ newfonts(1) = New BASS_MIDI_FONT(font2, -1, 0)
+ BassMidi.BASS_MIDI_StreamSetFonts(_stream, newfonts, 2)
+
+
+ int font1 = BassMidi.BASS_MIDI_FontInit("afont.sf2");
+ BASS_MIDI_FONTINFO fontInfo = new BASS_MIDI_FONTINFO();
+ BassMidi.BASS_MIDI_FontGetInfo(font1, fontInfo);
+ Console.WriteLine( fontInfo.ToString() );
+
+
+ Dim font1 As Integer = BassMidi.BASS_MIDI_FontInit("afont.sf2")
+ Dim fontInfo As New BASS_MIDI_FONTINFO()
+ BassMidi.BASS_MIDI_FontGetInfo(font1, fontInfo)
+ Console.WriteLine(fontInfo.ToString())
+
+
+ // open original soundfont
+ int handle = BassMidi.BASS_MIDI_FontInit( "afile.sf2");
+ // produce packed version
+ BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", "flac --best -");
+
+
+ ' open original soundfont
+ Dim handle As Integer = BassMidi.BASS_MIDI_FontInit("afile.sf2")
+ ' produce packed version
+ BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", "flac --best -")
+
+ Using the build-in encoder framework:
+
+ EncoderFLAC flac = new EncoderFLAC(0);
+ flac.InputFile = null; // use STDIN
+ flac.OutputFile = null; // use STDOUT
+ // produce packed version
+ BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", flac.EncoderCommandLine);
+
+
+ Dim flac As New EncoderFLAC(0)
+ flac.InputFile = Nothing ' use STDIN
+ flac.OutputFile = Nothing ' use STDOUT
+ ' produce packed version
+ BassMidi.BASS_MIDI_FontPack(handle, "afile.sf2pack", flac.EncoderCommandLine)
+
+
+ // load FLAC plugin
+ Bass.BASS_PluginLoad("bassflac.dll");
+ // open soundfont
+ int handle = BassMidi.BASS_MIDI_FontInit("afile.sf2pack");
+ // produce unpacked version
+ BassMidi.BASS_MIDI_FontUnpack(handle, "afile.sf2");
+
+
+ ' load FLAC plugin
+ Bass.BASS_PluginLoad("bassflac.dll")
+ ' open soundfont
+ Dim handle As Integer = BassMidi.BASS_MIDI_FontInit("afile.sf2pack")
+ ' produce unpacked version
+ BassMidi.BASS_MIDI_FontUnpack(handle, "afile.sf2")
+
+
+ Bass.LoadMe();
+ BassMidi.LoadMe();
+ ...
+ // when not used anymore...
+ BassMidi.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassMidi.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassMidi.FreeMe();
+ Bass.FreeMe();
+
+
+ private MIDIINPROC _midiProc;
+ private int _midiStream;
+ ...
+ // create a MIDI input callback delegate
+ _midiProc = new MIDIINPROC(MyMidiInProc);
+ BassMidi.BASS_MIDI_InInit(0, _midiProc, IntPtr.Zero);
+ ...
+ // create a MIDI stream to play the MIDI data
+ _midiStream = BassMidi.BASS_MIDI_StreamCreate(16, BASSFlag.BASS_DEFAULT, 44100);
+ ...
+ private void MyMidiInProc(int device, double time, IntPtr buffer, int length, IntPtr user)
+ {
+ // forward the data to the MIDI stream
+ BassMidi.BASS_MIDI_StreamEvents(_midiStream, BASSMIDIEventMode.BASS_MIDI_EVENTS_NONE, 0, buffer, length);
+ }
+
+
+ Private _midiProc As MIDIINPROC
+ Private _midiStream As Integer
+ ...
+ ' create a MIDI input callback delegate
+ _midiProc = New MIDIINPROC(AddressOf MyMidiInProc)
+ BassMidi.BASS_MIDI_InInit(0, _midiProc, IntPtr.Zero);
+ ...
+ ' create a MIDI input callback delegate
+ _midiStream = BassMidi.BASS_MIDI_StreamCreate(16, BASSFlag.BASS_DEFAULT, 44100)
+ ...
+ Private Procedure MyMidiInProc(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr)
+ ' forward the data to the MIDI stream
+ BassMidi.BASS_MIDI_StreamEvents(_midiStream, BASSMIDIEventMode.BASS_MIDI_EVENTS_NONE, 0, buffer, length)
+ End Procedure
+
+
+ if ( Utils.HighWord(BassEnc.BASS_Encode_GetVersion()) != BassEnc.BASSENCVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassEnc Version!");
+ }
+
+
+ If Utils.HighWord(BassEnc.BASS_Encode_GetVersion()) <> BassEnc.BASSENCVERSION Then
+ MessageBox.Show(Me, "Wrong BassEnc Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassEnc.BASS_Encode_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassEnc Version!");
+ }
+
+
+ If BassEnc.BASS_Encode_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassEnc Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassEnc.BASS_Encode_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassEnc Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassEnc.BASS_Encode_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassEnc Version!")
+ End If
+
+
+ BassEnc.BASS_Encode_Start(channel, "lame --alt-preset standard - output.mp3",
+ 0, null, IntPtr.Zero);
+ // start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, false);
+
+
+ BassEnc.BASS_Encode_Start(channel, "lame --alt-preset standard - output.mp3",
+ 0, Nothing, IntPtr.Zero)
+ ' start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, False)
+
+ Start writing a channel to a WAV file (output.wav):
+
+ BassEnc.BASS_Encode_Start(channel, "output.wav",
+ BASSEncode.BASS_ENCODE_PCM, null, IntPtr.Zero);
+ // start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, false);
+
+
+ BassEnc.BASS_Encode_Start(channel, "output.wav",
+ BASSEncode.BASS_ENCODE_PCM, Nothing, IntPtr.Zero)
+ ' start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, False)
+
+
+ BassEnc.BASS_Encode_Start(channel, "lame --alt-preset standard - output.mp3",
+ 0, null, IntPtr.Zero);
+ // start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, false);
+
+
+ BassEnc.BASS_Encode_Start(channel, "lame --alt-preset standard - output.mp3",
+ 0, Nothing, IntPtr.Zero)
+ ' start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, False)
+
+ Start writing a channel to a WAV file (output.wav):
+
+ BassEnc.BASS_Encode_Start(channel, "output.wav",
+ BASSEncode.BASS_ENCODE_PCM, null, IntPtr.Zero);
+ // start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, false);
+
+
+ BassEnc.BASS_Encode_Start(channel, "output.wav",
+ BASSEncode.BASS_ENCODE_PCM, Nothing, IntPtr.Zero)
+ ' start the channel playing & encoding
+ Bass.BASS_ChannelPlay(channel, False)
+
+
+ BASS_TAG_BEXT bext = new BASS_TAG_BEXT();
+ ... set the bext member here
+ string codingHistory = "...";
+ byte[] bextData = bext.AsByteArray(codingHistory);
+ bool ok = BassEnc.BASS_Encode_AddChunk(handle, "bext", bextData, bextData.Length);
+
+
+ private bool RecordingCallback(int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // continue recording if encoder is alive
+ return ( BassEnc.BASS_Encode_IsActive(channel) != BASSActive.BASS_ACTIVE_STOPPED );
+ }
+
+
+ Private Function RecordingCallback(channel As Integer, buffer As IntPtr,
+ length As Integer, user As IntPtr) As Boolean
+ ' continue recording if encoder is alive
+ Return BassEnc.BASS_Encode_IsActive(channel) <> BASSActive.BASS_ACTIVE_STOPPED
+ End Function
+
+
+ // get suggested (maximum) format buffer size
+ int formlen = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, null, BASSACMFormat.BASS_ACM_NONE);
+ // create a buffer for the codec
+ byte[] buffer = new byte[formlen];
+ // now create a pinned handle, so that the Garbage Collector will not move this object
+ GCHandle hGC = GCHandle.Alloc( buffer, GCHandleType.Pinned );
+ // get the pointer to that pinned object
+ IntPtr codec = hGC.AddrOfPinnedObject();
+ // let the user choose a codec...
+ if ( BassEnc.BASS_Encode_GetACMFormat( channel, codec, formlen, "Choose your format", BASSACMFormat.BASS_ACM_DEFAULT) > 0 )
+ {
+ // get the generic codec information back
+ ACMFORMAT acm = (ACMFORMAT)Marshal.PtrToStructure(codec, typeof(ACMFORMAT));
+ // begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile( channel, codec, BASSEncode.BASS_ENCODE_DEFAULT, "acm.wav");
+ }
+ // free the codec format buffer (you might free it even if encoding is still running)
+ hGC.Free();
+
+
+ ' get suggested (maximum) format buffer size
+ Dim formlen As Integer = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, Nothing, BASSACMFormat.BASS_ACM_NONE)
+ ' create a buffer for the codec
+ Dim buffer(formlen - 1) As Byte
+ ' now create a pinned handle, so that the Garbage Collector will not move this object
+ Dim hGC As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
+ ' get the pointer to that pinned object
+ Dim codec As IntPtr = hGC.AddrOfPinnedObject()
+ ' let the user choose a codec...
+ If BassEnc.BASS_Encode_GetACMFormat(channel, codec, formlen, "Choose your format",
+ BASSACMFormat.BASS_ACM_DEFAULT) > 0 Then
+ ' get the generic codec information back
+ Dim acm As ACMFORMAT = CType(Marshal.PtrToStructure(codec, GetType(ACMFORMAT)), ACMFORMAT)
+ ' begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile(channel, codec, BASSEncode.BASS_ENCODE_DEFAULT, "acm.wav")
+ End If
+ ' free the codec format buffer (you might free it even if encoding is still running)
+ hGC.Free()
+
+ If you are into C# using native pointers in an unsafe codeblock would be even faster:
+
+ // get suggested (maximum) format buffer size
+ int formlen = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, null, BASSACMFormat.BASS_ACM_NONE);
+ // create a buffer for the codec
+ byte[] buffer = new byte[formlen];
+ unsafe
+ {
+ fixed (byte* p = buffer)
+ {
+ // let the user choose a codec...
+ if ( BassEnc.BASS_Encode_GetACMFormat( channel, (IntPtr)p, formlen, "Choose your format", BASSACMFormat.BASS_ACM_DEFAULT) > 0 )
+ {
+ // get the generic codec information back
+ ACMFORMAT acm = (ACMFORMAT)Marshal.PtrToStructure((IntPtr)p, typeof(ACMFORMAT));
+ // begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile( channel, acm, BASSEncode.BASS_ENCODE_DEFAULT, "acm.wav");
+ }
+ }
+ }
+
+ For more convenience use the other overload of
+ ACMFORMAT codec = BassEnc.BASS_Encode_GetACMFormat(channel, "Select your encoder",
+ BASSACMFormat.BASS_ACM_DEFAULT,
+ WAVEFormatTag.UNKNOWN);
+ if ( codec != null )
+ {
+ // begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile( channel, codec, BASSEncode.BASS_ENCODE_DEFAULT, "acm.wav");
+ }
+
+
+ Dim codec As ACMFORMAT = BassEnc.BASS_Encode_GetACMFormat(channel, "Select your encoder",
+ BASSACMFormat.BASS_ACM_DEFAULT,
+ WAVEFormatTag.UNKNOWN)
+ If Not (codec Is Nothing) Then
+ ' begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile(channel, codec, BASSEncode.BASS_ENCODE_DEFAULT, "acm.wav")
+ End If
+
+
+ ACMFORMAT codec = BassEnc.BASS_Encode_GetACMFormatSuggest(channel,
+ BASSACMFormat.BASS_ACM_CHANS | BASSACMFormat.BASS_ACM_RATE,
+ WAVEFormatTag.MPEGLAYER3);
+ if ( codec != null )
+ {
+ // begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile( channel, codec, BASSEncode.BASS_ENCODE_DEFAULT, "acm.mp3");
+ }
+
+
+ Dim codec As ACMFORMAT = BassEnc.BASS_Encode_GetACMFormatSuggest(channel,
+ BASSACMFormat.BASS_ACM_CHANS Or BASSACMFormat.BASS_ACM_RATE,
+ WAVEFormatTag.MPEGLAYER3)
+ If Not (codec Is Nothing) Then
+ ' begin encoding using the codec
+ BassEnc.BASS_Encode_StartACMFile(channel, codec, BASSEncode.BASS_ENCODE_DEFAULT, "acm.mp3")
+ End If
+
+
+ // the encoding callback
+ private ENCODEPROC _myEncProc;
+ private byte[] _encbuffer = null;
+ ...
+ ACMFORMAT codec = BassEnc.BASS_Encode_GetACMFormat(channel, "Select your encoder",
+ BASSACMFormat.BASS_ACM_DEFAULT, WAVEFormatTag.UNKNOWN);
+ if ( codec != null )
+ {
+ // create the delegate
+ _myEncProc = new ENCODEPROC(MyEncoderProc);
+ // begin encoding using the codec with the delegate callback
+ int encHandle = BassEnc.BASS_Encode_StartACM( channel, codec,
+ BASSEncode.BASS_ENCODE_DEFAULT, _myEncProc, IntPtr.Zero);
+ }
+ ...
+ private bool MyEncodingWriter(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // dynamic buffer allocation
+ if ( _encbuffer == null || _encbuffer.Length < length )
+ _encbuffer = new byte[length];
+
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _encbuffer, 0, length);
+ // process the data in _encbuffer, e.g. write to disk or whatever
+ ...
+ }
+
+
+ Private _myEncProc As ENCODEPROC
+ Private _encbuffer As Byte() = Nothing
+ ...
+ Dim codec As ACMFORMAT = BassEnc.BASS_Encode_GetACMFormat(channel, "Select your encoder",
+ BASSACMFormat.BASS_ACM_DEFAULT, WAVEFormatTag.UNKNOWN)
+ If Not (codec Is Nothing) Then
+ ' create the delegate
+ _myEncProc = New ENCODEPROC(AddressOf MyEncoderProc)
+ ' begin encoding using the codec with the delegate callback
+ Dim encHandle As Integer = BassEnc.BASS_Encode_StartACM(channel, codec,
+ BASSEncode.BASS_ENCODE_DEFAULT, _myEncProc, IntPtr.Zero)
+ End If
+ ...
+ Private Function MyEncodingWriter(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ ' dynamic buffer allocation
+ If _encbuffer Is Nothing OrElse _encbuffer.Length < length Then
+ _encbuffer = New Byte(length) {}
+ End If
+
+ ' copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _encbuffer, 0, length)
+ ' process the data in _encbuffer, e.g. write to disk or whatever
+ ...
+ End Function
+
+ If you are into C# you might also use native pointer access in an unsafe codeblock:
+
+ private unsafe void MyEncoding(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // here we receive the encoded data back.
+ // the encoded data is a kind of raw byte buffer...
+ byte *data = (byte*)buffer;
+
+ for (int a=0; a<length; a++)
+ {
+ // do whatever you want with the encoded data
+ _stream.WriteByte( data[a] );
+ }
+ }
+
+
+ // get suggested (maximum) format buffer size
+ int formlen = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, null, BASSACMFormat.BASS_ACM_NONE);
+ // create a buffer for the codec
+ byte[] buffer = new byte[formlen];
+ unsafe
+ {
+ fixed (byte* p = buffer)
+ {
+ // let the user choose a codec...
+ if ( BassEnc.BASS_Encode_GetACMFormat( channel, (IntPtr)p, formlen, "Choose your format",
+ BASSACMFormat.BASS_ACM_DEFAULT) > 0 )
+ {
+ // create the delegate
+ _myEncProc = new ENCODEPROC(MyEncoderProc);
+ // begin encoding using the codec with the delegate callback
+ int encHandle = BassEnc.BASS_Encode_StartACMFile(channel, (IntPtr)p, BASSEncode.BASS_ENCODE_DEFAULT, _myEncProc, IntPtr.Zero);
+ }
+ }
+ }
+ ...
+ // the encoding callback
+ private ENCODEPROC _myEncProc; // keep the callback delegate in a global member
+ private bool MyEncodingWriter(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ ...
+ }
+
+
+ ' get suggested (maximum) format buffer size
+ Dim formlen As Integer = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, Nothing, BASSACMFormat.BASS_ACM_NONE)
+ ' create a buffer for the codec
+ Dim buffer(formlen - 1) As Byte
+ ' now create a pinned handle, so that the Garbage Collector will not move this object
+ Dim hGC As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
+ ' get the pointer to that pinned object
+ Dim codec As IntPtr = hGC.AddrOfPinnedObject()
+ ' let the user choose a codec...
+ If BassEnc.BASS_Encode_GetACMFormat(channel, codec, formlen, "Choose your format",
+ BASSACMFormat.BASS_ACM_DEFAULT) > 0 Then
+ ' create the delegate
+ _myEncProc = New ENCODEPROC(AddressOf MyEncoderProc)
+ ' begin encoding using the codec with the delegate callback
+ Dim encHandle As Integer = BassEnc.BASS_Encode_StartACMFile(channel, codec,
+ BASSEncode.BASS_ENCODE_DEFAULT, _myEncProc, IntPtr.Zero)
+ End If
+ ' free the codec format buffer (you might free it even if encoding is still running)
+ hGC.Free()
+ ...
+ Private _myEncProc As ENCODEPROC
+ Private Function MyEncodingWriter(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ ...
+ End Function
+
+ If you are into C# using native pointers in an unsafe codeblock would be even faster:
+
+ // get suggested (maximum) format buffer size
+ int formlen = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, null, BASSACMFormat.BASS_ACM_NONE);
+ // create a buffer for the codec
+ byte[] form = new byte[formlen];
+ unsafe
+ {
+ fixed (byte* p = form)
+ {
+ // automatically suggest an MP3 codec
+ if (BassEnc.BASS_Encode_GetACMFormat(handle, (IntPtr)p, formlen, null,
+ (BASSACMFormat)Utils.MakeLong((int)(BASSACMFormat.BASS_ACM_SUGGEST | BASSACMFormat.BASS_ACM_RATE | BASSACMFormat.BASS_ACM_CHANS),
+ (int)WAVEFormatTag.MPEGLAYER3)) > 0)
+ {
+ // begin encoding
+ int encHandle = BassEnc.BASS_Encode_StartACMFile(channel, (IntPtr)p,
+ BASSEncode.BASS_ENCODE_NOHEAD, "output.mp3" );
+ }
+
+
+ ' get suggested (maximum) format buffer size
+ Dim formlen As Integer = BassEnc.BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, Nothing, BASSACMFormat.BASS_ACM_NONE)
+ ' create a buffer for the codec
+ Dim buffer(formlen - 1) As Byte
+ ' now create a pinned handle, so that the Garbage Collector will not move this object
+ Dim hGC As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
+ ' get the pointer to that pinned object
+ Dim codec As IntPtr = hGC.AddrOfPinnedObject()
+ ' automatically suggest an MP3 codec
+ If BassEnc.BASS_Encode_GetACMFormat(handle, codec, formlen, Nothing,
+ CType(Utils.MakeLong(CInt(BASSACMFormat.BASS_ACM_SUGGEST Or BASSACMFormat.BASS_ACM_RATE Or BASSACMFormat.BASS_ACM_CHANS),
+ CInt(WAVEFormatTag.MPEGLAYER3)), BASSACMFormat)) > 0 Then
+ ' begin encoding
+ Dim encHandle As Integer = BassEnc.BASS_Encode_StartACMFile(channel, codec,
+ BASSEncode.BASS_ENCODE_NOHEAD, "output.mp3")
+ End If
+ ' free the codec format buffer (you might free it even if encoding is still running)
+ hGC.Free()
+
+
+ ACMFORMAT codec = BassEnc.BASS_Encode_GetACMFormat(channel, "Select your encoder",
+ BASSACMFormat.BASS_ACM_DEFAULT, WAVEFormatTag.UNKNOWN);
+ if ( codec != null )
+ {
+ // begin encoding
+ int encHandle = BassEnc.BASS_Encode_StartACMFile( channel, codec,
+ BASSEncode.BASS_ENCODE_DEFAULT, "output.wav" );
+ }
+
+
+ Dim codec As ACMFORMAT = BassEnc.BASS_Encode_GetACMFormat(channel, "Select your encoder",
+ BASSACMFormat.BASS_ACM_DEFAULT, WAVEFormatTag.UNKNOWN)
+ If Not (codec Is Nothing) Then
+ ' begin encoding
+ Dim encHandle As Integer = BassEnc.BASS_Encode_StartACMFile(channel, codec,
+ BASSEncode.BASS_ENCODE_DEFAULT, "output.wav")
+ End If
+
+
+ private ENCODENOTIFYPROC _myEndoderNotify;
+ private int _encoder = 0;
+ private int _recChan = 0;
+ private bool _autoreconnect = true;
+ ...
+ _recChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, null, IntPtr.Zero);
+ Start();
+ ...
+ private void Start()
+ {
+ // start an encoder
+ _encoder = BassEnc.BASS_Encode_Start(_recChan, "lame -r -x -s 44100 -b 128 -",
+ BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
+ _myEndoderNotify = new ENCODENOTIFYPROC(EncoderNotify);
+ // start a caster
+ BassEnc.BASS_Encode_CastInit(_encoder, "server.com:8000", "password",
+ BassEnc.BASS_ENCODE_TYPE_MP3, "name", "url", "genre", null, null, 128, true);
+ // notify on dead encoder/connection
+ BassEnc.BASS_Encode_SetNotify(_encoder, _myEndoderNotify, IntPtr.Zero);
+ }
+
+ private void Stop()
+ {
+ if (_encoder != 0)
+ {
+ BassEnc.BASS_Encode_SetNotify(_encoder, null, IntPtr.Zero);
+ BassEnc.BASS_Encode_Stop(_encoder);
+ _encoder = 0;
+ }
+ }
+
+ private void EncoderNotify(int handle, int status, IntPtr user)
+ {
+ // encoder/connection lost
+ Stop();
+ if (_autoreconnect)
+ {
+ // do auto-reconnect...
+ Thread.Sleep(1000); // wait a sec
+ Start();
+ }
+ }
+
+
+ Private _myEndoderNotify As ENCODENOTIFYPROC
+ Private _encoder As Integer = 0
+ Private _recChan As Integer = 0
+ Private _autoreconnect As Boolean = True
+ ...
+ _recChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, Nothing, IntPtr.Zero)
+ Start()
+ ...
+ Private Sub Start()
+ ' start an encoder
+ _encoder = BassEnc.BASS_Encode_Start(_recChan, "lame -r -x -s 44100 -b 128 -",
+ BASSEncode.BASS_ENCODE_NOHEAD, Nothing, IntPtr.Zero)
+ _myEndoderNotify = New ENCODENOTIFYPROC(AddressOf EncoderNotify)
+ ' start a caster
+ BassEnc.BASS_Encode_CastInit(_encoder, "server.com:8000", "password",
+ Bass.BASS_ENCODE_TYPE_MP3, "name", "url", "genre", Nothing, Nothing, 128, True)
+ ' notify on dead encoder/connection
+ BassEnc.BASS_Encode_SetNotify(_encoder, _myEndoderNotify, IntPtr.Zero)
+ End Sub
+
+ Private Sub Stop()
+ If _encoder <> 0 Then
+ BassEnc.BASS_Encode_SetNotify(_encoder, Nothing, IntPtr.Zero)
+ BassEnc.BASS_Encode_Stop(_encoder)
+ _encoder = 0
+ End If
+ End Sub
+
+ Private Sub EncoderNotify(handle As Integer, status As Integer, user As IntPtr)
+ ' encoder/connection lost
+ Stop()
+ If _autoreconnect Then
+ ' do auto-reconnect...
+ Thread.Sleep(1000) ' wait a sec
+ Start()
+ End If
+ End Sub
+
+
+ // setup the encoder
+ int encoder = BassEnc.BASS_Encode_Start(channel, "lame -r -x -s 44100 -b 128 -",
+ BASS_ENCODE_NOHEAD, null, 0);
+ // setup the encoder
+ BassEnc.BASS_Encode_CastInit(encoder, "server.com:8000", "password", BassEnc.BASS_ENCODE_TYPE_MP3,
+ "name", "url", "genre", null, null, 128, true);
+
+
+ ' setup the encoder
+ Dim encoder As Integer = BassEnc.BASS_Encode_Start(channel, "lame -r -x -s 44100 -b 128 -",
+ BASS_ENCODE_NOHEAD, Nothing, 0)
+ ' setup the encoder
+ BassEnc.BASS_Encode_CastInit(encoder, "server.com:8000", "password", BassEnc.BASS_ENCODE_TYPE_MP3,
+ "name", "url", "genre", Nothing, Nothing, 128, True)
+
+
+ Encoding utf8 = Encoding.UTF8;
+ BassEnc.BASS_Encode_CastSetTitle(encoder, utf8.GetBytes(song+"\0"), null);
+
+
+ Dim utf8 As Encoding = Encoding.UTF8
+ BassEnc.BASS_Encode_CastSetTitle(encoder, utf8.GetBytes(song+"\0"), Nothing)
+
+
+ string stats = BassEnc.BASS_Encode_CastGetStats(encoder,
+ BASSEncodeStats.BASS_ENCODE_STATS_SHOUT, password);
+ if (stats != null)
+ {
+ int start = stats.IndexOf( "<CURRENTLISTENERS>" );
+ int end = stats.IndexOf( "</CURRENTLISTENERS>" );
+ if (start > 0 && end > 0)
+ {
+ start += 18;
+ count = int.Parse( stats.Substring(start, end-start) );
+ }
+ }
+
+
+ Dim stats As String = BassEnc.BASS_Encode_CastGetStats(encoder,
+ BASSEncodeStats.BASS_ENCODE_STATS_SHOUT, password)
+ If Not (stats Is Nothing) Then
+ Dim start As Integer = stats.IndexOf("<CURRENTLISTENERS>")
+ Dim [end] As Integer = stats.IndexOf("</CURRENTLISTENERS>")
+ If start > 0 AndAlso end > 0 Then
+ start += 18
+ count = Integer.Parse(stats.Substring(start, end - start))
+ End If
+ End If
+
+
+ // setup the encoder
+ int encoder = BassEnc.BASS_Encode_Start(channel, "lame -r -s 44100 -b 128 -",
+ BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
+ // start the server
+ BassEnc.BASS_Encode_ServerInit(encoder, "8000", 64000, 64000,
+ BASSEncodeServer.BASS_ENCODE_SERVER_DEFAULT, null, IntPtr.Zero);
+
+ Start encoding a stereo 44100Hz channel to 160kb/s OGG, and start a server on any available port on the loopback address (127.0.0.1) with a fully burstable 2 second (40KB) buffer:
+
+ // setup the encoder
+ int encoder = BassEnc.BASS_Encode_Start(channel, "oggenc -r -R 44100 -M 160 -m 160 -",
+ BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
+ // start the server
+ BassEnc.BASS_Encode_ServerInit(encoder, "127.0.0.1", 40000, 40000,
+ BASSEncodeServer.BASS_ENCODE_SERVER_DEFAULT, null, IntPtr.Zero);
+
+ Setup PCM encoding on a dummy stream to feed pre-encoded data to a server on port 8000 with a 64KB buffer:
+
+ // create a dummy stream to host the encoder
+ int dummy = Bass.BASS_StreamCreateDummy(44100, 1, BASSFlag.BASS_STREAM_DECODE, IntPtr.Zero);
+ // setup the encoder
+ int encoder = BassEnc.BASS_Encode_Start(dummy, null,
+ BASSEncode.BASS_ENCODE_PCM | BASSEncode.BASS_ENCODE_NOHEAD,
+ null, IntPtr.Zero);
+ // start the server
+ int port = BassEnc.BASS_Encode_ServerInit(encoder, "8000", 64000, 64000,
+ BASSEncodeServer.BASS_ENCODE_SERVER_DEFAULT, null, IntPtr.Zero);
+ ...
+ // feed encoded data to the encoder/server (repeat periodically)
+ BassEnc.BASS_Encode_Write(encoder, data, length);
+
+
+ Bass.LoadMe();
+ BassEnc.LoadMe();
+ ...
+ // when not used anymore...
+ BassEnc.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassEnc.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassEnc.FreeMe();
+ Bass.FreeMe();
+
+
+ ACMFORMAT codec = null;
+ // get the maximum codec format length
+ int formlen = BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, null, BASSACMFormat.BASS_ACM_NONE);
+ byte[] buffer = new byte[formlen];
+ GCHandle hGC = GCHandle.Alloc( buffer, GCHandleType.Pinned );
+ try
+ {
+ IntPtr codecPtr = hGC.AddrOfPinnedObject();
+ if ( BassEnc.BASS_Encode_GetACMFormat( handle, codecPtr, formlen, title, flags) > 0 )
+ {
+ codec = new ACMFORMAT(codecPtr);
+ }
+ }
+ catch { codec = null; }
+ finally
+ {
+ hGC.Free();
+ }
+
+
+ Dim codec As ACMFORMAT = Nothing
+ ' get the maximum codec format length
+ Dim formlen As Integer = BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, Nothing, BASSACMFormat.BASS_ACM_NONE)
+ Dim buffer(formlen - 1) As Byte
+ Dim hGC As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
+ Try
+ Dim codecPtr As IntPtr = hGC.AddrOfPinnedObject()
+ If BassEnc.BASS_Encode_GetACMFormat(handle, codecPtr, formlen, title, flags) > 0 Then
+ codec = New ACMFORMAT(codecPtr)
+ End If
+ Catch
+ codec = Nothing
+ Finally
+ hGC.Free()
+ End Try
+
+ If you are into C# you might also use native pointers in an unsafe codeblock:
+
+ ACMFORMAT codec = null;
+ // get the maximum codec format length
+ int formlen = BASS_Encode_GetACMFormat(0, IntPtr.Zero, 0, null, BASSACMFormat.BASS_ACM_NONE);
+ byte[] buffer = new byte[formlen];
+ unsafe
+ {
+ fixed (byte* p = buffer)
+ {
+ if ( BassEnc.BASS_Encode_GetACMFormat( handle, (IntPtr)p, formlen, title, flags) > 0 )
+ {
+ codec = new ACMFORMAT((IntPtr)p);
+ }
+ }
+ }
+
+
+ // the encoding callback
+ private ENCODEPROC _myEndoderProc;
+ private byte[] _encbuffer = new byte[1048510]; // 1MB buffer
+ ...
+ _myEndoderProc = new ENCODEPROC(MyEncodingWriter);
+ // create the encoder (with default setting for lame)
+ BassEnc.BASS_Encode_Start(channel, "lame --alt-preset standard",
+ BASSEncode.BASS_ENCODE_DEFAULT, _myEndoderProc, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(channel, false); // start the channel playing & encoding
+ ...
+ private bool MyEncodingWriter(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _encbuffer, 0, length);
+ // process the data in _encbuffer, e.g. write to disk or whatever
+ ...
+ }
+
+
+ Private _myEndoderProc As ENCODEPROC
+ Private _encbuffer(1048510) As Byte ' 1MB buffer
+ ...
+ _myEndoderProc = New ENCODEPROC(AddressOf MyEncodingWriter)
+ ' create the encoder (with default setting for lame)
+ BassEnc.BASS_Encode_Start(channel, "lame --alt-preset standard",
+ BASSEncode.BASS_ENCODE_DEFAULT, _myEndoderProc, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(channel, False)
+ ' start the channel playing & encoding
+ Private Function MyEncodingWriter(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ ' copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _encbuffer, 0, length)
+ ' process the data in _encbuffer, e.g. write to disk or whatever
+ ...
+ End Function
+
+ If you are into C# you might also use native pointer access in an unsafe code block:
+
+ // assuming you have created a: BinaryWriter bw = new BinaryWriter(_fs);
+ private unsafe bool MyEncodingWriter(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ byte *data = (byte*)buffer;
+ // process the data in 'data', e.g. write to disk or whatever
+ for (int a=0; a<length; a++)
+ {
+ // write the received sample data to a local file
+ bw.Write( data[a] );
+ }
+ }
+
+
+ private ENCODENOTIFYPROC _myEndoderNotify;
+ private int _encoder = 0;
+ private int _recChan = 0;
+ private bool _autoreconnect = true;
+ ...
+ _recChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, null, IntPtr.Zero);
+ Start();
+ ...
+ private void Start()
+ {
+ // start an encoder
+ _encoder = BassEnc.BASS_Encode_Start(_recChan, "lame -r -x -s 44100 -b 128 -",
+ BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
+ _myEndoderNotify = new ENCODENOTIFYPROC(EncoderNotify);
+ // start a caster
+ BassEnc.BASS_Encode_CastInit(_encoder, "server.com:8000", "password",
+ BassEnc.BASS_ENCODE_TYPE_MP3, "name", "url", "genre", null, null, 128, true);
+ // notify on dead encoder/connection
+ BassEnc.BASS_Encode_SetNotify(_encoder, _myEndoderNotify, IntPtr.Zero);
+ }
+
+ private void Stop()
+ {
+ if (_encoder != 0)
+ {
+ BassEnc.BASS_Encode_SetNotify(_encoder, null, IntPtr.Zero);
+ BassEnc.BASS_Encode_Stop(_encoder);
+ _encoder = 0;
+ }
+ }
+
+ private void EncoderNotify(int handle, BASSEncodeNotify status, IntPtr user)
+ {
+ // encoder/connection lost
+ Stop();
+ if (_autoreconnect)
+ {
+ // do auto-reconnect...
+ Thread.Sleep(1000); // wait a sec
+ Start();
+ }
+ }
+
+
+ Private _myEndoderNotify As ENCODENOTIFYPROC
+ Private _encoder As Integer = 0
+ Private _recChan As Integer = 0
+ Private _autoreconnect As Boolean = True
+ ...
+ _recChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, Nothing, IntPtr.Zero)
+ Start()
+ ...
+ Private Sub Start()
+ ' start an encoder
+ _encoder = BassEnc.BASS_Encode_Start(_recChan, "lame -r -x -s 44100 -b 128 -",
+ BASSEncode.BASS_ENCODE_NOHEAD, Nothing, IntPtr.Zero)
+ _myEndoderNotify = New ENCODENOTIFYPROC(AddressOf EncoderNotify)
+ ' start a caster
+ BassEnc.BASS_Encode_CastInit(_encoder, "server.com:8000", "password",
+ Bass.BASS_ENCODE_TYPE_MP3, "name", "url", "genre", Nothing, Nothing, 128, True)
+ ' notify on dead encoder/connection
+ BassEnc.BASS_Encode_SetNotify(_encoder, _myEndoderNotify, IntPtr.Zero)
+ End Sub
+
+ Private Sub Stop()
+ If _encoder <> 0 Then
+ BassEnc.BASS_Encode_SetNotify(_encoder, Nothing, IntPtr.Zero)
+ BassEnc.BASS_Encode_Stop(_encoder)
+ _encoder = 0
+ End If
+ End Sub
+
+ Private Sub EncoderNotify(handle As Integer, status As BASSEncodeNotify, user As IntPtr)
+ ' encoder/connection lost
+ Stop()
+ If _autoreconnect Then
+ ' do auto-reconnect...
+ Thread.Sleep(1000) ' wait a sec
+ Start()
+ End If
+ End Sub
+
+
+ int _listeners = 0; // client count
+
+ private bool EncodeClientProc(int handle, bool connect, string client, IntPtr headers, IntPtr user)
+ {
+ if (connect)
+ {
+ if (_listeners == 5)
+ {
+ // hit client limit
+ string[] resHeaders = new string[1] { "HTTP/1.0 403 Server Full" };
+ // set custom status
+ Utils.StringToNullTermAnsi(resHeaders, headers, true);
+ // refuse the connection
+ return false;
+ }
+ if (!client.StartsWith("192.168."))
+ {
+ // not on the 196.168/16 network
+ // refuse the connection
+ return false;
+ }
+ // increment the client count
+ _listeners++;
+ }
+ else
+ {
+ // decrement the client count
+ _listeners--;
+ }
+ return true;
+ }
+
+ A callback function that only allows connections with a particular "User-Agent" request header:
+
+ private bool EncodeClientProc(int handle, bool connect, string client, IntPtr headers, IntPtr user)
+ {
+ if (connect)
+ {
+ // get the received headers
+ string[] getHeaders = Utils.IntPtrToArrayNullTermAnsi(headers);
+ // find the User-Agent header
+ foreach (string content in getHeaders)
+ {
+ if (content.StartsWith("User-Agent:"))
+ {
+ // found the User-Agent header
+ if (content.Substring(11) != "Special Agent")
+ return false;
+ break;
+ }
+ }
+ }
+ return true;
+ }
+
+
+ - OctiMax (dsp_omxw.dll)
+ - Enhancer (dsp_enh.dll)
+ - RockSteady (DSP_RockSteady.dll)
+ - Nullsoft Signal Processing Studio (dsp_sps.dll)
+ - SHOUTcast Source DSP (dsp_sc.dll - needs lamedll.dll in your startup directory)
+ - SAM Encoders (dsp_encoders.dll)
+ - Sound Solution (dsp_ss.dll - needs the ssN.dat files in your startup directory)
+ - VST PlugIn Wrapper (dsp_vst.dll)
+ - EQ by Nevi (dsp_eqfir.dll)
+ - DFX Audio Enhander (dsp_dfx.dll)
+
+
+ - Reverb3 (dsp_reverb3.dll - working with fixed Packets of 1152 samples only)
+ - TomSteady (dsp_tom.dll - working with fixed Packets of 1152 samples only)
+ - PaceMaker (dsp_pacemaker.dll)
+
+
+ if ( Utils.HighWord(BassWaDsp.BASS_WADSP_GetVersion()) != BassWaDsp.BASSWADSPVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassWaDsp Version!");
+ }
+
+
+ If Utils.HighWord(BassWaDsp.BASS_WADSP_GetVersion()) <> BassWaDsp.BASSWADSPVERSION Then
+ MessageBox.Show(Me, "Wrong BassWaDsp Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassWaDsp.BASS_WADSP_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassWaDsp Version!");
+ }
+
+
+ If BassWaDsp.BASS_WADSP_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassWaDsp Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassWaDsp.BASS_WADSP_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassWaDsp Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassWaDsp.BASS_WADSP_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassWaDsp Version!")
+ End If
+
+
+ int dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, null);
+ if (dspPluginA != 0)
+ {
+ BassWaDsp.BASS_WADSP_Start(dspPluginA, 0, 0);
+ }
+
+
+ Dim dspPluginA As Integer = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, Nothing)
+ If dspPluginA <> 0 Then
+ BassWaDsp.BASS_WADSP_Start(dspPluginA, 0, 0)
+ End If
+
+
+ private int _streamA = 0;
+ private int _dspPluginA = 0;
+ private DSPPROC _myDSPAddr;
+ ...
+ _dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, null);
+ BassWaDsp.BASS_WADSP_Start(_dspPluginA, 0, 0);
+ ...
+ _streamA = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE);
+ // play the stream
+ if (_streamA != 0 )
+ {
+ _myDSPAddr = new DSPPROC(MyWinampDSP);
+ Bass.BASS_ChannelSetDSP(_streamA, _myDSPAddr, new IntPtr(_dspPluginA), -500);
+ BassWaDsp.BASS_WADSP_SetChannel(_dspPluginA, _streamA);
+ Bass.BASS_ChannelPlay(_streamA, false);
+ }
+ ...
+ private void MyWinampDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length == 0 || buffer == IntPtr.Zero)
+ return;
+ BassWaDsp.BASS_WADSP_ModifySamplesDSP(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _streamA As Integer = 0
+ Private _dspPluginA As Integer = 0
+ Private _myDSPAddr As DSPPROC
+ ...
+ _dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, Nothing)
+ BassWaDsp.BASS_WADSP_Start(_dspPluginA, 0, 0)
+ ...
+ _streamA = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_STREAM_AUTOFREE)
+ ' play the stream
+ If _streamA <> 0 Then
+ _myDSPAddr = New DSPPROC(AddressOf MyWinampDSP)
+ Bass.BASS_ChannelSetDSP(_streamA, _myDSPAddr, New IntPtr(_dspPluginA), - 500)
+ BassWaDsp.BASS_WADSP_SetChannel(_dspPluginA, _streamA)
+ Bass.BASS_ChannelPlay(_streamA, False)
+ End If
+ ...
+ Private Sub MyWinampDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ If length = 0 OrElse buffer = IntPtr.Zero Then
+ Return
+ End If
+ BassWaDsp.BASS_WADSP_ModifySamplesDSP(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ private int _streamA = 0;
+ private int _dspPluginA = 0;
+ ...
+ _dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, null);
+ BassWaDsp.BASS_WADSP_Start(_dspPluginA, 0, 0);
+ ...
+ // create the stream
+ _streamA = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE);
+ // play the stream
+ if (_streamA != 0 )
+ {
+ // the next will setup a DSP on the playing channel to the selected Winamp DSP
+ int hDsp = BassWaDsp.BASS_WADSP_ChannelSetDSP(this._dspPluginA, _streamA, 1);
+ // and finally play it
+ Bass.BASS_ChannelPlay(_streamA, false);
+ }
+
+
+ Private _streamA As Integer = 0
+ Private _dspPluginA As Integer = 0
+ ...
+ _dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, Nothing)
+ BassWaDsp.BASS_WADSP_Start(_dspPluginA, 0, 0)
+ ...
+ ' create the stream
+ _streamA = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_STREAM_AUTOFREE)
+ ' play the stream
+ If _streamA <> 0 Then
+ ' the next will setup a DSP on the playing channel to the selected Winamp DSP
+ Dim hDsp As Integer = BassWaDsp.BASS_WADSP_ChannelSetDSP(Me._dspPluginA, _streamA, 1)
+ ' and finally play it
+ Bass.BASS_ChannelPlay(_streamA, False)
+ End If
+
+
+ private int _streamA = 0;
+ private int _dspPluginA = 0;
+ private DSPPROC _myDSPAddr;
+ ...
+ _dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, null);
+ BassWaDsp.BASS_WADSP_Start(_dspPluginA, 0, 0);
+ ...
+ _streamA = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE);
+ // play the stream
+ if (_streamA != 0 )
+ {
+ _myDSPAddr = new DSPPROC(MyWinampDSP);
+ Bass.BASS_ChannelSetDSP(_streamA, _myDSPAddr, new IntPtr(_dspPluginA), -500);
+ BassWaDsp.BASS_WADSP_SetChannel(_dspPluginA, _streamA);
+ Bass.BASS_ChannelPlay(_streamA, false);
+ }
+ ...
+ private void MyWinampDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length == 0 || buffer == IntPtr.Zero)
+ return;
+ BassWaDsp.BASS_WADSP_ModifySamplesDSP(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _streamA As Integer = 0
+ Private _dspPluginA As Integer = 0
+ Private _myDSPAddr As DSPPROC
+ ...
+ _dspPluginA = BassWaDsp.BASS_WADSP_Load("dsp_test.dll", 5, 5, 100, 100, Nothing)
+ BassWaDsp.BASS_WADSP_Start(_dspPluginA, 0, 0)
+ ...
+ _streamA = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_STREAM_AUTOFREE)
+ ' play the stream
+ If _streamA <> 0 Then
+ _myDSPAddr = New DSPPROC(AddressOf MyWinampDSP)
+ Bass.BASS_ChannelSetDSP(_streamA, _myDSPAddr, New IntPtr(_dspPluginA), - 500)
+ BassWaDsp.BASS_WADSP_SetChannel(_dspPluginA, _streamA)
+ Bass.BASS_ChannelPlay(_streamA, False)
+ End If
+ ...
+ Private Sub MyWinampDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ If length = 0 OrElse buffer = IntPtr.Zero Then
+ Return
+ End If
+ BassWaDsp.BASS_WADSP_ModifySamplesDSP(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ string name;
+ for (int n=0; (name = BassWaDsp.BASS_WADSP_GetModuleName(plugin, n)) != null; n++)
+ {
+ Console.WriteLine(name);
+ }
+
+
+ Dim n As Integer = 0
+ Dim name As String = ""
+ While Not (name Is Nothing)
+ name = BassWaDsp.BASS_WADSP_GetModuleName(plugin, n)
+ n += 1
+ If Not (name Is Nothing) Then
+ Console.WriteLine(name)
+ End If
+ End While
+
+
+ string name;
+ for (int n=0; (name = BassWaDsp.BASS_WADSP_PluginInfoGetModuleName(n)) != null; n++)
+ {
+ Console.WriteLine(name);
+ }
+
+
+ Dim n As Integer = 0
+ Dim name As String = ""
+ While Not (name Is Nothing)
+ name = BassWaDsp.BASS_WADSP_PluginInfoGetModuleName(n)
+ n += 1
+ If Not (name Is Nothing) Then
+ Console.WriteLine(name)
+ End If
+ End While
+
+
+ WINAMP_DSP.FindPlugins("C:\\Program Files\\Winamp\\Plugins");
+ this.listBox1.Items.AddRange(WINAMP_DSP.PlugIns);
+ ...
+ // and display all modules out of a certain dsp...
+ WINAMP_DSP dsp = (WINAMP_DSP)this.listBox1.SelectedItem;
+ if (dsp.modulecount > 0)
+ {
+ // display all modules
+ this.comboBox1.Items.Clear();
+ this.comboBox1.Items.AddRange(dsp.modulenames);
+ this.comboBox1.SelectedIndex = 0;
+ }
+
+
+ WINAMP_DSP.BASS_WADSP_FindPlugins("C:\Program Files\Winamp\Plugins")
+ Me.listBox1.Items.AddRange(WINAMP_DSP.PlugIns)
+ ...
+ ' and display all modules out of a certain dsp...
+ Dim dsp As WINAMP_DSP = CType(Me.listBox1.SelectedItem, WINAMP_DSP)
+ If dsp.modulecount > 0 Then
+ ' display all modules
+ Me.comboBox1.Items.Clear()
+ Me.comboBox1.Items.AddRange(dsp.modulenames)
+ Me.comboBox1.SelectedIndex = 0
+ End If
+
+
+ if ( Utils.HighWord(BassDShow.BASS_DSHOW_GetVersion()) != BassDShow.BASSDSHOWVERSION )
+ {
+ MessageBox.Show(this, "Wrong BassDShow Version!");
+ }
+
+
+ If Utils.HighWord(BassDShow.BASS_DSHOW_GetVersion()) <> BassDShow.BASSDSHOWVERSION Then
+ MessageBox.Show(Me, "Wrong BassDShow Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (BassDShow.BASS_DSHOW_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong BassDShow Version!");
+ }
+
+
+ If BassDShow.BASS_DSHOW_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong BassDShow Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (BassDShow.BASS_DSHOW_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong BassDShow Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If BassDShow.BASS_DSHOW_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong BassDShow Version!")
+ End If
+
+
+ public class DSP_MyDsp : BaseDSP
+ {
+ // First Constructor overload
+ public DSP_MyDsp() : base()
+ {
+ }
+ // Second Constructor overload
+ public DSP_MyDsp(int channel, int priority) : base(channel, priority, 0)
+ {
+ }
+
+ // example implementation of the DSPCallback method
+ unsafe public override void DSPCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (IsBypassed)
+ return;
+
+ if (ChannelBitwidth == 16)
+ {
+ // process the data
+ short *data = (short*)buffer;
+ for (int a = 0; a < length/2; a++)
+ {
+ // your work goes here (16-bit sample data)
+ }
+ }
+ else if (ChannelBitwidth == 32)
+ {
+ // process the data
+ float *data = (float*)buffer;
+ for (int a = 0; a < length/4; a++)
+ {
+ // your work goes here (32-bit sample data)
+ }
+ }
+ else
+ {
+ // process the data
+ byte *data = (byte*)buffer;
+ for (int a = 0; a < length; a++)
+ {
+ // your work goes here (8-bit sample data)
+ }
+ }
+ // if you have calculated UI relevant data you might raise the event
+ // else comment out the following line
+ RaiseNotification();
+ }
+
+ public override void OnChannelChanged()
+ {
+ // override this method if you need to react on channel changes
+ // e.g. usefull, if an internal buffer needs to be reset etc.
+ }
+
+ public override string ToString()
+ {
+ return "My DSP";
+ }
+ }
+
+
+ private DSP_PeakLevelMeter _plm;
+ public delegate void UpdatePeakMeterCallback();
+ ...
+ Bass.BASS_RecordInit(-1);
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, _recProc, 0);
+ ...
+ // set up a ready-made DSP (here the PeakLevelMeter)
+ _plm = new DSP_PeakLevelMeter(_recHandle, 1);
+ _plm.CalcRMS = true;
+ _plm.Notification += new EventHandler(UpdatePeakMeterDisplay);
+ ...
+ private void UpdatePeakMeterDisplay(object sender, EventArgs e)
+ {
+ this.progressBarRecL.Value = _plm.LevelL;
+ this.progressBarRecR.Value = _plm.LevelR;
+ this.labelRMS.Text = String.Format( "RMS: {0:#00.0} dB - AVG: {1:#00.0} dB - Peak: {2:#00.0} dB",
+ _plm.RMS_dBV,
+ _plm.AVG_dBV,
+ Math.Max(_plm.PeakHoldLevelL_dBV, _plm.PeakHoldLevelR_dBV) );
+ }
+
+
+ private DSP_StreamCopy _streamCopy;
+ ...
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ ...
+ // create the original stream (on device 1)
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT);
+ // start playing it...
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ _streamCopy = new DSP_StreamCopy();
+ BASS_INFO info = Bass.BASS_GetInfo();
+ _streamCopy.OutputLatency = info.latency;
+ // the stream to copy
+ _streamCopy.ChannelHandle = stream;
+ _streamCopy.DSPPriority = -1000;
+ // use device 2 to create the copy on
+ _streamCopy.StreamCopyDevice = 2;
+ // use the exact same stream flags for the stream copy
+ _streamCopy.StreamCopyFlags = _streamCopy.ChannelInfo.flags;
+ _streamCopy.Start();
+
+
+ Private _streamCopy As DSP_StreamCopy
+ ...
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ ...
+ ' create the original stream (on device 1)
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT)
+ ' start playing it...
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ _streamCopy = New DSP_StreamCopy()
+ BASS_INFO info = Bass.BASS_GetInfo()
+ _streamCopy.OutputLatency = info.latency
+ ' the stream to copy
+ _streamCopy.ChannelHandle = stream
+ _streamCopy.DSPPriority = -1000
+ ' use device 2 to create the copy on
+ _streamCopy.StreamCopyDevice = 2
+ ' use the exact same stream flags for the stream copy
+ _streamCopy.StreamCopyFlags = _streamCopy.ChannelInfo.flags
+ _streamCopy.Start()
+
+ Create a copy of a regular BASS stream and play it on other speakers:
+
+ private DSP_StreamCopy _streamCopy;
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, IntPtr.Zero);
+ ...
+ // create the original stream (using front speakers)
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SPEAKER_FRONT);
+ // start playing it...
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ _streamCopy = new DSP_StreamCopy();
+ BASS_INFO info = Bass.BASS_GetInfo();
+ _streamCopy.OutputLatency = info.latency;
+ // the stream to copy
+ _streamCopy.ChannelHandle = stream;
+ _streamCopy.DSPPriority = -1000;
+ // use different speaker flags for the stream copy
+ _streamCopy.StreamCopyFlags = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SPEAKER_REAR;
+ _streamCopy.Start();
+
+
+ Private _streamCopy As DSP_StreamCopy
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, IntPtr.Zero)
+ ...
+ ' create the original stream (using front speakers)
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_SPEAKER_FRONT)
+ ' start playing it...
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ _streamCopy = New DSP_StreamCopy()
+ BASS_INFO info = Bass.BASS_GetInfo();
+ _streamCopy.OutputLatency = info.latency;
+ ' the stream to copy
+ _streamCopy.ChannelHandle = stream
+ _streamCopy.DSPPriority = -1000
+ ' use different speaker flags for the stream copy
+ _streamCopy.StreamCopyFlags = BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_SPEAKER_REAR
+ _streamCopy.Start()
+
+ Create a copy of a BASSmix source mixer stream and copy it to another BASSmix mixer as a source:
+
+ private DSP_StreamCopy _streamCopy;
+ ...
+ _streamCopy = new DSP_StreamCopy();
+ BASS_INFO info = Bass.BASS_GetInfo();
+ _streamCopy.OutputLatency = info.latency;
+ _streamCopy.DSPPriority = -9000;
+ ...
+ // assign the copy
+ _streamCopy.ChannelHandle = _mixerSourceStream; // the stream to copy
+ _streamCopy.StreamCopyDevice = 0;
+ _streamCopy.StreamCopyFlags = BASSFlag.BASS_STREAM_DECODE;
+ _streamCopy.SourceMixerStream = MixerStreamA;
+ _streamCopy.TargetMixerStream = MixerStreamB;
+ _streamCopy.IsOutputBuffered = true;
+ _streamCopy.Start();
+ ...
+ // start playing the original source
+ BassMix.BASS_Mixer_ChannelPlay(_mixerSourceStream);
+ if (_streamCopy.IsAssigned)
+ _streamCopy.ReSync();
+ ...
+ // pausing the original source
+ BassMix.BASS_Mixer_ChannelPause(_mixerSourceStream);
+ ...
+
+
+ Private _streamCopy As DSP_StreamCopy
+ ...
+ _streamCopy = New DSP_StreamCopy()
+ BASS_INFO info = Bass.BASS_GetInfo();
+ _streamCopy.OutputLatency = info.latency;
+ _streamCopy.DSPPriority = -9000
+ ...
+ ' assign the copy
+ _streamCopy.ChannelHandle = _mixerSourceStream ' the stream to copy
+ _streamCopy.StreamCopyDevice = 0
+ _streamCopy.StreamCopyFlags = BASSFlag.BASS_STREAM_DECODE
+ _streamCopy.SourceMixerStream = MixerStreamA
+ _streamCopy.TargetMixerStream = MixerStreamB
+ _streamCopy.IsOutputBuffered = true
+ _streamCopy.Start()
+ ...
+ ' start playing the original source
+ BassMix.BASS_Mixer_ChannelPlay(_mixerSourceStream)
+ If _streamCopy.IsAssigned Then
+ _streamCopy.ReSync();
+ End If
+ ...
+ ' pausing the original source
+ BassMix.BASS_Mixer_ChannelPause(_mixerSourceStream)
+ ...
+
+
+ private DSP_BufferStream _bufferStream;
+ ...
+ // create a mixer outout stream
+ _mixer1 = BassMix.BASS_MIXER_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(_mixer1, false);
+ _mixer2 = BassMix.BASS_MIXER_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(_mixer2, false);
+ // create a source stream and add it to the mixer1
+ _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT |
+ BASSFlag.BASS_STREAM_DECODE);
+ BassMix.BASS_Mixer_StreamAddChannel(_mixer1, _stream, BASSFlag.BASS_DEFAULT);
+ ...
+ // create a clone of the source stream to add it to mixer2
+ _bufferStream = new DSP_BufferStream();
+ _bufferStream.ChannelHandle = _stream; // the stream to copy
+ _bufferStream.DSPPriority = -4000;
+ _bufferStream.Start();
+ BassMix.BASS_Mixer_StreamAddChannel(_mixer1, _bufferStream.BufferStream, BASSFlag.BASS_DEFAULT);
+
+
+ Private _bufferStream As DSP_BufferStream
+ ...
+ ' create a mixer outout stream
+ _mixer1 = BassMix.BASS_MIXER_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(_mixer1, False)
+ _mixer2 = BassMix.BASS_MIXER_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(_mixer2, False)
+ ' create a source stream and add it to the mixer1
+ _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT Or
+ BASSFlag.BASS_STREAM_DECODE)
+ BassMix.BASS_Mixer_StreamAddChannel(_mixer1, _stream, BASSFlag.BASS_DEFAULT)
+ ...
+ ' create a clone of the source stream to add it to mixer2
+ _bufferStream = New DSP_BufferStream()
+ _bufferStream.ChannelHandle = _stream ' the stream to copy
+ _bufferStream.DSPPriority = - 4000
+ _bufferStream.Start()
+ BassMix.BASS_Mixer_StreamAddChannel(_mixer1, _bufferStream.BufferStream, BASSFlag.BASS_DEFAULT)
+
+ Create a buffered stream copy to sync a FFT or GetLevel call:
+
+ private DSP_BufferStream _bufferStream;
+ ...
+ // create a mixer outout stream
+ _mixer = BassMix.BASS_MIXER_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(BASSFlag.BASS_DEFAULT, false);
+ // create a source stream and add it to the mixer
+ _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT |
+ BASSFlag.BASS_STREAM_DECODE);
+ BassMix.BASS_Mixer_StreamAddChannel(_mixer, _stream, BASSFlag.BASS_DEFAULT);
+ ...
+ // create a buffer of the source stream for level and/or FFT data retrival in sync with the mixer output
+ _bufferStream = new DSP_BufferStream();
+ _bufferStream.ChannelHandle = _stream; // the stream to copy
+ _bufferStream.OutputHandle = _mixer; // the stream to sync with (what's being heard)
+ _bufferStream.DSPPriority = -4000;
+ _bufferStream.Start();
+ ...
+ float[] fft = new float[2048];
+ Bass.BASS_ChannelGetData(_bufferStream.BufferStream, fft, (int)BASSData.BASS_DATA_FFT4096);
+
+
+ Private _bufferStream As DSP_BufferStream
+ ...
+ ' create a mixer outout stream
+ _mixer = BassMix.BASS_MIXER_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(BASSFlag.BASS_DEFAULT, False)
+ ' create a source stream and add it to the mixer
+ _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT Or
+ BASSFlag.BASS_STREAM_DECODE)
+ BassMix.BASS_Mixer_StreamAddChannel(_mixer, _stream, BASSFlag.BASS_DEFAULT)
+ ...
+ ' create a buffer of the source stream for level and/or FFT data retrival in sync with the mixer output
+ _bufferStream = New DSP_BufferStream()
+ _bufferStream.ChannelHandle = _stream ' the stream to copy
+ _bufferStream.OutputHandle = _mixer ' the stream to sync with (what's being heard)
+ _bufferStream.DSPPriority = - 4000
+ _bufferStream.Start()
+ ...
+ Dim fft(2048) As Single
+ Bass.BASS_ChannelGetData(_bufferStream.BufferStream, fft, CInt(BASSData.BASS_DATA_FFT4096))
+
+
+ private int _recHandle;
+ private BroadCast _broadCast;
+ ...
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, null, 0);
+ ...
+ // create an encoder instance (e.g. for MP3 use EncoderLAME):
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+ lame.InputFile = null; //STDIN
+ lame.OutputFile = null; //STDOUT
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_56;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono;
+ lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_22050;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+
+ // create a StreamingServer instance (e.g. SHOUTcast) using the encoder:
+ SHOUTcast shoutcast = new SHOUTcast(lame);
+ shoutcast.ServerAddress = "localhost";
+ shoutcast.ServerPort = 8000;
+ shoutcast.Password = "changeme";
+ shoutcast.PublicFlag = true;
+
+ // use the BroadCast class to control streaming:
+ _broadCast = new BroadCast(shoutcast);
+ _broadCast.AutoReconnect = true;
+ _broadCast.Notification += new BroadCastEventHandler(OnBroadCast_Notification);
+ _broadCast.AutoConnect();
+
+ private void OnBroadCast_Notification(object sender, BroadCastEventArgs e)
+ {
+ // Note: this method might be called from another thread (non UI thread)!
+ if (_broadCast == null)
+ return;
+ if (_broadCast.IsConnected)
+ {
+ // we are connected...
+ }
+ else
+ {
+ // we are not connected...
+ }
+ }
+
+
+ Private _recHandle As Integer
+ Private _broadCast As BroadCast
+ ...
+ _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, Nothing, 0)
+ ...
+ ' create an encoder instance (e.g. for MP3 use EncoderLAME):
+ Dim lame As New EncoderLAME(_recHandle)
+ lame.InputFile = Nothing 'STDIN
+ lame.OutputFile = Nothing 'STDOUT
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
+ lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+
+ ' create a StreamingServer instance (e.g. SHOUTcast) using the encoder:
+ Dim shoutcast As New SHOUTcast(lame)
+ shoutcast.ServerAddress = "localhost"
+ shoutcast.ServerPort = 8000
+ shoutcast.Password = "changeme"
+ shoutcast.PublicFlag = True
+
+ ' use the BroadCast class to control streaming:
+ _broadCast = New BroadCast(shoutcast)
+ _broadCast.AutoReconnect = True
+ AddHandler _broadCast.Notification, AddressOf OnBroadCast_Notification
+ _broadCast.AutoConnect()
+
+ Private Sub OnBroadCast_Notification(sender As Object, e As BroadCastEventArgs)
+ ' Note: this method might be called from another thread (non UI thread)!
+ If _broadCast Is Nothing Then
+ Return
+ End If
+ If _broadCast.IsConnected Then
+ ' we are connected...
+ Else
+ ' we are not connected...
+ End If
+ End Sub
+
+
+ private BroadCast _broadCast;
+ private ENCODEPROC _myEncProc;
+ ...
+ // create your encoder (using a recording handle)
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+
+ // create an streaming server instance
+ SHOUTcast shoutcast = new SHOUTcast(lame);
+
+ // create the broadcast instance
+ _broadCast = new BroadCast(shoutcast);
+ _broadCast.AutoReconnect = true;
+ _broadCast.Notification += new BroadCastEventHandler(OnBroadCast_Notification);
+
+ // create your encoder callback
+ _myEncProc = new ENCODEPROC(MyEncodingCallback);
+ // start the encoder (paused)
+ _broadCast.StartEncoder(_myEncProc, IntPtr.Zero, true);
+ // now connect to start your broadcast
+ _broadCast.Connect();
+ // and really start the encoder
+ _broadCast.Server.Encoder.Pause(false);
+ ...
+
+ // your broadcast encoder callback implementation
+ private void MyEncodingCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // here we receive the encoded data back (manual mode)
+ if ( _broadCast.IsConnected )
+ {
+ _broadCast.SendData(buffer, length);
+ }
+ }
+
+ private void OnBroadCast_Notification(object sender, BroadCastEventArgs e)
+ {
+ if (e.EventType == BroadCastEventType.EncoderRestartRequired)
+ _broadCast.StartEncoder(_myEncProc, 0);
+
+ if (!_broadCast.IsConnected)
+ {
+ // connection lost
+ }
+ }
+
+
+ Private _broadCast As BroadCast
+ Private _myEncProc As ENCODEPROC
+ ...
+ ' create your encoder (using a recording handle)
+ Dim lame As New EncoderLAME(_recHandle)
+
+ ' create an streaming server instance
+ Dim shoutcast As New SHOUTcast(lame)
+
+ ' create the broadcast instance
+ _broadCast = New BroadCast(shoutcast)
+ _broadCast.AutoReconnect = True
+ AddHandler _broadCast.Notification, AddressOf OnBroadCast_Notification
+
+ ' create your encoder callback
+ _myEncProc = New ENCODEPROC(AddressOf MyEncodingCallback)
+ ' start the encoder (paused)
+ _broadCast.StartEncoder(_myEncProc, IntPtr.Zero, True)
+ ' now connect to start your broadcast
+ _broadCast.Connect()
+ ' and really start the encoder
+ _broadCast.Server.Encoder.Pause(False)
+ ...
+
+ ' your broadcast encoder callback implementation
+ Private Sub MyEncodingCallback(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ ' here we receive the encoded data back (manual mode)
+ If _broadCast.IsConnected Then
+ _broadCast.SendData(buffer, length)
+ End If
+ End Sub
+
+ Private Sub OnBroadCast_Notification(sender As Object, e As BroadCastEventArgs)
+ If e.EventType = BroadCastEventType.EncoderRestartRequired Then
+ _broadCast.StartEncoder(_myEncProc, 0)
+ End If
+
+ If Not _broadCast.IsConnected Then
+ ' connection lost
+ End If
+ End Sub
+
+
+ private BroadCast _broadCast;
+ private ENCODEPROC _myEncProc;
+ ...
+ // create your encoder (using a recording handle)
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+
+ // create an streaming server instance
+ SHOUTcast shoutcast = new SHOUTcast(lame);
+
+ // create the broadcast instance
+ _broadCast = new BroadCast(shoutcast);
+ _broadCast.AutoReconnect = true;
+ _broadCast.Notification += new BroadCastEventHandler(OnBroadCast_Notification);
+
+ // create your encoder callback
+ _myEncProc = new ENCODEPROC(MyEncodingCallback);
+ // start the encoder (paused)
+ _broadCast.StartEncoder(_myEncProc, IntPtr.Zero, true);
+ // now connect to start your broadcast
+ _broadCast.Connect();
+ // and really start the encoder
+ _broadCast.Server.Encoder.Pause(false);
+ ...
+
+ // your broadcast encoder callback implementation
+ private void MyEncodingCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // here we receive the encoded data back (manual mode)
+ if ( _broadCast.IsConnected )
+ {
+ _broadCast.SendData(buffer, length);
+ }
+ }
+
+ private void OnBroadCast_Notification(object sender, BroadCastEventArgs e)
+ {
+ if (e.EventType == BroadCastEventType.EncoderRestartRequired)
+ _broadCast.StartEncoder(_myEncProc, 0);
+
+ if (!_broadCast.IsConnected)
+ {
+ // connection lost
+ }
+ }
+
+
+ Private _broadCast As BroadCast
+ Private _myEncProc As ENCODEPROC
+ ...
+ ' create your encoder (using a recording handle)
+ Dim lame As New EncoderLAME(_recHandle)
+
+ ' create an streaming server instance
+ Dim shoutcast As New SHOUTcast(lame)
+
+ ' create the broadcast instance
+ _broadCast = New BroadCast(shoutcast)
+ _broadCast.AutoReconnect = True
+ AddHandler _broadCast.Notification, AddressOf OnBroadCast_Notification
+
+ ' create your encoder callback
+ _myEncProc = New ENCODEPROC(AddressOf MyEncodingCallback)
+ ' start the encoder (paused)
+ _broadCast.StartEncoder(_myEncProc, IntPtr.Zero, True)
+ ' now connect to start your broadcast
+ _broadCast.Connect()
+ ' and really start the encoder
+ _broadCast.Server.Encoder.Pause(False)
+ ...
+
+ ' your broadcast encoder callback implementation
+ Private Sub MyEncodingCallback(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ ' here we receive the encoded data back (manual mode)
+ If _broadCast.IsConnected Then
+ _broadCast.SendData(buffer, length)
+ End If
+ End Sub
+
+ Private Sub OnBroadCast_Notification(sender As Object, e As BroadCastEventArgs)
+ If e.EventType = BroadCastEventType.EncoderRestartRequired Then
+ _broadCast.StartEncoder(_myEncProc, 0)
+ End If
+
+ If Not _broadCast.IsConnected Then
+ ' connection lost
+ End If
+ End Sub
+
+
+ public class MyOwnServer : StreamingServer
+ {
+ // Constructor
+ public MyOwnServer(IBaseEncoder encoder, bool useBASS) : base(encoder, useBASS)
+ {
+ // validity check
+ if (encoder.EncoderType != BASSChannelType.BASS_CTYPE_STREAM_MP3 &&
+ encoder.EncoderType != BASSChannelType.BASS_CTYPE_STREAM_AAC)
+ throw new Exception( "Invalid EncoderType (only MP3 and AAC is supported)!" );
+ }
+
+ private Socket _socket = null;
+ private bool _loggedIn = false;
+ private byte[] _data = null;
+ private object _lock = false;
+ public string ServerAddress = "localhost";
+ public int ServerPort = 8000;
+
+ public override bool IsConnected
+ {
+ get
+ {
+ if (_socket != null)
+ return _socket.Connected && _loggedIn;
+ else
+ return false;
+ }
+ }
+
+ public override bool Connect()
+ {
+ // check the encoder
+ if (!Encoder.IsActive)
+ {
+ LastError = STREAMINGERROR.Error_EncoderError;
+ LastErrorMessage = "Encoder not active!";
+ return false;
+ }
+ // close any connections, if still open
+ if (_socket != null && _socket.Connected)
+ {
+ _socket.Close();
+ _socket = null;
+ }
+ // create a connection at port+1
+ _socket = CreateSocket( ServerAddress, ServerPort+1 );
+ return (_socket != null && _socket.Connected);
+ }
+
+ public override bool Disconnect()
+ {
+ bool ok = false;
+ try
+ {
+ _socket.Close();
+ }
+ catch { }
+ finally
+ {
+ if (_socket != null && _socket.Connected)
+ {
+ LastError = STREAMINGERROR.Error_Disconnect;
+ LastErrorMessage = "Winsock error: " +
+ Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
+ }
+ else
+ {
+ ok = true;
+ _socket = null;
+ _loggedIn = false;
+ }
+ }
+ return ok;
+ }
+
+ public override bool Login()
+ {
+ if (_socket == null)
+ {
+ LastError = STREAMINGERROR.Error_NotConnected;
+ LastErrorMessage = "Not connected to server.";
+ return false;
+ }
+ bool ok = false;
+ if ( MyLogin() )
+ {
+ if ( MyInit() )
+ {
+ ok = true;
+ _loggedIn = true;
+ LastError = STREAMINGERROR.Ok;
+ LastErrorMessage = String.Empty;
+ }
+ else
+ {
+ LastError = STREAMINGERROR.Error_Login;
+ LastErrorMessage = "Server could not be initialized.";
+ }
+ }
+ else
+ {
+ LastError = STREAMINGERROR.Error_Login;
+ LastErrorMessage = "Invalid username or password.";
+ }
+ return ok;
+ }
+
+ public override int SendData(IntPtr buffer, int length)
+ {
+ if (buffer == IntPtr.Zero || length == 0)
+ return 0;
+ int sendData = -1;
+ try
+ {
+ lock (_lock)
+ {
+ // dynamic buffer allocation
+ if (_data == null || _data.Length < length)
+ _data = new byte[length];
+ Marshal.Copy(buffer, _data, 0, length);
+ sendData = _socket.Send( _data, 0, length, SocketFlags.None );
+ if (sendData < 0)
+ {
+ LastError = STREAMINGERROR.Error_SendingData;
+ LastErrorMessage = String.Format( "{0} bytes not send.", length);
+ Disconnect();
+ }
+ else if (sendData != length)
+ {
+ LastError = STREAMINGERROR.Warning_LessDataSend;
+ LastErrorMessage = String.Format( "{0} of {1} bytes send.", sendData, length);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ LastError = STREAMINGERROR.Error_SendingData;
+ LastErrorMessage = e.Message;
+ sendData = -1;
+ Disconnect();
+ }
+ return sendData;
+ }
+
+ public override bool UpdateTitle(string song, string url)
+ {
+ SongTitle = song;
+ return MyUpdateTitle(song);
+ }
+
+ private Socket CreateSocket(string serveraddress, int port)
+ {
+ Socket socket = null;
+ IPHostEntry hostEntry = null;
+ try
+ {
+ // Get host related information
+ hostEntry = Dns.GetHostEntry(serveraddress);
+ // Loop through the AddressList to obtain the supported AddressFamily.
+ foreach(IPAddress address in hostEntry.AddressList)
+ {
+ try
+ {
+ IPEndPoint ipe = new IPEndPoint(address, port);
+ Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+ tempSocket.Connect(ipe);
+ if (tempSocket.Connected)
+ {
+ socket = tempSocket;
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+ catch (Exception e)
+ {
+ LastError = STREAMINGERROR.Error_CreatingConnection;
+ LastErrorMessage = e.Message;
+ socket = null;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ LastError = STREAMINGERROR.Error_ResolvingServerAddress;
+ LastErrorMessage = e.Message;
+ socket = null;
+ }
+ return socket;
+ }
+
+ private bool MyLogin()
+ {
+ if (_socket == null)
+ return false;
+ // e.g. send password here using the "_socket"
+ ...
+ }
+
+ private bool MyInit()
+ {
+ if (_socket == null)
+ return false;
+ // e.g. send some init data to the server here using the "_socket"
+ ...
+ }
+
+ private bool MyUpdateTitle(string song)
+ {
+ bool ok = false;
+ Socket socket = null;
+ try
+ {
+ socket = CreateSocket( ServerAddress, ServerPort );
+ if (socket != null)
+ {
+ // send the song title using the created "socket"
+ ...
+ ok = true;
+ }
+ }
+ catch { }
+ finally
+ {
+ // disconnect
+ if (socket != null)
+ {
+ socket.Close();
+ socket = null;
+ }
+ }
+ return ok;
+ }
+ }
+
+
+ Public Class MyOwnServer Inherits StreamingServer
+
+ ' Constructor
+ Public Sub New(encoder As IBaseEncoder, useBASS As Boolean) MyBase.New(encoder, useBASS)
+ ' validity check
+ If encoder.EncoderType <> BASSChannelType.BASS_CTYPE_STREAM_MP3 AndAlso
+ encoder.EncoderType <> BASSChannelType.BASS_CTYPE_STREAM_AAC Then
+ Throw New Exception("Invalid EncoderType (only MP3 and AAC is supported)!")
+ End If
+ End Sub
+
+ Private _socket As Socket = Nothing
+ Private _loggedIn As Boolean = False
+ Private _data As Byte() = Nothing
+ Private _lock As Object = False
+ Public ServerAddress As String = "localhost"
+ Public ServerPort As Integer = 8000
+
+ Public Overrides ReadOnly Property IsConnected() As Boolean
+ Get
+ If Not (_socket Is Nothing) Then
+ Return _socket.Connected AndAlso _loggedIn
+ Else
+ Return False
+ End If
+ End Get
+ End Property
+
+ Public Overrides Function Connect() As Boolean
+ ' check the encoder
+ If Not Encoder.IsActive Then
+ LastError = STREAMINGERROR.Error_EncoderError
+ LastErrorMessage = "Encoder not active!"
+ Return False
+ End If
+ ' close any connections, if still open
+ If Not (_socket Is Nothing) AndAlso _socket.Connected Then
+ _socket.Close()
+ _socket = Nothing
+ End If
+ ' create a connection at port+1
+ _socket = CreateSocket(ServerAddress, ServerPort + 1)
+ Return Not (_socket Is Nothing) AndAlso _socket.Connected
+ End Function
+
+ Public Overrides Function Disconnect() As Boolean
+ Dim ok As Boolean = False
+ Try
+ _socket.Close()
+ Catch
+ Finally
+ If Not (_socket Is Nothing) AndAlso _socket.Connected Then
+ LastError = STREAMINGERROR.Error_Disconnect
+ LastErrorMessage = "Winsock error: " +
+ Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error())
+ Else
+ ok = True
+ _socket = Nothing
+ _loggedIn = False
+ End If
+ End Try
+ Return ok
+ End Function
+
+ Public Overrides Function Login() As Boolean
+ If _socket Is Nothing Then
+ LastError = STREAMINGERROR.Error_NotConnected
+ LastErrorMessage = "Not connected to server."
+ Return False
+ End If
+ Dim ok As Boolean = False
+ If MyLogin() Then
+ If MyInit() Then
+ ok = True
+ _loggedIn = True
+ LastError = STREAMINGERROR.Ok
+ LastErrorMessage = [String].Empty
+ Else
+ LastError = STREAMINGERROR.Error_Login
+ LastErrorMessage = "Server could not be initialized."
+ End If
+ Else
+ LastError = STREAMINGERROR.Error_Login
+ LastErrorMessage = "Invalid username or password."
+ End If
+ Return ok
+ End Function
+
+ Public Overrides Function SendData(buffer As IntPtr, length As Integer) As Integer
+ If buffer = IntPtr.Zero OrElse length = 0 Then
+ Return 0
+ End If
+ Dim sendData As Integer = -1
+ Try
+ SyncLock _lock
+ ' dynamic buffer allocation
+ If _data Is Nothing OrElse _data.Length < length Then
+ _data = New Byte(length) {}
+ End If
+ Marshal.Copy(buffer, _data, 0, length)
+ sendData = _socket.Send(_data, 0, length, SocketFlags.None)
+ If sendData < 0 Then
+ LastError = STREAMINGERROR.Error_SendingData
+ LastErrorMessage = [String].Format("{0} bytes not send.", length)
+ Disconnect()
+ Else
+ If sendData <> length Then
+ LastError = STREAMINGERROR.Warning_LessDataSend
+ LastErrorMessage = [String].Format("{0} of {1} bytes send.", sendData, length)
+ End If
+ End If
+ End SyncLock
+ Catch e As Exception
+ LastError = STREAMINGERROR.Error_SendingData
+ LastErrorMessage = e.Message
+ sendData = -1
+ Disconnect()
+ End Try
+ Return sendData
+ End Function
+
+ Public Overrides Function UpdateTitle(song As String) As Boolean
+ SongTitle = song
+ Return MyUpdateTitle(song)
+ End Function
+
+ Private Function CreateSocket(serveraddress As String, port As Integer) As Socket
+ Dim socket As Socket = Nothing
+ Dim hostEntry As IPHostEntry = Nothing
+ Try
+ ' Get host related information
+ hostEntry = Dns.GetHostEntry(serveraddress)
+ ' Loop through the AddressList to obtain the supported AddressFamily.
+ Dim address As IPAddress
+ For Each address In hostEntry.AddressList
+ Try
+ Dim ipe As New IPEndPoint(address, port)
+ Dim tempSocket As New Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
+ tempSocket.Connect(ipe)
+ If tempSocket.Connected Then
+ socket = tempSocket
+ Exit ForEach
+ Else
+ GoTo ContinueForEach1
+ End If
+ Catch e As Exception
+ LastError = STREAMINGERROR.Error_CreatingConnection
+ LastErrorMessage = e.Message
+ socket = Nothing
+ End Try
+ ContinueForEach1:
+ Next address
+ Catch e As Exception
+ LastError = STREAMINGERROR.Error_ResolvingServerAddress
+ LastErrorMessage = e.Message
+ socket = Nothing
+ End Try
+ Return socket
+ End Function
+
+ Private Function MyLogin() As Boolean
+ If _socket Is Nothing Then
+ Return False
+ End If
+ ' e.g. send password here using the "_socket"
+ ...
+ End Function
+
+ Private Function MyInit() As Boolean
+ If _socket Is Nothing Then
+ Return False
+ End If
+ ' e.g. send some init data to the server here using the "_socket"
+ ...
+ End Function
+
+ Private Function MyUpdateTitle(song As String) As Boolean
+ Dim ok As Boolean = False
+ Dim socket As Socket = Nothing
+ Try
+ socket = CreateSocket(ServerAddress, ServerPort)
+ If Not (socket Is Nothing) Then
+ ' send the song title using the created "socket"
+ ...
+ ok = True
+ End If
+ Catch
+ Finally
+ ' disconnect
+ If Not (socket Is Nothing) Then
+ socket.Close()
+ socket = Nothing
+ End If
+ End Try
+ Return ok
+ End Function
+
+ End Class
+
+
+ // create an encoder instance
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_56;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono;
+ lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_22050;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+
+ // now create the SHOUTcast instance using LAME
+ SHOUTcast shoutcast = new SHOUTcast(lame);
+ shoutcast.ServerAddress = "http://serveraddress.com";
+ shoutcast.ServerPort = 8000;
+ shoutcast.Password = "password";
+ ...
+
+
+ ' create an encoder instance
+ Dim lame As New EncoderLAME(_recHandle)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
+ lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+
+ ' now create the SHOUTcast instance using LAME
+ Dim shoutcast As New SHOUTcast(lame)
+ shoutcast.ServerAddress = "http://serveraddress.com"
+ shoutcast.ServerPort = 8000
+ shoutcast.Password = "password"
+ ...
+
+
+ // create an encoder instance
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_56;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono;
+ lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_22050;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+
+ // now create the SHOUTcast instance using LAME
+ SHOUTcast shoutcast = new SHOUTcast(lame, true);
+ shoutcast.ServerAddress = "http://serveraddress.com";
+ shoutcast.ServerPort = 8000;
+ shoutcast.Password = "password";
+ ...
+
+
+ ' create an encoder instance
+ Dim lame As New EncoderLAME(_recHandle)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
+ lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+
+ ' now create the SHOUTcast instance using LAME
+ Dim shoutcast As New SHOUTcast(lame, True)
+ shoutcast.ServerAddress = "http://serveraddress.com"
+ shoutcast.ServerPort = 8000
+ shoutcast.Password = "password"
+ ...
+
+
+ // create an encoder instance
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_56;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono;
+ lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_22050;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+
+ // now create the ICEcast instance using LAME
+ ICEcast icecast = new ICEcast(lame);
+ icecast.ServerAddress = "http://serveraddress.com";
+ icecast.ServerPort = 8000;
+ icecast.Password = "password";
+ icecast.Mountpoint = "/mystream";
+ ...
+
+
+ ' create an encoder instance
+ Dim lame As New EncoderLAME(_recHandle)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
+ lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+
+ ' now create the ICEcast instance using LAME
+ Dim icecast As New ICEcast(lame)
+ icecast.ServerAddress = "http://serveraddress.com"
+ icecast.ServerPort = 8000
+ icecast.Password = "password"
+ icecast.Mountpoint = "/mystream"
+ ...
+
+
+ // create an encoder instance
+ EncoderLAME lame = new EncoderLAME(_recHandle);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_56;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono;
+ lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_22050;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+
+ // now create the ICEcast instance using LAME
+ ICEcast icecast = new ICEcast(lame, true);
+ icecast.ServerAddress = "http://serveraddress.com";
+ icecast.ServerPort = 8000;
+ icecast.Password = "password";
+ icecast.Mountpoint = "/mystream";
+ ...
+
+
+ ' create an encoder instance
+ Dim lame As New EncoderLAME(_recHandle)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
+ lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+
+ ' now create the ICEcast instance using LAME
+ Dim icecast As New ICEcast(lame, True)
+ icecast.ServerAddress = "http://serveraddress.com"
+ icecast.ServerPort = 8000
+ icecast.Password = "password"
+ icecast.Mountpoint = "/mystream"
+ ...
+
+
+ // create an encoder instance
+ EncoderWMA wma = new EncoderWMA(_recHandle);
+ wma.WMA_Bitrate = (int)EncoderWMA.BITRATE.kbps_64;
+ wma.WMA_UseNetwork = true;
+
+ // now create the WMAcast instance
+ WMAcast wmacast = new WMAcast(wma);
+ wmacast.ServerPort = 8080;
+ ...
+ wma.Start(null, IntPtr.Zero, true); // start paused
+ wma.Connect();
+ wma.Pause(false); // start encoding
+ Bass.BASS_ChannelPlay(_recHandle, false);
+ ...
+
+
+ ' create an encoder instance
+ Dim wma As New EncoderWMA(_recHandle)
+ wma.WMA_Bitrate = CInt(EncoderWMA.BITRATE.kbps_64)
+ wma.WMA_UseNetwork = True
+
+ ' now create the WMAcast instance
+ Dim wmacast As New WMAcast(wma)
+ wmacast.ServerPort = 8080
+ ...
+ wma.Start(Nothing, IntPtr.Zero, True) ' start paused
+ wma.Connect()
+ wma.Pause(False) ' start encoding
+ Bass.BASS_ChannelPlay(_recHandle, False)
+ ...
+
+
+ EncoderNeroAAC n = new EncoderNeroAAC(_recHandle);
+ n.InputFile = null;
+ n.OutputFile = "test.m4a";
+ n.NERO_Bitrate = 48;
+ n.Start(null, IntPtr.Zero, false);
+ // your recording will be encoded until you call...
+ n.Stop();
+
+
+ Dim n As New EncoderNeroAAC(_recHandle)
+ n.InputFile = Nothing
+ n.OutputFile = "test.m4a"
+ n.NERO_Bitrate = 48
+ n.Start(Nothing, IntPtr.Zero, False)
+ ' your recording will be encoded until you call...
+ n.Stop()
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_STREAM_DECODE);
+ EncoderLAME l = new EncoderLAME(stream);
+ l.InputFile = null; //STDIN
+ l.OutputFile = "test.mp3";
+ l.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_64;
+ l.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ l.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ l.Start(null, IntPtr.Zero, false);
+ // decode the stream (if not using a decoding channel, simply call "Bass.BASS_ChannelPlay" here)
+ byte[] encBuffer = new byte[65536]; // our dummy encoder buffer
+ while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ // getting sample data will automatically feed the encoder
+ int len = Bass.BASS_ChannelGetData(_stream, encBuffer, encBuffer.Length);
+ }
+ l.Stop(); // finish
+ Bass.BASS_StreamFree(stream);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_STREAM_DECODE)
+ Dim l As New EncoderLAME(stream)
+ l.InputFile = Nothing 'STDIN
+ l.OutputFile = "test.mp3"
+ l.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_64)
+ l.LAME_Mode = EncoderLAME.LAMEMode.Default
+ l.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ l.Start(Nothing, IntPtr.Zero, False)
+ ' decode the stream (if not using a decoding channel, simply call "Bass.BASS_ChannelPlay" here)
+ Dim encBuffer(65536) As Byte ' our dummy encoder buffer
+ While Bass.BASS_ChannelIsActive(stream) = BASSActive.BASS_ACTIVE_PLAYING
+ ' getting sample data will automatically feed the encoder
+ Dim len As Integer = Bass.BASS_ChannelGetData(_stream, encBuffer, encBuffer.Length)
+ End While
+ l.Stop() ' finish
+ Bass.BASS_StreamFree(stream)
+
+
+ EncoderOGG o = new EncoderOGG(0);
+ o.InputFile = "test.wav";
+ o.OutputFile = "test.ogg";
+ o.OGG_UseQualityMode = true;
+ o.OGG_Quality = 4;
+ BaseEncoder.EncodeFile(o, null, true, false, true);
+
+
+ Dim o As New EncoderOGG(0)
+ o.InputFile = "test.wav"
+ o.OutputFile = "test.ogg"
+ o.OGG_UseQualityMode = True
+ o.OGG_Quality = 4
+ BaseEncoder.EncodeFile(o, Nothing, True, False, True)
+
+
+ public class MyOwnEncoder : BaseEncoder
+ {
+ // Constructor
+ public MyOwnEncoder(int channel) : base(channel)
+ {
+ }
+
+ public override string ToString()
+ {
+ return "My Encoder (BASS_CTYPE_STREAM_MP3)";
+ }
+
+ public override string DefaultOutputExtension
+ {
+ get { return ".mp3"; }
+ }
+
+ public override BASSChannelType EncoderType
+ {
+ get { return BASSChannelType.BASS_CTYPE_STREAM_MP3; }
+ }
+
+ public override bool SupportsSTDOUT
+ {
+ get { return true; }
+ }
+
+ public override string EncoderCommandLine
+ {
+ get { return BuildEncoderCommandLine(); }
+ }
+
+ public override int EffectiveBitrate
+ {
+ get { return My_Bitrate; }
+ }
+
+ public override bool Start(ENCODEPROC proc, IntPtr user, bool paused)
+ {
+ if (EncoderHandle != 0 || (proc != null && !SupportsSTDOUT))
+ return false;
+ // start the encoder
+ BASSEncode flag = BASSEncode.BASS_ENCODE_NOHEAD;
+ if (Force16Bit)
+ flag |= BASSEncode.BASS_ENCODE_FP_16BIT;
+ if (paused)
+ flag |= BASSEncode.BASS_ENCODE_PAUSE;
+ EncoderHandle = BassEnc.BASS_Encode_Start(ChannelHandle, EncoderCommandLine,
+ flag, proc, user);
+ if (EncoderHandle == 0)
+ return false;
+ else
+ return true;
+ }
+
+ // local members for setting individual parameters
+ public int My_Bitrate = 128;
+
+ // just an example here!
+ private string BuildEncoderCommandLine()
+ {
+ CultureInfo enCI = new CultureInfo("en-US", false);
+ StringBuilder sb = new StringBuilder();
+ // the file name and path
+ sb.Append( Path.Combine( EncoderDirectory, "myencoder.exe" ) );
+ // raw input?
+ if (InputFile == null) // STDIN: add the raw pcm header data
+ sb.Append( String.Format( enCI, " -r -x -s {0:##0.0##} --bitwidth {1}",
+ ChannelSampleRate/1000f, ChannelBitwidth > 16 ? 16 : ChannelBitwidth ) );
+ // ...more options here...
+ sb.Append( String.Format( enCI, " -b {0} -h", My_Bitrate ) );
+ // STDIN or filename
+ if (InputFile != null)
+ sb.Append( " \""+InputFile+"\"" );
+ else
+ sb.Append( " -" );
+ // STDOUT or filename
+ if (OutputFile != null)
+ sb.Append( " \""+OutputFile+"\"" );
+ else
+ sb.Append( " -" );
+ return sb.ToString();
+ }
+ }
+
+
+ Public Class MyOwnEncoder Inherits BaseEncoder
+
+ ' Constructor
+ Public Sub New(channel As Integer) MyBase.New(channel)
+ End Sub
+
+ Public Overrides Function ToString() As String
+ Return "My Encoder (BASS_CTYPE_STREAM_MP3)"
+ End Function
+
+ Public Overrides ReadOnly Property DefaultOutputExtension() As String
+ Get
+ Return ".mp3"
+ End Get
+ End Property
+
+ Public Overrides ReadOnly Property EncoderType() As BASSChannelType
+ Get
+ Return BASSChannelType.BASS_CTYPE_STREAM_MP3
+ End Get
+ End Property
+
+ Public Overrides ReadOnly Property SupportsSTDOUT() As Boolean
+ Get
+ Return True
+ End Get
+ End Property
+
+ Public Overrides ReadOnly Property EncoderCommandLine() As String
+ Get
+ Return BuildEncoderCommandLine()
+ End Get
+ End Property
+
+ Public Overrides ReadOnly Property EffectiveBitrate() As Integer
+ Get
+ Return My_Bitrate
+ End Get
+ End Property
+
+ Public Overrides Function Start(proc As ENCODEPROC, user As IntPtr, paused As Boolean) As Boolean
+ If EncoderHandle <> 0 OrElse (Not (proc Is Nothing) AndAlso Not SupportsSTDOUT) Then
+ Return False
+ End If
+ ' start the encoder
+ Dim flag As BASSEncode = BASSEncode.BASS_ENCODE_NOHEAD
+ If Force16Bit Then
+ flag = flag Or BASSEncode.BASS_ENCODE_FP_16BIT
+ End If
+ If paused Then
+ flag = flag Or BASSEncode.BASS_ENCODE_PAUSE
+ End If
+ EncoderHandle = BassEnc.BASS_Encode_Start(ChannelHandle, EncoderCommandLine,
+ flag, proc, user)
+ End If
+ If EncoderHandle = 0 Then
+ Return False
+ Else
+ Return True
+ End If
+ End Function
+
+ ' local members for setting individual parameters
+ Public My_Bitrate As Integer = 128
+
+ ' just an example here!
+ Private Function BuildEncoderCommandLine() As String
+ Dim enCI As New CultureInfo("en-US", False)
+ Dim sb As New StringBuilder()
+ ' the file name and path
+ sb.Append(Path.Combine(EncoderDirectory, "myencoder.exe"))
+ ' raw input?
+ If InputFile Is Nothing Then ' STDIN: add the raw pcm header data
+ sb.Append([String].Format(enCI, " -r -x -s {0:##0.0##} --bitwidth {1}",
+ ChannelSampleRate / 1000F,(If ChannelBitwidth > 16 Then 16 Else ChannelBitwidth))) 'ToDo: Unsupported feature: conditional (?) operator.
+ End If ' ...more options here...
+ sb.Append([String].Format(enCI, " -b {0} -h", My_Bitrate))
+ ' STDIN or filename
+ If Not (InputFile Is Nothing) Then
+ sb.Append((" """ + InputFile + """"))
+ Else
+ sb.Append(" -")
+ End If ' STDOUT or filename
+ If Not (OutputFile Is Nothing) Then
+ sb.Append((" """ + OutputFile + """"))
+ Else
+ sb.Append(" -")
+ End If
+ Return sb.ToString()
+ End Function
+
+ End Class
+
+
+ EncoderWMA wma = new EncoderWMA(0);
+ wma.WMA_Bitrate = 128;
+ BaseEncoder.EncodeFile("test.wav", null, wma,
+ new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), true, false);
+
+ public void FileEncodingNotification(long bytesTotal, long bytesDone)
+ {
+ Console.Write("Encoding: {0:P}\r", Math.Round((double)bytesDone/(double)bytesTotal, 2));
+ }
+
+
+ Dim wma As New EncoderWMA(0)
+ wma.WMA_Bitrate = 128
+ BaseEncoder.EncodeFile("test.wav", Nothing, wma,
+ New BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), True, False)
+
+ Public Sub FileEncodingNotification(bytesTotal As Long, bytesDone As Long)
+ Console.Write("Encoding: {0:P}\r", Math.Round(CDbl(bytesDone) / CDbl(bytesTotal), 2))
+ End Sub
+
+ Encodes OGG input to an MP3 output using EncoderLAME (with the 'standard' preset):
+
+ EncoderLAME enc = new EncoderLAME(0);
+ enc.LAME_PresetName = "standard";
+ BaseEncoder.EncodeFile("test.ogg", null, enc, null, true, false);
+
+
+ Dim enc As New EncoderLAME(0)
+ enc.LAME_PresetName = "standard"
+ BaseEncoder.EncodeFile("test.ogg", Nothing, enc, Nothing, True, False)
+
+
+ EncoderWMA wma = new EncoderWMA(0);
+ wma.InputFile = "testin.ogg";
+ wma.OutputFile = "testout.wma";
+ wma.WMA_Bitrate = 128;
+ wma.WMA_UsePro = true;
+ BaseEncoder.EncodeFile(wma, new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), true, false);
+
+ public void FileEncodingNotification(long bytesTotal, long bytesDone)
+ {
+ Console.Write("Encoding: {0:P}\r", Math.Round((double)bytesDone/(double)bytesTotal, 2));
+ }
+
+
+ Dim wma As New EncoderWMA(0)
+ wma.InputFile = "testin.ogg"
+ wma.OutputFile = "testout.wma"
+ wma.WMA_Bitrate = 128
+ wma.WMA_UsePro = True
+ BaseEncoder.EncodeFile(wma, New BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), True, False)
+
+ Public Sub FileEncodingNotification(bytesTotal As Long, bytesDone As Long)
+ Console.Write("Encoding: {0:P}\r", Math.Round(CDbl(bytesDone) / CDbl(bytesTotal), 2))
+ End Sub
+
+
+ EncoderLAME lame = new EncoderLAME(0);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ lame.TAGs = BassTags.BASS_TAG_GetFromFile("testin.ogg", true, false);;
+ BaseEncoder.EncodeFile("testin.ogg", "testout.mp3", lame, null, true, false, true);
+
+
+ Dim lame As New EncoderLAME(0)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_192)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ lame.TAGs = BassTags.BASS_TAG_GetFromFile("testin.ogg", True, False)
+ BaseEncoder.EncodeFile("testin.ogg", "testout.mp3", lame, Nothing, True, False, True)
+
+
+ TAG_INFO tags = new TAG_INFO();
+ tags.artist = "The Artist";
+ tags.title = "The Title";
+
+ EncoderLAME lame = new EncoderLAME(0);
+ lame.InputFile = "test.ogg";
+ lame.TAGs = tags;
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ BaseEncoder.EncodeFile(lame,
+ new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), true, false, true);
+
+ public void FileEncodingNotification(long bytesTotal, long bytesDone)
+ {
+ Console.Write("Encoding: {0:P}\r", Math.Round((double)bytesDone/(double)bytesTotal, 2));
+ }
+
+
+ Dim tags As New TAG_INFO()
+ tags.artist = "The Artist"
+ tags.title = "The Title"
+
+ Dim lame As New EncoderLAME(0)
+ lame.InputFile = "test.ogg"
+ lame.TAGs = tags
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_192)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ BaseEncoder.EncodeFile(lame,
+ New BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), True, False, True)
+
+ Public Sub FileEncodingNotification(bytesTotal As Long, bytesDone As Long)
+ Console.Write("Encoding: {0:P}\r", Math.Round(CDbl(bytesDone) / CDbl(bytesTotal), 2))
+ End Sub
+
+
+ EncoderLAME lame = new EncoderLAME(0);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ BaseEncoder.EncodeFile("testin.ogg", "testout.mp3", lame, null, true, false, true, 4096, 61440);
+
+
+ Dim lame As New EncoderLAME(0)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_192)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ BaseEncoder.EncodeFile("testin.ogg", "testout.mp3", lame, Nothing, True, False, True, 4096, 61440)
+
+
+ EncoderLAME lame = new EncoderLAME(0);
+ lame.InputFile = "testin.ogg";
+ lame.OutputFile = "testout.mp3";
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ BaseEncoder.EncodeFile(lame,
+ new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification),
+ true, false, true, 4096, 61440);
+
+ public void FileEncodingNotification(long bytesTotal, long bytesDone)
+ {
+ Console.Write("Encoding: {0:P}\r", Math.Round((double)bytesDone/(double)bytesTotal, 2));
+ }
+
+
+ Dim lame As New EncoderLAME(0)
+ lame.InputFile = "testin.ogg"
+ lame.OutputFile = "testout.mp3"
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_192)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ BaseEncoder.EncodeFile(lame,
+ New BaseEncoder.ENCODEFILEPROC(FileEncodingNotification),
+ True, False, True, 4096, 61440)
+
+ Public Sub FileEncodingNotification(bytesTotal As Long, bytesDone As Long)
+ Console.Write("Encoding: {0:P}\r", Math.Round(CDbl(bytesDone) / CDbl(bytesTotal), 2))
+ End Sub
+
+
+ EncoderLAME lame = new EncoderLAME(0);
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ BaseEncoder.EncodeFile("testin.ogg", "testout.mp3", lame,
+ new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification),
+ true, false, true, 5.1f, 25.3f);
+
+ public void FileEncodingNotification(long bytesTotal, long bytesDone)
+ {
+ Console.Write("Encoding: {0:P}\r", Math.Round((double)bytesDone/(double)bytesTotal, 2));
+ }
+
+
+ Dim lame As New EncoderLAME(0)
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_192)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ BaseEncoder.EncodeFile("testin.ogg", "testout.mp3", lame,
+ New BaseEncoder.ENCODEFILEPROC(FileEncodingNotification),
+ True, False, True, 5.1F, 25.3F)
+
+ Public Sub FileEncodingNotification(bytesTotal As Long, bytesDone As Long)
+ Console.Write("Encoding: {0:P}\r", Math.Round(CDbl(bytesDone) / CDbl(bytesTotal), 2))
+ End Sub
+
+
+ EncoderLAME lame = new EncoderLAME(0);
+ lame.InputFile = "testin.ogg";
+ lame.OutputFile = "testout.mp3";
+ lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
+ BaseEncoder.EncodeFile(lame,
+ new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification),
+ true, false, true,
+ 5.1f, 25.3f);
+
+ public void FileEncodingNotification(long bytesTotal, long bytesDone)
+ {
+ Console.Write("Encoding: {0:P}\r", Math.Round((double)bytesDone/(double)bytesTotal, 2));
+ }
+
+
+ Dim lame As New EncoderLAME(0)
+ lame.InputFile = "testin.ogg"
+ lame.OutputFile = "testout.mp3"
+ lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_192)
+ lame.LAME_Mode = EncoderLAME.LAMEMode.Default
+ lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality
+ BaseEncoder.EncodeFile(lame,
+ New BaseEncoder.ENCODEFILEPROC(FileEncodingNotification),
+ True, False, True, 5.1F, 25.3F)
+
+ Public Sub FileEncodingNotification(bytesTotal As Long, bytesDone As Long)
+ Console.Write("Encoding: {0:P}\r", Math.Round(CDbl(bytesDone) / CDbl(bytesTotal), 2))
+ End Sub
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
+ EncoderWAV w = new EncoderWAV(stream);
+ w.InputFile = null;
+ w.OutputFile = "test.wav"; // will be a 32-bit IEEE float WAVE file, since the stream is float
+ w.Start(null, IntPtr.Zero, false);
+ // do the encoding
+ Utils.DecodeAllData(stream, true);
+ w.Stop();
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ Dim w As New EncoderWAV(stream)
+ w.InputFile = Nothing
+ w.OutputFile = "test.wav" ' will be a 32-bit IEEE float WAVE file, since the stream is float
+ w.Start(Nothing, IntPtr.Zero, False)
+ ' do the encoding
+ Utils.DecodeAllData(stream, True)
+ w.Stop()
+
+ Manual encoding "File" To "File" in 24-bit:
+
+ EncoderWAV w = new EncoderWAV(0);
+ w.InputFile = "testIn.wav";
+ w.OutputFile = "testOut.wav";
+ w.WAV_BitsPerSample = 24;
+ w.Start(null, IntPtr.Zero, false);
+ w.Stop();
+
+
+ Dim w As New EncoderWAV(0)
+ w.InputFile = "testIn.wav"
+ w.OutputFile = "testOut.wav"
+ w.WAV_BitsPerSample = 24
+ w.Start(Nothing, IntPtr.Zero, False)
+ w.Stop()
+
+ "Recording" To "File" in 16-bit:
+
+ private RECORDPROC _recProc;
+
+ // init your recording device (we use the default device)
+ if ( !Bass.BASS_RecordInit(-1) )
+ MessageBox.Show(this, "Bass_RecordInit error!" );
+ _recProc = new RECORDPROC(RecordingHandler);
+ // start recording at 44.1kHz, stereo (paused)
+ int recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _recProc, IntPtr.Zero);
+ if (recHandle == Bass.FALSE)
+ MessageBox.Show(this, "BASS_RecordStart error!" );
+
+ // setup the encoder
+ EncoderWAV w = new EncoderWAV(recHandle);
+ w.InputFile = null;
+ w.OutputFile = "testrec.wav";
+ w.Start(null, IntPtr.Zero, true); // start encoder paused
+ ...
+ // now really start recording and encoding
+ w.Pause(false);
+ Bass.BASS_ChannelPlay(recHandle, false);
+ ...
+ // your recording will be encoded until you call
+ w.Stop();
+
+ private bool RecordingHandler(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ return true;
+ }
+
+
+ private RECORDPROC _recProc;
+
+ ' init your recording device (we use the default device)
+ If Not Bass.BASS_RecordInit(- 1) Then
+ MessageBox.Show(Me, "Bass_RecordInit error!")
+ End If
+ _recProc = New RECORDPROC(AddressOf RecordingHandler)
+ ' start recording at 44.1kHz, stereo (paused)
+ Dim recHandle As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _recProc, IntPtr.Zero)
+ If recHandle = Bass.FALSE Then
+ MessageBox.Show(Me, "BASS_RecordStart error!")
+ End If
+
+ ' setup the encoder
+ Dim w As New EncoderWAV(recHandle)
+ w.InputFile = Nothing
+ w.OutputFile = "testrec.wav"
+ w.Start(Nothing, IntPtr.Zero, True) ' start encoder paused
+ ...
+ ' now really start recording and encoding
+ w.Pause(False)
+ Bass.BASS_ChannelPlay(recHandle, False)
+ ...
+ ' your recording will be encoded until you call
+ w.Stop()
+
+ Private Function RecordingHandler(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ Return True
+ End Function
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_STREAM_DECODE);
+ EncoderWMA wma = new EncoderWMA(stream);
+ wma.WMA_UseVBR = true;
+ wma.WMA_VBRQuality = 100; // lossless
+ wma.InputFile = null; //STDIN
+ wma.OutputFile = "test.wma";
+ wma.Start(null, IntPtr.Zero, false);
+ // encode all the data right away
+ Utils.DecodeAllData(stream, true);
+ wma.Stop();
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_STREAM_DECODE)
+ Dim wma As New EncoderWMA(stream)
+ wma.WMA_UseVBR = True
+ wma.WMA_VBRQuality = 100 ' lossless
+ wma.InputFile = Nothing 'STDIN
+ wma.OutputFile = "test.wma"
+ wma.Start(Nothing, IntPtr.Zero, False)
+ ' encode all the data right away
+ Utils.DecodeAllData(stream, True)
+ wma.Stop()
+
+ Automatic encoding to the local network (using a recording handle):
+
+ EncoderWMA wma = new EncoderWMA(_recHandle);
+ wma.WMA_UseVBR = false;
+ wma.WMA_Bitrate = 64;
+ wma.WMA_UsePro = true;
+ wma.WMA_UseNetwork = true;
+ wma.WMA_NetworkPort = 80;
+ wma.WMA_NetworkClients = 10;
+ wma.InputFile = null; //STDIN
+ wma.OutputFile = null; //STDOUT
+ wma.Start(null, IntPtr.Zero, false);
+ ...
+ // encodes until this is called
+ wma.Stop();
+
+
+ Dim wma As New EncoderWMA(_recHandle)
+ wma.WMA_UseVBR = False
+ wma.WMA_Bitrate = 64
+ wma.WMA_UsePro = True
+ wma.WMA_UseNetwork = True
+ wma.WMA_NetworkPort = 80
+ wma.WMA_NetworkClients = 10
+ wma.InputFile = Nothing 'STDIN
+ wma.OutputFile = Nothing 'STDOUT
+ wma.Start(Nothing, IntPtr.Zero, False)
+ ...
+ ' encodes until this is called
+ wma.Stop()
+
+
+ BassNet.Registration("your emai", "your registration code");
+ ...
+ Bass.Init(...);
+
+ Register BASS.NET, but show splash anyhow (for 30sec., center parent, 5% transparent):
+
+ BassNet.Registration("your email", "your registration code");
+ BassNet.ShowSplash(this, 30000, 0.95, 2);
+ ...
+ Bass.Init(...);
+
+
+ BassNet.Registration("your email", "your registration code")
+ BassNet.ShowSplash(Me, 30000, 0.95, 2)
+ ...
+ Bass.Init(...)
+
+
+ BassNet.Registration("your email", "your registration code");
+ BassNet.ShowSplash(this, 30000, 0.95, 2);
+ ...
+ Bass.Init(...);
+
+ Show splash (infinit until closed, center screen):
+
+ BassNet.Registration("your email", "your registration code");
+ BassNet.ShowSplash(null, -1, 1.0, 0);
+ ...
+ Bass.Init(...);
+
+
+ using System;
+ using Un4seen.Bass;
+
+ namespace MyFirstBass
+ {
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ // init BASS using the default output device
+ if ( Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) )
+ {
+ // create a stream channel from a file
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
+ if (stream != 0)
+ {
+ // play the stream channel
+ Bass.BASS_ChannelPlay(stream, false);
+ }
+ else
+ {
+ // error creating the stream
+ Console.WriteLine("Stream error: {0}", Bass.BASS_ErrorGetCode());
+ }
+
+ // wait for a key
+ Console.WriteLine("Press any key to exit");
+ Console.ReadKey(false);
+
+ // free the stream
+ Bass.BASS_StreamFree(stream);
+ // free BASS
+ Bass.BASS_Free();
+ }
+ }
+ }
+ }
+
+
+ Imports System
+ Imports Un4seen.Bass
+
+ Namespace MyFirstBass
+ Class Program
+ Shared Sub Main(ByVal args() As String)
+ ' init BASS using the default output device
+ If Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) Then
+ ' create a stream channel from a file
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT)
+ If stream <> 0 Then
+ ' play the stream channel
+ Bass.BASS_ChannelPlay(stream, False)
+ Else
+ ' error creating the stream
+ Console.WriteLine("Stream error: {0}", Bass.BASS_ErrorGetCode())
+ End If
+
+ ' wait for a key
+ Console.WriteLine("Press any key to exit")
+ Console.ReadKey(False)
+
+ ' free the stream
+ Bass.BASS_StreamFree(stream)
+ ' free BASS
+ Bass.BASS_Free()
+ End If
+ End Sub
+ End Class
+ End Namespace
+
+
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+
+
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+
+
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+
+
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+
+ Initialize BASS/DirectSound with A3D
+
+ Guid clsidA3d = new Guid(0xd8f1eee0, 0xf634, 0x11cf, 0x87, 0x0, 0x0, 0xa0, 0x24, 0x5d, 0x91, 0x8b);
+ Bass.BASS_Init(-1, 44100, 0, this.Handle, clsidA3d);
+
+
+ Dim clsidA3d As Guid = New Guid(0xd8f1eee0, 0xf634, 0x11cf, 0x87, 0x0, 0x0, 0xa0, 0x24, 0x5d, 0x91, 0x8b)
+ Bass.BASS_Init(-1, 44100, 0, Me.Handle, clsidA3d)
+
+
+ BASS_DEVICEINFO info = new BASS_DEVICEINFO();
+ for (int n=0; Bass.BASS_GetDeviceInfo(n, info); n++)
+ {
+ Console.WriteLine(info.ToString());
+ }
+
+
+ Dim n As Integer = 0
+ Dim info As New BASS_DEVICEINFO()
+ While (Bass.BASS_GetDeviceInfo(n, info))
+ Console.WriteLine(info.ToString())
+ n += 1
+ End While
+
+ Or use the
+ int defDevice = -1;
+ BASS_DEVICEINFO info;
+ for (int n = 0; (info = Bass.BASS_GetDeviceInfo(n)) != null; n++)
+ {
+ if (info.IsDefault)
+ {
+ defDevice = n;
+ break;
+ }
+ }
+
+
+ Dim defDevice As Integer = -1
+ Dim n As Integer = 0
+ Dim info As New BASS_DEVICEINFO()
+ While Not (info Is Nothing)
+ info = Bass.BASS_GetDeviceDescription(n)
+ If Not (info Is Nothing) And info.IsDefault Then
+ defDevice = n
+ Exit While
+ End If
+ n += 1
+ End While
+
+ Or use the
+ if ( Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle) )
+ {
+ BASS_INFO info = new BASS_INFO();
+ if (Bass.BASS_GetInfo(info))
+ Console.WriteLine( info.ToString() );
+ }
+
+
+ If Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle) Then
+ Dim info As New BASS_INFO()
+ If Bass.BASS_GetInfo(info) Then
+ Console.WriteLine(info.ToString())
+ End If
+ End If
+
+
+ if ( Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle) )
+ {
+ BASS_INFO info = Bass.BASS_GetInfo();
+ if (info != null && !info.SupportsDirectSound)
+ Console.WriteLine("Device does NOT have DirectSound support");
+ }
+
+
+ If Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle) Then
+ Dim info As BASS_INFO = Bass.BASS_GetInfo()
+ If info IsNot Nothing AndAlso Not info.SupportsDirectSound Then
+ Console.WriteLine("Device does NOT have DirectSound support")
+ End If
+ End If
+
+
+ // init device 1 and 2
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ ...
+ // create the stream for device 1
+ Bass.BASS_SetDevice(1);
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ ...
+ // create the stream for device 2
+ Bass.BASS_SetDevice(2);
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ ...
+ // free any initialized device
+ Bass.BASS_SetDevice(1);
+ Bass.BASS_Free();
+ Bass.BASS_SetDevice(2);
+ Bass.BASS_Free();
+
+
+ ' init device 1 and 2
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ ...
+ ' create the stream for device 1
+ Bass.BASS_SetDevice(1)
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ ' create the stream for device 2
+ Bass.BASS_SetDevice(2)
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ ...
+ ' free any initialized device
+ Bass.BASS_SetDevice(1)
+ Bass.BASS_Free()
+ Bass.BASS_SetDevice(2)
+ Bass.BASS_Free()
+
+
+ if ( Utils.HighWord(Bass.BASS_GetVersion()) != Bass.BASSVERSION )
+ {
+ MessageBox.Show(this, "Wrong Bass Version!");
+ }
+
+
+ If Utils.HighWord(Bass.BASS_GetVersion()) <> Bass.BASSVERSION Then
+ MessageBox.Show(Me, "Wrong Bass Version!")
+ End If
+
+ Checking for full version "2.4.1.3":
+
+ if (Bass.BASS_GetVersion() < Utils.MakeLong(0x0103, 0x0204))
+ {
+ MessageBox.Show(this, "Wrong Bass Version!");
+ }
+
+
+ If Bass.BASS_GetVersion() < Utils.MakeLong(&H103, &H204) Then
+ MessageBox.Show(Me, "Wrong Bass Version!")
+ End If
+
+
+ Version expectedVersion = new Version(2, 4);
+ if (Bass.BASS_GetVersion(2) < expectedVersion)
+ {
+ MessageBox.Show( this, "Wrong Bass Version!" );
+ }
+
+
+ Dim expectedVersion As New Version(2, 4)
+ If Bass.BASS_GetVersion(2) < expectedVersion Then
+ MessageBox.Show(Me, "Wrong Bass Version!")
+ End If
+
+
+ // init device 1 and 2
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ // now device 1 is the current one
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ // now device 2 is the current one
+ ...
+ // create the stream for device 1
+ Bass.BASS_SetDevice(1);
+ // now device 1 is the current one
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ ...
+ // create the stream for device 2
+ Bass.BASS_SetDevice(2);
+ // now device 2 is the current one
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ ...
+ // free any initialized device
+ Bass.BASS_SetDevice(1);
+ Bass.BASS_Free();
+ Bass.BASS_SetDevice(2);
+ Bass.BASS_Free();
+
+
+ ' init device 1 and 2
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ ' now device 1 is the current one
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ ' now device 2 is the current one
+ ...
+ ' create the stream for device 1
+ Bass.BASS_SetDevice(1)
+ ' now device 1 is the current one
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ ' create the stream for device 2
+ Bass.BASS_SetDevice(2)
+ ' now device 2 is the current one
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ ...
+ ' free any initialized device
+ Bass.BASS_SetDevice(1)
+ Bass.BASS_Free()
+ Bass.BASS_SetDevice(2)
+ Bass.BASS_Free()
+
+
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 100);
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20);
+
+
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 100)
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20)
+
+
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true);
+
+
+ Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, True)
+
+
+ public IntPtr _myUserAgentPtr;
+ ...
+ // create an unmanaged pointer containing a copy of the string
+ _myUserAgentPtr = Marshal.StringToHGlobalAnsi("radio42");
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr);
+ ...
+ // make sure to free the myUserAgentPtr!!!
+ // e.g. when you dispose your class or application
+ Marshal.FreeHGlobal(_myUserAgentPtr);
+
+
+ Public _myUserAgentPtr As IntPtr
+ ...
+ ' create an unmanaged pointer containing a copy of the string
+ _myUserAgentPtr = Marshal.StringToHGlobalAnsi("radio42")
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr)
+ ...
+ ' make sure to free the myUserAgentPtr!!!
+ ' e.g. when you dispose your class or application
+ Marshal.FreeHGlobal(_myUserAgentPtr)
+
+ If you need to dynamically change the BASS_CONFIG_NET_PROXY or BASS_CONFIG_NET_AGENT option,
+ you will need to call
+ public static string _myUserAgent = "radio42";
+ public IntPtr _myUserAgentPtr;
+ ...
+ // create an unmanaged pointer containing a copy of the string
+ _myUserAgentPtr = Marshal.StringToHGlobalAnsi(_myUserAgent);
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr);
+ ...
+ // change it to a new value,
+ // but first free the previous one
+ Marshal.FreeHGlobal(_myUserAgentPtr);
+ // then assign the new value
+ _myUserAgent = "new value";
+ _myUserAgentPtr = Marshal.StringToHGlobalAnsi(_myUserAgent);
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr);
+ ...
+ // make sure to free the myUserAgentPtr!!!
+ // e.g. when you dispose your class or application
+ Marshal.FreeHGlobal(_myUserAgentPtr);
+
+
+ Public Shared _myUserAgent As String = "radio42"
+ Public _myUserAgentPtr As IntPtr
+ ...
+ ' create an unmanaged pointer containing a copy of the string
+ _myUserAgentPtr = Marshal.StringToHGlobalAnsi(_myUserAgent)
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr)
+ ...
+ ' change it to a new value,
+ ' but first free the previous one
+ Marshal.FreeHGlobal(_myUserAgentPtr)
+ ' then assign the new value
+ _myUserAgent = "new value"
+ _myUserAgentPtr = Marshal.StringToHGlobalAnsi(_myUserAgent)
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr)
+ ...
+ ' make sure to free the myUserAgentPtr!!!
+ ' e.g. when you dispose your class or application
+ Marshal.FreeHGlobal(_myUserAgentPtr)
+
+ An alternative way of creating a pointer to a managed object and pinning it
+ is the use of GCHandle:
+
+ private GCHandle _userAgentGCH;
+ ...
+ string userAgent = "BASS.NET";
+ byte[] userAgentBytes = Encoding.Default.GetBytes(userAgent);
+ // create a pinned handle to our managed object
+ _userAgentGCH = GCHandle.Alloc(userAgentBytes, GCHandleType.Pinned);
+ // use the pointer to the string
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _userAgentGCH.AddrOfPinnedObject());
+ ...
+ // make sure to free the handle when you don't need it anymore!
+ // e.g. when you dispose your class or application
+ _userAgentGCH.Free();
+
+
+ Private _userAgentGCH As GCHandle
+ ...
+ Dim userAgent As String = "BASS.NET"
+ Dim userAgentBytes As Byte() = Encoding.Default.GetBytes(userAgent)
+ ' create a pinned handle to our managed object
+ _userAgentGCH = GCHandle.Alloc(userAgentBytes, GCHandleType.Pinned)
+ ' use the pointer to the string
+ Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _userAgentGCH.AddrOfPinnedObject())
+ ...
+ ' make sure to free the handle when you don't need it anymore!
+ ' e.g. when you dispose your class or application
+ _userAgentGCH.Free()
+
+
+ int bufLen = Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER);
+
+
+ Dim bufLen As Integer = Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER)
+
+
+ bool floatDSP = Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP);
+
+
+ Dim floatDSP As Boolean = Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP)
+
+
+ string userAgent = String.Empty;
+ IntPtr p = Bass.BASS_GetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT);
+ if (p != IntPtr.Zero)
+ {
+ userAgent = Marshal.PtrToStringAnsi(p);
+ }
+
+
+ Dim userAgent As String = [String].Empty
+ Dim p As IntPtr = Bass.BASS_GetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT)
+ If p <> IntPtr.Zero Then
+ userAgent = Marshal.PtrToStringAnsi(p)
+ End If
+
+
+ string userAgent = Bass.BASS_GetConfigString(BASSConfig.BASS_CONFIG_NET_AGENT);
+ if (userAgent != null)
+ {
+ ...
+ }
+
+
+ Dim userAgent As String = Bass.BASS_GetConfigString(BASSConfig.BASS_CONFIG_NET_AGENT)
+ If Not (userAgent Is Nothing) Then
+ ...
+ End If
+
+
+ // load the FLAC add-on
+ int pluginFlac = Bass.BASS_PluginLoad("bassflac.dll");
+ ...
+ // use the add-on
+ int stream = Bass.BASS_StreamCreateFile("file.flac", 0, 0, BASSFlag.BASS_DEFAULT);
+ ...
+ // un-load the FLAC add-on
+ Bass.BASS_PluginFree(pluginFlac);
+
+
+ ' load the FLAC add-on
+ Dim pluginFlac As Integer = Bass.BASS_PluginLoad("bassflac.dll")
+ ...
+ ' use the add-on
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("file.flac", 0, 0, BASSFlag.BASS_DEFAULT)
+ ...
+ ' un-load the FLAC add-on
+ Bass.BASS_PluginFree(pluginFlac)
+
+
+ // load the FLAC add-on
+ int pluginFlac = Bass.BASS_PluginLoad("bassflac.dll");
+ ...
+ // use the add-on
+ int stream = Bass.BASS_StreamCreateFile("file.flac", 0, 0, BASSFlag.BASS_DEFAULT);
+ ...
+ // un-load the FLAC add-on
+ Bass.BASS_PluginFree(pluginFlac);
+
+
+ ' load the FLAC add-on
+ Dim pluginFlac As Integer = Bass.BASS_PluginLoad("bassflac.dll")
+ ...
+ ' use the add-on
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("file.flac", 0, 0, BASSFlag.BASS_DEFAULT)
+ ...
+ ' un-load the FLAC add-on
+ Bass.BASS_PluginFree(pluginFlac)
+
+
+ Dictionary<int, string> loadedPlugIns = Bass.BASS_PluginLoadDirectory("C:\\BASS");
+ if (loadedPlugIns != null)
+ {
+ foreach (string file in loadedPlugIns.Values)
+ Console.Writeln( file );
+ }
+
+
+ Dim loadedPlugIns As Dictionary(Of Integer, String) = Bass.BASS_PluginLoadDirectory("C:\BASS")
+ If Not (loadedPlugIns Is Nothing) Then
+ Dim file As String
+ For Each file In loadedPlugIns.Values
+ Console.Writeln(file)
+ Next file
+ End If
+
+
+ int pluginFlac = Bass.BASS_PluginLoad("bassflac.dll");
+ BASS_PLUGININFO info = Bass.BASS_PluginGetInfo(pluginFlac);
+ foreach (BASS_PLUGINFORM f in info.formats)
+ Console.WriteLine("Type={0}, Name={1}, Exts={2}", f.ctype, f.name, f.exts);
+
+
+ Dim pluginFlac As Integer = Bass.BASS_PluginLoad("bassflac.dll")
+ Dim info As BASS_PLUGININFO = Bass.BASS_PluginGetInfo(pluginFlac)
+ Dim f As BASS_PLUGINFORM
+ For Each f In info.formats
+ Console.WriteLine("Type={0}, Name={1}, Exts={2}", f.ctype, f.name, f.exts)
+ Next f
+
+
+ EAXEnvironment env = EAXEnvironment.EAX_ENVIRONMENT_LEAVECURRENT;
+ float vol = 0f;
+ float decay = 0f;
+ float damp = 0f;
+ if (Bass.BASS_GetEAXParameters(ref env, ref vol, ref decay, ref damp))
+ Console.WriteLine("Env={0}, Vol={1}, Decay={2}, Damp={3}", env, vol, decay, damp);
+
+
+ Dim env As EAXEnvironment = EAXEnvironment.EAX_ENVIRONMENT_LEAVECURRENT
+ Dim vol As Single = 0F
+ Dim decay As Single = 0F
+ Dim damp As Single = 0F
+ If Bass.BASS_GetEAXParameters(env, vol, decay, damp) Then
+ Console.WriteLine("Env={0}, Vol={1}, Decay={2}, Damp={3}", env, vol, decay, damp)
+ End If
+
+
+ object env = EAXEnvironment.EAX_ENVIRONMENT_LEAVECURRENT;
+ object vol = 0f;
+ if ( Bass.BASS_GetEAXParameters( env, vol, null, null ) )
+ {
+ // env needs to be casted back to an EAXEnvironment
+ // vol needs to be casted back to float
+ Console.WriteLine( "Env={0}, Vol={1}", (EAXEnvironment)env, (float)vol );
+ }
+ else
+ Console.WriteLine( "Bass_Init error OR Device does not support EAX!" );
+
+
+ Dim env As Object = EAXEnvironment.EAX_ENVIRONMENT_LEAVECURRENT
+ Dim vol As Object = 0F
+ If Bass.BASS_GetEAXParameters(env, vol, Nothing, Nothing) Then
+ ' env needs to be casted back to an EAXEnvironment
+ ' vol needs to be casted back to float
+ Console.WriteLine("Env={0}, Vol={1}", CType(env, EAXEnvironment), CSng(vol))
+ Else
+ Console.WriteLine("Bass_Init error OR Device does not support EAX!")
+ End If
+
+
+ Bass.BASS_SetEAXParameters( EAXEnvironment.EAX_ENVIRONMENT_LEAVECURRENT, 0.3f, 1f, -1f );
+
+
+ Bass.BASS_SetEAXParameters( EAXEnvironment.EAX_ENVIRONMENT_LEAVECURRENT, 0.3F, 1F, -1F )
+
+
+ Bass.BASS_SetEAXParameters(EAXPreset.EAX_PRESET_ARENA);
+
+
+ Bass.BASS_SetEAXParameters(EAXPreset.EAX_PRESET_ARENA)
+
+
+ Bass.BASS_Set3DFactors(0.9144f, -1f, -1f);
+ Bass.BASS_Apply3D(); // apply the change
+
+
+ Bass.BASS_Set3DFactors(0.9144F, -1F, -1F)
+ Bass.BASS_Apply3D() ' apply the change
+
+
+ float distf = 0f;
+ float rollf = 0f;
+ float doppf = 0f;
+ Bass.BASS_Get3DFactors(ref distf, ref rollf, ref doppf);
+
+
+ Dim distf As Single = 0F
+ Dim rollf As Single = 0F
+ Dim doppf As Single = 0F
+ Bass.BASS_Get3DFactors(distf, rollf, doppf)
+
+
+ object distf = 0f;
+ Bass.BASS_Get3DFactors(distf, null, null);
+ float distanceFactor = (float)distf;
+
+
+ Dim distf As Object = 0F
+ Bass.BASS_Get3DFactors(distf, Nothing, Nothing)
+ Dim distanceFactor As Single = CSng(distf)
+
+
+ BASS_3DVECTOR pos = new BASS_3DVECTOR();
+ Bass.BASS_Set3DPosition(pos, null, null, null);
+
+
+ Dim pos As New BASS_3DVECTOR()
+ Bass.BASS_Set3DPosition(pos, Nothing, Nothing, Nothing)
+
+ Updates the position, velocity and top of the listener:
+
+ BASS_3DVECTOR position = new BASS_3DVECTOR(camera.RealPosition.x, camera.RealPosition.y, camera.RealPosition.z);
+ BASS_3DVECTOR direction = new BASS_3DVECTOR(camera.RealDirection.x, camera.RealDirection.y, camera.RealDirection.z);
+ BASS_3DVECTOR up = new BASS_3DVECTOR(-camera.RealUp.x, -camera.RealUp.y, -camera.RealUp.z);
+
+ if (!Bass.BASS_Set3DPosition(position, velocity, direction, up))
+ throw new AudioException("Could not set the 3d position of the listener", "listener", Bass.BASS_ErrorGetCode());
+
+ Bass.BASS_Apply3D();
+
+
+ Dim position As New BASS_3DVECTOR(camera.RealPosition.x, camera.RealPosition.y, camera.RealPosition.z)
+ Dim direction As New BASS_3DVECTOR(camera.RealDirection.x, camera.RealDirection.y, camera.RealDirection.z)
+ Dim up As New BASS_3DVECTOR(-camera.RealUp.x, -camera.RealUp.y, -camera.RealUp.z)
+
+ If Not Bass.BASS_Set3DPosition(position, velocity, direction, up) Then
+ Throw New AudioException("Could not set the 3d position of the listener", "listener", Bass.BASS_ErrorGetCode())
+ End If
+
+ Bass.BASS_Apply3D()
+
+
+ BASS_3DVECTOR pos = new BASS_3DVECTOR();
+ Bass.BASS_Get3DPosition(pos, null, null, null);
+
+
+ Dim pos As New BASS_3DVECTOR()
+ Bass.BASS_Get3DPosition(pos, Nothing, Nothing, Nothing)
+
+ Updates the position, velocity and top of the listener:
+
+ BASS_3DVECTOR position = new BASS_3DVECTOR(camera.RealPosition.x, camera.RealPosition.y, camera.RealPosition.z);
+ BASS_3DVECTOR direction = new BASS_3DVECTOR(camera.RealDirection.x, camera.RealDirection.y, camera.RealDirection.z);
+ BASS_3DVECTOR up = new BASS_3DVECTOR(-camera.RealUp.x, -camera.RealUp.y, -camera.RealUp.z);
+
+ if (!Bass.BASS_Set3DPosition(position, velocity, direction, up))
+ throw new AudioException("Could not set the 3d position of the listener", "listener", Bass.BASS_ErrorGetCode());
+
+ Bass.BASS_Apply3D();
+
+
+ Dim position As New BASS_3DVECTOR(camera.RealPosition.x, camera.RealPosition.y, camera.RealPosition.z)
+ Dim direction As New BASS_3DVECTOR(camera.RealDirection.x, camera.RealDirection.y, camera.RealDirection.z)
+ Dim up As New BASS_3DVECTOR(-camera.RealUp.x, -camera.RealUp.y, -camera.RealUp.z)
+
+ If Not Bass.BASS_Set3DPosition(position, velocity, direction, up) Then
+ Throw New AudioException("Could not set the 3d position of the listener", "listener", Bass.BASS_ErrorGetCode())
+ End If
+
+ Bass.BASS_Apply3D()
+
+
+ int sample = Bass.BASS_SampleLoad("test.wav", 0L, 0, 1, BASSFlag.BASS_DEFAULT);
+ int channel = Bass.BASS_SampleGetChannel(sample, false); // get a sample channel
+ Bass.BASS_ChannelPlay(channel, false); // play it
+
+
+ Dim sample As Integer = Bass.BASS_SampleLoad("test.wav", 0L.ToUInt32(), 0, 1, BASSFlag.BASS_DEFAULT)
+ Dim channel As Integer = Bass.BASS_SampleGetChannel(sample, False) ' get a sample channel
+ Bass.BASS_ChannelPlay(channel, False) ' play it
+
+
+ // create the sample
+ int sample = Bass.BASS_SampleCreate(256, 28160, 1, 1,
+ BASSFlag.BASS_SAMPLE_LOOP | BASSFlag.BASS_SAMPLE_OVER_POS );
+ // the data buffer (256 byte = 128 Int16)
+ short[] data = new short[128];
+ // create the sine wave
+ for (int a=0; a<128; a++)
+ data[a] = (short)(32767.0 * Math.Sin((double)a * 6.283185 / 64d));
+ // set the sample's data
+ Bass.BASS_SampleSetData(sample, data);
+ // get a sample channel
+ int channel = Bass.BASS_SampleGetChannel(sample, false);
+ // play it
+ Bass.BASS_ChannelPlay(channel, false);
+
+
+ ' create the sample
+ Dim sample As Integer = Bass.BASS_SampleCreate(256, 28160, 1, 1, BASSFlag.BASS_SAMPLE_LOOP Or BASSFlag.BASS_SAMPLE_OVER_POS)
+ ' the data buffer (256 byte = 128 Int16)
+ Dim data(128 - 1) As Short
+ ' create the sine wave
+ Dim a As Integer
+ For a = 0 To 127
+ data(a) = CShort(32767.0 * Math.Sin((CDbl(a) * 6.283185 / 64.0)))
+ Next a
+ ' set the sample's data
+ Bass.BASS_SampleSetData(sample, data)
+ ' get a sample channel
+ Dim channel As Integer = Bass.BASS_SampleGetChannel(sample, False)
+ ' play it
+ Bass.BASS_ChannelPlay(channel, False)
+
+
+ BASS_SAMPLE info = Bass.BASS_SampleGetInfo(sample);
+ float[] buffer = new float[info.length/4];
+ Bass.BASS_SampleGetData(sample, buffer);
+
+
+ Dim info As BASS_SAMPLE = Bass.BASS_SampleGetInfo(sample)
+ Dim buffer(info.length/4 - 1) As Single
+ Bass.BASS_SampleGetData(sample, buffer)
+
+
+ BASS_SAMPLE info = Bass.BASS_SampleGetInfo(sample);
+ short[] buffer = new short[info.length/2];
+ Bass.BASS_SampleGetData(sample, buffer);
+
+
+ Dim info As BASS_SAMPLE = Bass.BASS_SampleGetInfo(sample)
+ Dim buffer(info.length/2 - 1) As Short
+ Bass.BASS_SampleGetData(sample, buffer)
+
+
+ BASS_SAMPLE info = Bass.BASS_SampleGetInfo(sample);
+ byte[] buffer = new byte[info.length];
+ Bass.BASS_SampleGetData(sample, buffer);
+
+
+ Dim info As BASS_SAMPLE = Bass.BASS_SampleGetInfo(sample)
+ Dim buffer(info.length - 1) As Byte
+ Bass.BASS_SampleGetData(sample, buffer)
+
+
+ int sample = Bass.BASS_SampleLoad("test.wav", 0L, 0, 1, BASSFlag.BASS_DEFAULT);
+ int channel = Bass.BASS_SampleGetChannel(sample, false); // get a sample channel
+ Bass.BASS_ChannelPlay(channel, false); // play it
+ ...
+ // when done
+ Bass.BASS_SampleFree(sample);
+
+
+ Dim sample As Integer = Bass.BASS_SampleLoad("test.wav", 0L.ToUInt32(), 0, 1, BASSFlag.BASS_DEFAULT)
+ Dim channel As Integer = Bass.BASS_SampleGetChannel(sample, False) ' get a sample channel
+ Bass.BASS_ChannelPlay(channel, False) ' play it
+ ...
+ ' when done
+ Bass.BASS_SampleFree(sample)
+
+
+ BASS_SAMPLE info = new BASS_SAMPLE();
+ bool ok = Bass.BASS_SampleGetInfo(sample, info);
+
+
+ Dim info As New BASS_SAMPLE()
+ Dim ok As Boolean = Bass.BASS_SampleGetInfo(sample, info)
+
+
+ BASS_SAMPLE info = Bass.BASS_SampleGetInfo(sample);
+
+
+ Dim info As BASS_SAMPLE = Bass.BASS_SampleGetInfo(sample)
+
+
+ BASS_SAMPLE info = new BASS_SAMPLE(44100, 100, 0, ...);
+ bool ok = Bass.BASS_SampleSetInfo(sample, info);
+
+
+ Dim info As New BASS_SAMPLE(44100, 100, 0, ...)
+ Dim ok As Boolean = Bass.BASS_SampleSetInfo(sample, info)
+
+
+ int sample = Bass.BASS_SampleLoad("test.wav", 0L, 0, 1, BASSFlag.BASS_DEFAULT);
+ int channel = Bass.BASS_SampleGetChannel(sample, false); // get a sample channel
+ Bass.BASS_ChannelPlay(channel, false); // play it
+
+
+ Dim sample As Integer = Bass.BASS_SampleLoad("test.wav", 0L.ToUInt32(), 0, 1, BASSFlag.BASS_DEFAULT)
+ Dim channel As Integer = Bass.BASS_SampleGetChannel(sample, False) ' get a sample channel
+ Bass.BASS_ChannelPlay(channel, False) ' play it
+
+
+ // get sample info for "max" value
+ BASS_SAMPLE info = Bass.BASS_SampleGetInfo(handle);
+ // allocate channels array
+ int[] chans = new int[info.max];
+ // get the channels
+ int count = Bass.BASS_SampleGetChannels(handle, chans);
+ // go through them all and...
+ for (int a=0; a<count; a++)
+ {
+ // set the sample rate to 10000
+ Bass.BASS_ChannelSetAttribute(chans[a], BASSAttribute.BASS_ATTRIB_FREQ, 10000f);
+ }
+
+
+ ' get sample info for "max" value
+ Dim info As BASS_SAMPLE = Bass.BASS_SampleGetInfo(handle)
+ ' allocate channels array
+ Dim chans(info.max) As Integer
+ ' get the channels
+ Dim count As Integer = Bass.BASS_SampleGetChannels(handle, hGC.AddrOfPinnedObject())
+ ' go through them all and...
+ Dim a As Integer
+ For a = 0 To count - 1
+ ' set the sample rate to 10000
+ Bass.BASS_ChannelSetAttribute(chans(a), BASSAttribute.BASS_ATTRIB_FREQ, 10000F)
+ Next a
+
+
+ int[] chans = Bass.BASS_SampleGetChannels(handle);
+ if (chans != null)
+ {
+ // go through them all and...
+ for (int a=0; a<chans.Length; a++)
+ {
+ // set the sample rate to 10000
+ Bass.BASS_ChannelSetAttribute(chans[a], BASSAttribute.BASS_ATTRIB_FREQ, 10000f);
+ }
+ }
+
+
+ Dim chans As Integer() = Bass.BASS_SampleGetChannels(handle)
+ If Not (chans Is Nothing) Then
+ ' go through them all and...
+ Dim a As Integer
+ For a = 0 To chans.Length - 1
+ ' set the sample rate to 10000
+ Bass.BASS_ChannelSetAttribute(chans(a), BASSAttribute.BASS_ATTRIB_FREQ, 10000F)
+ Next a
+ End If
+
+
+ private STREAMPROC _myStreamCreate; // make it global, so that the GC can not remove it
+ private byte[] _data = null; // our local buffer
+ ...
+ _myStreamCreate = new STREAMPROC(MyFileProc);
+ FileStream fs = File.OpenRead("test.raw");
+ int channel = Bass.BASS_StreamCreate(44100, 2,
+ BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(channel, false);
+ ...
+ private int MyFileProc(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ // implementing the callback for BASS_StreamCreate...
+ // here we need to deliver PCM sample data
+
+ // increase the data buffer as needed
+ if (_data == null || _data.Length < length)
+ _data = new byte[length];
+
+ int bytesread = _fs.Read( _data, 0, length );
+ Marshal.Copy( _data, 0, buffer, bytesread );
+ if ( bytesread < length )
+ {
+ // set indicator flag
+ bytesread |= (int)BASSStreamProc.BASS_STREAMPROC_END;
+ _fs.Close();
+ }
+ return bytesread;
+ }
+
+
+ Private _myStreamCreate As STREAMPROC ' make it global, so that the GC can not remove it
+ Private _data As Byte() = Nothing ' our local buffer
+ ...
+ _myStreamCreate = New STREAMPROC(AddressOf MyFileProc)
+ Dim fs As FileStream = File.OpenRead("test.raw")
+ Dim channel As Integer = Bass.BASS_StreamCreate(44100, 2,
+ BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(channel, False)
+ ...
+ Private Function MyFileProc(ByVal handle As Integer, ByVal buffer As IntPtr,
+ ByVal length As Integer, ByVal user As IntPtr) As Integer
+ ' implementing the callback for BASS_StreamCreate...
+ ' here we need to deliver PCM sample data
+
+ ' increase the data buffer as needed
+ If _data = Nothing OrElse _data.Length < length Then
+ _data = New Byte(length) {}
+ End If
+
+ Dim bytesread As Integer = _fs.Read(_data, 0, length)
+ Marshal.Copy(_data, 0, buffer, bytesread)
+ If bytesread < length Then
+ bytesread = bytesread Or CInt(BASSStreamProc.BASS_STREAMPROC_END) ' set indicator flag
+ _fs.Close()
+ EndIf
+ Return bytesread
+ End Function
+
+
+ private DSPPROC _dupCallback;
+ ...
+ // create stream on device 1
+ Bass.BASS_SetDevice(1);
+ int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
+ Bass.BASS_ChannelPlay(orig, false);
+ ...
+ // create a clone on device 2
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ Bass.BASS_SetDevice(2);
+ int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
+ // pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream);
+ int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
+ byte[] buf = new byte[c];
+ Bass.BASS_ChannelGetData(stream, buf, c);
+ Bass.BASS_StreamPutData(clone, buf, c);
+ // set DSP to copy new data from source stream
+ _dupCallback = new DSPPROC(DupDSP);
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
+ Bass.BASS_ChannelPlay(orig, false); // resume source
+ Bass.BASS_ChannelPlay(clone, false); // play clone
+ ...
+ private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _dupCallback As DSPPROC
+ ...
+ ' create stream on device 1
+ Bass.BASS_SetDevice(1)
+ Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
+ Bass.BASS_ChannelPlay(orig, False)
+ ...
+ ' create a clone on device 2
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ Bass.BASS_SetDevice(2)
+ Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
+ ' pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream)
+ Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
+ Dim buf(c) As Byte
+ Bass.BASS_ChannelGetData(stream, buf, c)
+ Bass.BASS_StreamPutData(clone, buf, c)
+ ' set DSP to copy new data from source stream
+ _dupCallback = New DSPPROC(DupDSP)
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
+ Bass.BASS_ChannelPlay(orig, False) ' resume source
+ Bass.BASS_ChannelPlay(clone, False) ' play clone
+ ...
+ Private Sub DupDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ void Connect()
+ {
+ bufferobj = new Buffer();
+ stream = BASS_StreamCreateFileUser(STREAMFILE_BUFFERPUSH, ...);
+ lock
+ {
+ BASS_StreamPutData(stream, ...); // feed remaining buffered data
+ bufferobj = NULL; // don't need the buffer anymore
+ }
+ }
+
+ void OnReceiveData(pointer buffer, int length)
+ {
+ lock
+ {
+ if (bufferobj)
+ bufferobj.Write(buffer, length);
+ else
+ BASS_StreamPutData(stream, buffer, length);
+ }
+ }
+
+ int FileReadProc(pointer buffer, int length, pointer user)
+ {
+ int todo = length;
+ while (TRUE)
+ {
+ lock
+ {
+ done = bufferobj.Read(buffer, todo);
+ }
+ buffer += done; // move pointer
+ todo -= done;
+ if (todo == 0)
+ break;
+ if (!bufferobj.WaitForData(timeout)) // wait for more data
+ break; // timed-out (or perhaps EOF)
+ }
+ return length - todo;
+ }
+
+
+ // Init Bass
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ // create the stream
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
+ if (stream != 0 && Bass.BASS_ChannelPlay(stream, false) )
+ {
+ // playing
+ }
+ else
+ {
+ Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode());
+ }
+
+
+ ' Init Bass
+ Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ ' create the stream
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_PRESCAN)
+ If stream <> 0 AndAlso Bass.BASS_ChannelPlay(stream, False) Then
+ ' playing
+ Else
+ Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode())
+ End If
+
+
+ private GCHandle _hGCFile;
+ ...
+ // open a file
+ FileStream fs = File.OpenRead( "test.mp3" );
+ // get the legth of the file
+ long length = fs.Length;
+ // create the buffer which will keep the file in memory
+ byte[] buffer = new byte[length];
+ // read the file into the buffer
+ fs.Read(buffer, 0, (int)length);
+ // buffer is filled, file can be closed
+ fs.Close();
+
+ // now create a pinned handle, so that the Garbage Collector will not move this object
+ _hGCFile = GCHandle.Alloc( buffer, GCHandleType.Pinned );
+ // create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
+ int stream = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(),
+ 0L, length, BASSFlag.BASS_SAMPLE_FLOAT);
+
+ if (stream != 0 && Bass.BASS_ChannelPlay(stream, false) )
+ {
+ // playing...
+ }
+ else
+ {
+ Console.WriteLine("Error = {0}", Bass.BASS_ErrorGetCode());
+ }
+ ...
+ // when playback has ended and the pinned object is not needed anymore,
+ // we need to free the handle!
+ // Note: calling this method to early will crash the application,
+ // since the buffer would be stolen from BASS while still playing!
+ _hGCFile.Free();
+
+
+ Private _hGCFile As GCHandle
+ ...
+ ' open a file
+ Dim fs As FileStream = File.OpenRead("test.mp3")
+ ' get the legth of the file
+ Dim length As Long = fs.Length
+ ' create the buffer which will keep the file in memory
+ Dim buffer(length - 1) As Byte
+ ' read the file into the buffer
+ fs.Read(buffer, 0, length)
+ ' buffer is filled, file can be closed
+ fs.Close()
+
+ ' now create a pinned handle, so that the Garbage Collector will not move this object
+ _hGCFile = GCHandle.Alloc(buffer, GCHandleType.Pinned)
+ ' create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
+ Dim stream As Integer = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(),
+ 0L, length, BASSFlag.BASS_SAMPLE_FLOAT)
+
+ If stream <> 0 AndAlso Bass.BASS_ChannelPlay(stream, False) Then
+ ' playing...
+ Else
+ Console.WriteLine("Error = {0}", Bass.BASS_ErrorGetCode())
+ End If
+ ...
+ ' when playback has ended and the pinned object is not needed anymore,
+ ' we need to free the handle!
+ ' Note: calling this method to early will crash the application,
+ ' since the buffer would be stolen from BASS while still playing!
+ _hGCFile.Free()
+
+
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ int channel = Bass.BASS_StreamCreateURL("http://someurl.com:8000", 0,
+ BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(channel, false);
+
+
+ Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ Dim channel As Integer = Bass.BASS_StreamCreateURL("http://someurl.com:8000", 0,
+ BASSFlag.BASS_DEFAULT, Nothing, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(channel, False)
+
+
+ float progress;
+ // file length
+ int len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END);
+ // download progress
+ int down = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD);
+ // get channel info
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ // streaming in blocks?
+ if (info.flags & BASSFlag.BASS_STREAM_BLOCK != BASSFlag.BASS_DEFAULT)
+ {
+ // decode position
+ int dec = BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT);
+ // percentage of buffer used
+ progress = (down-dec)*100f / len;
+ if (progress > 100)
+ progress = 100; // restrict to 100 (can be higher)
+ }
+ else
+ {
+ // percentage of file downloaded
+ progress = down*100f / len;
+ }
+
+
+ Dim progress As Single
+ ' file length
+ Dim len As Integer = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END)
+ ' download progress
+ Dim down As Integer = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD)
+ ' get channel info
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ ' streaming in blocks?
+ If info.flags And BASSFlag.BASS_STREAM_BLOCK <> BASSFlag.BASS_DEFAULT Then
+ ' decode position
+ Dim dec As Integer = BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
+ ' percentage of buffer used
+ progress =(down - dec) * 100F / len
+ If progress > 100 Then
+ progress = 100 ' restrict to 100 (can be higher)
+ End If
+ Else
+ ' percentage of file downloaded
+ progress = down * 100F / len
+ End If
+
+ Get the average bitrate of a file:
+
+ // playback duration
+ double time = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream));
+ // file length
+ long len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END);
+ // bitrate (kbps)
+ int bitrate = (int)(len/(125*time)+0.5d);
+
+
+ ' playback duration
+ Dim time As Double = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))
+ ' file length
+ Dim len As Long = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END)
+ ' bitrate (kbps)
+ Dim bitrate As Integer = CInt(len /(125 * time) + 0.5)
+
+
+ private DSPPROC _dupCallback;
+ ...
+ // create stream on device 1
+ Bass.BASS_SetDevice(1);
+ int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
+ Bass.BASS_ChannelPlay(orig, false);
+ ...
+ // create a clone on device 2
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ Bass.BASS_SetDevice(2);
+ int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
+ // pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream);
+ int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
+ byte[] buf = new byte[c];
+ Bass.BASS_ChannelGetData(stream, buf, c);
+ Bass.BASS_StreamPutData(clone, buf, c);
+ // set DSP to copy new data from source stream
+ _dupCallback = new DSPPROC(DupDSP);
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
+ Bass.BASS_ChannelPlay(orig, false); // resume source
+ Bass.BASS_ChannelPlay(clone, false); // play clone
+ ...
+ private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _dupCallback As DSPPROC
+ ...
+ ' create stream on device 1
+ Bass.BASS_SetDevice(1)
+ Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
+ Bass.BASS_ChannelPlay(orig, False)
+ ...
+ ' create a clone on device 2
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ Bass.BASS_SetDevice(2)
+ Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
+ ' pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream)
+ Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
+ Dim buf(c) As Byte
+ Bass.BASS_ChannelGetData(stream, buf, c)
+ Bass.BASS_StreamPutData(clone, buf, c)
+ ' set DSP to copy new data from source stream
+ _dupCallback = New DSPPROC(DupDSP)
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
+ Bass.BASS_ChannelPlay(orig, False) ' resume source
+ Bass.BASS_ChannelPlay(clone, False) ' play clone
+ ...
+ Private Sub DupDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ private DSPPROC _dupCallback;
+ ...
+ // create stream on device 1
+ Bass.BASS_SetDevice(1);
+ int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
+ Bass.BASS_ChannelPlay(orig, false);
+ ...
+ // create a clone on device 2
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ Bass.BASS_SetDevice(2);
+ int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
+ // pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream);
+ int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
+ byte[] buf = new byte[c];
+ Bass.BASS_ChannelGetData(stream, buf, c);
+ Bass.BASS_StreamPutData(clone, buf, c);
+ // set DSP to copy new data from source stream
+ _dupCallback = new DSPPROC(DupDSP);
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
+ Bass.BASS_ChannelPlay(orig, false); // resume source
+ Bass.BASS_ChannelPlay(clone, false); // play clone
+ ...
+ private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _dupCallback As DSPPROC
+ ...
+ ' create stream on device 1
+ Bass.BASS_SetDevice(1)
+ Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
+ Bass.BASS_ChannelPlay(orig, False)
+ ...
+ ' create a clone on device 2
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ Bass.BASS_SetDevice(2)
+ Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
+ ' pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream)
+ Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
+ Dim buf(c) As Byte
+ Bass.BASS_ChannelGetData(stream, buf, c)
+ Bass.BASS_StreamPutData(clone, buf, c)
+ ' set DSP to copy new data from source stream
+ _dupCallback = New DSPPROC(DupDSP)
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
+ Bass.BASS_ChannelPlay(orig, False) ' resume source
+ Bass.BASS_ChannelPlay(clone, False) ' play clone
+ ...
+ Private Sub DupDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ private DSPPROC _dupCallback;
+ ...
+ // create stream on device 1
+ Bass.BASS_SetDevice(1);
+ int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
+ Bass.BASS_ChannelPlay(orig, false);
+ ...
+ // create a clone on device 2
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ Bass.BASS_SetDevice(2);
+ int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
+ // pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream);
+ int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
+ byte[] buf = new byte[c];
+ Bass.BASS_ChannelGetData(stream, buf, c);
+ Bass.BASS_StreamPutData(clone, buf, c);
+ // set DSP to copy new data from source stream
+ _dupCallback = new DSPPROC(DupDSP);
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
+ Bass.BASS_ChannelPlay(orig, false); // resume source
+ Bass.BASS_ChannelPlay(clone, false); // play clone
+ ...
+ private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _dupCallback As DSPPROC
+ ...
+ ' create stream on device 1
+ Bass.BASS_SetDevice(1)
+ Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
+ Bass.BASS_ChannelPlay(orig, False)
+ ...
+ ' create a clone on device 2
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ Bass.BASS_SetDevice(2)
+ Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
+ ' pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream)
+ Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
+ Dim buf(c) As Byte
+ Bass.BASS_ChannelGetData(stream, buf, c)
+ Bass.BASS_StreamPutData(clone, buf, c)
+ ' set DSP to copy new data from source stream
+ _dupCallback = New DSPPROC(DupDSP)
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
+ Bass.BASS_ChannelPlay(orig, False) ' resume source
+ Bass.BASS_ChannelPlay(clone, False) ' play clone
+ ...
+ Private Sub DupDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ private DSPPROC _dupCallback;
+ ...
+ // create stream on device 1
+ Bass.BASS_SetDevice(1);
+ int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
+ Bass.BASS_ChannelPlay(orig, false);
+ ...
+ // create a clone on device 2
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ Bass.BASS_SetDevice(2);
+ int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
+ // pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream);
+ int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
+ byte[] buf = new byte[c];
+ Bass.BASS_ChannelGetData(stream, buf, c);
+ Bass.BASS_StreamPutData(clone, buf, c);
+ // set DSP to copy new data from source stream
+ _dupCallback = new DSPPROC(DupDSP);
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
+ Bass.BASS_ChannelPlay(orig, false); // resume source
+ Bass.BASS_ChannelPlay(clone, false); // play clone
+ ...
+ private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _dupCallback As DSPPROC
+ ...
+ ' create stream on device 1
+ Bass.BASS_SetDevice(1)
+ Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
+ Bass.BASS_ChannelPlay(orig, False)
+ ...
+ ' create a clone on device 2
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ Bass.BASS_SetDevice(2)
+ Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
+ ' pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream)
+ Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
+ Dim buf(c) As Byte
+ Bass.BASS_ChannelGetData(stream, buf, c)
+ Bass.BASS_StreamPutData(clone, buf, c)
+ ' set DSP to copy new data from source stream
+ _dupCallback = New DSPPROC(DupDSP)
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
+ Bass.BASS_ChannelPlay(orig, False) ' resume source
+ Bass.BASS_ChannelPlay(clone, False) ' play clone
+ ...
+ Private Sub DupDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ private DSPPROC _dupCallback;
+ ...
+ // create stream on device 1
+ Bass.BASS_SetDevice(1);
+ int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
+ Bass.BASS_ChannelPlay(orig, false);
+ ...
+ // create a clone on device 2
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
+ Bass.BASS_SetDevice(2);
+ int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
+ // pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream);
+ int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
+ byte[] buf = new byte[c];
+ Bass.BASS_ChannelGetData(stream, buf, c);
+ Bass.BASS_StreamPutData(clone, buf, c);
+ // set DSP to copy new data from source stream
+ _dupCallback = new DSPPROC(DupDSP);
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
+ Bass.BASS_ChannelPlay(orig, false); // resume source
+ Bass.BASS_ChannelPlay(clone, false); // play clone
+ ...
+ private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
+ }
+
+
+ Private _dupCallback As DSPPROC
+ ...
+ ' create stream on device 1
+ Bass.BASS_SetDevice(1)
+ Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
+ Bass.BASS_ChannelPlay(orig, False)
+ ...
+ ' create a clone on device 2
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
+ Bass.BASS_SetDevice(2)
+ Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
+ ' pause source stream to synchonise buffer contents
+ Bass.BASS_ChannelPause(stream)
+ Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
+ Dim buf(c) As Byte
+ Bass.BASS_ChannelGetData(stream, buf, c)
+ Bass.BASS_StreamPutData(clone, buf, c)
+ ' set DSP to copy new data from source stream
+ _dupCallback = New DSPPROC(DupDSP)
+ Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
+ Bass.BASS_ChannelPlay(orig, False) ' resume source
+ Bass.BASS_ChannelPlay(clone, False) ' play clone
+ ...
+ Private Sub DupDSP(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
+ End Sub
+
+
+ int music = Bass.BASS_MusicLoad("test.mod", 0, 0, BASSFlag.BASS_DEFAULT, 0);
+
+
+ Dim music As Integer = Bass.BASS_MusicLoad("test.mod", 0, 0, BASSFlag.BASS_DEFAULT, 0)
+
+
+ // Init Bass
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ // open file
+ FileStream fs = File.OpenRead( "test.mod" );
+ // get the length of the file
+ int length = (int)fs.Length;
+ // create the buffer which will keep the file in memory
+ byte[] buffer = new byte[length];
+ // read the file into the buffer
+ fs.Read(buffer, 0, length);
+ // buffer is filled, file can be closed
+ fs.Close();
+ // load music from memory buffer
+ int music = Bass.BASS_MusicLoad(buffer, 0, length, BASSFlag.BASS_DEFAULT, 0);
+ if (music != 0 && Bass.BASS_ChannelPlay(stream, false) )
+ {
+ // playing...
+ }
+ else
+ {
+ Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode());
+ }
+
+
+ ' Init Bass
+ Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ ' open file
+ Dim fs As FileStream = File.OpenRead("test.mod")
+ ' get the length of the file
+ Dim length As Integer = CInt(fs.Length)
+ ' create the buffer which will keep the file in memory
+ Dim buffer(length - 1) As Byte
+ ' read the file into the buffer
+ fs.Read(buffer, 0, length)
+ ' buffer is filled, file can be closed
+ fs.Close()
+ ' load music from memory buffer
+ Dim music As Integer = Bass.BASS_MusicLoad(buffer, 0, length, BASSFlag.BASS_DEFAULT, 0)
+ If music <> 0 AndAlso Bass.BASS_ChannelPlay(stream, False) Then
+ ' playing...
+ Else
+ Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode())
+ End If
+
+
+ private RECORDPROC _myRecProc; // make it global, so that the GC can not remove it
+ private int _byteswritten = 0;
+ private byte[] _recbuffer; // local recording buffer
+ ...
+ if ( Bass.BASS_RecordInit(-1) )
+ {
+ _myRecProc = new RECORDPROC(MyRecording);
+ int recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero);
+ ...
+ // start recording
+ Bass.BASS_ChannelPlay(recHandle, false);
+ }
+ ...
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ bool cont = true;
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // increase the rec buffer as needed
+ if (_recbuffer == null || _recbuffer.Length < length)
+ _recbuffer = new byte[length];
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _recbuffer, 0, length);
+ _byteswritten += length;
+ // write to file
+ ...
+ // stop recording after a certain amout (just to demo)
+ if (_byteswritten > 800000)
+ cont = false; // stop recording
+ }
+ return cont;
+ }
+
+
+ Private _myRecProc As RECORDPROC ' make it global, so that the GC can not remove it
+ Private _byteswritten As Integer = 0
+ Private _recbuffer() As Byte ' local recording buffer
+ ...
+ If Bass.BASS_RecordInit(-1) Then
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ Dim recHandle As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero)
+ ...
+ ' start recording
+ Bass.BASS_ChannelPlay(recHandle, False)
+ End If
+ ...
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ Dim cont As Boolean = True
+ If length > 0 AndAlso buffer <> IntPtr.Zero Then
+ ' increase the rec buffer as needed
+ If _recbuffer Is Nothing OrElse _recbuffer.Length < length Then
+ _recbuffer = New Byte(length) {}
+ End If
+ ' copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _recbuffer, 0, length)
+ _byteswritten += length
+ ' write to file
+ ...
+ ' stop recording after a certain amout (just to demo)
+ If _byteswritten > 800000 Then
+ cont = False ' stop recording
+ End If
+ End If
+ Return cont
+ End Function
+
+ If you are into C# you might also use an unsafe codeblock with native pointer access
+ (which might be must faster than the above - depending on what you are doing with the data):
+
+ private unsafe bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ bool cont = true;
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // assuming 16-bit sample data here
+ short *data = (short*)buffer;
+ ...
+
+ // stop recording after a certain amout (just to demo)
+ if (_byteswritten > 800000)
+ cont = false; // stop recording
+ }
+ return cont;
+ }
+
+
+ private RECORDPROC _myRecProc; // make it global, so that the Garbage Collector can not remove it
+ ...
+ Bass.BASS_RecordInit(-1);
+ _myRecProc = new RECORDPROC(MyRecording);
+ // start recording paused
+ int recChannel = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero);
+ ...
+ // really start recording
+ Bass.BASS_ChannelPlay(recChannel, false);
+ ...
+ // the recording callback
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ return true;
+ }
+
+
+ Private _myRecProc As RECORDPROC
+ ...
+ Bass.BASS_RecordInit(- 1)
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ ' start recording paused
+ Dim recChannel As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero)
+ ...
+ ' really start recording
+ Bass.BASS_ChannelPlay(recChannel, False)
+ ...
+ ' the recording callback
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ Return True
+ End Function
+
+ See
+ private RECORDPROC _myRecProc; // make it global, so that the Garbage Collector can not remove it
+ ...
+ Bass.BASS_RecordInit(-1);
+ _myRecProc = new RECORDPROC(MyRecording);
+ // start recording paused
+ int recChannel = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, 50, _myRecProc, IntPtr.Zero);
+ ...
+ // really start recording
+ Bass.BASS_ChannelPlay(recChannel, false);
+ ...
+ // the recording callback
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ return true;
+ }
+
+
+ Private _myRecProc As RECORDPROC
+ ...
+ Bass.BASS_RecordInit(-1)
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ ' start recording paused
+ Dim recChannel As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, 50, _myRecProc, IntPtr.Zero)
+ ...
+ ' really start recording
+ Bass.BASS_ChannelPlay(recChannel, False)
+ ...
+ ' the recording callback
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ Return True
+ End Function
+
+ See
+ BASS_DEVICEINFO info = new BASS_DEVICEINFO();
+ for (int n=0; Bass.BASS_RecordGetDeviceInfo(n, info); n++)
+ {
+ Console.WriteLine(info.ToString());
+ }
+
+
+ Dim n As Integer = 0
+ Dim info As New BASS_DEVICEINFO()
+ While (Bass.BASS_RecordGetDeviceInfo(n, info))
+ Console.WriteLine(info.ToString())
+ n += 1
+ End While
+
+ Or use the
+ int defDevice = -1;
+ BASS_DEVICEINFO info;
+ for (int n = 0; (info = Bass.BASS_RecordGetDeviceInfo(n)) != null; n++)
+ {
+ if (info.IsDefault)
+ {
+ defDevice = n;
+ break;
+ }
+ }
+
+
+ Dim defDevice As Integer = -1
+ Dim n As Integer = 0
+ Dim info As New BASS_DEVICEINFO()
+ While Not (info Is Nothing)
+ info = Bass.BASS_RecordGetDeviceDescription(n)
+ If Not (info Is Nothing) And info.IsDefault Then
+ defDevice = n
+ Exit While
+ End If
+ n += 1
+ End While
+
+ Or use the
+ BASS_RECORDINFO info = new BASS_RECORDINFO();
+ bool ok = Bass.BASS_RecordGetInfo(info);
+
+
+ Dim info As New BASS_RECORDINFO()
+ Dim ok As Boolean = Bass.BASS_RecordGetInfo(info)
+
+
+ BASS_RECORDINFO info = Bass.BASS_RecordGetInfo(info);
+ if (info != null)
+ Console.WriteLine(info.ToString());
+
+
+ Dim info As BASS_RECORDINFO = Bass.BASS_RecordGetInfo(info)
+ If Not (info Is Nothing) Then
+ Console.WriteLine(info.ToString())
+ End If
+
+
+ string inputName = Bass.BASS_RecordGetInputName(0);
+
+
+ Dim inputName As String = Bass.BASS_RecordGetInputName(0)
+
+
+ // Disable the master input without changing the volume:
+ Bass.BASS_RecordSetInput(-1, BASSInput.BASS_INPUT_OFF, -1f );
+
+ // Enable the first input and set the volume to 50%:
+ Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_ON, 0.5f );
+
+ // Set the volume of the first input without changing the settings:
+ Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_NONE, 1f );
+
+
+ ' Disable the master input without changing the volume:
+ Bass.BASS_RecordSetInput(-1, BASSInput.BASS_INPUT_OFF, -1F)
+
+ ' Enable the first input and set the volume to 50%:
+ Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_ON, 0.5F)
+
+ ' Set the volume of the first input without changing the settings:
+ Bass.BASS_RecordSetInput(0, BASSInput.BASS_INPUT_NONE, 1F );
+
+
+ Bass.BASS_RecordInit(-1); // init the default device
+ string name;
+ for (int n = 0; (name = Bass.BASS_RecordGetInputName(n)) != null; n++)
+ {
+ float vol = 0f;
+ int setting = Bass.BASS_RecordGetInput(n, ref vol);
+ Console.WriteLine("{0} [{1} : {2}] - {3}",
+ name,
+ (BASSInputType)((int)BASSInputType.BASS_INPUT_TYPE_MASK & setting),
+ vol,
+ ((int)BASSInput.BASS_INPUT_OFF & setting) != 0 ? "Off" : "On");
+ }
+
+
+ Bass.BASS_RecordInit(-1) ' init the default device
+ Dim n As Integer = 0
+ Dim name As String = ""
+ While Not (name Is Nothing)
+ name = Bass.BASS_RecordGetInputName(n)
+ n += 1
+ If Not (name Is Nothing) Then
+ Dim vol As Single = 0F
+ Dim setting As Integer = Bass.BASS_RecordGetInput(n, vol)
+ Console.WriteLine("{0} [{1} : {2}] - {3}",
+ name,
+ CType(CInt(BASSInputType.BASS_INPUT_TYPE_MASK) And setting, BASSInputType),
+ vol,
+ CStr(IIf(CInt(BASSInput.BASS_INPUT_OFF) And setting <> 0, "Off", "On")))
+ End If
+ End While
+
+ Find a microphone input:
+
+ Bass.BASS_RecordInit(-1);
+ int mic = -1;
+ int n = 0;
+ int settings = 0;
+ float vol = 0f;
+ while (settings != -1)
+ {
+ // get the settings of that input
+ settings = Bass.BASS_RecordGetInput(n, ref vol);
+ if ( (settings & (int)BASSInputType.BASS_INPUT_TYPE_MASK) == (int)BASSInputType.BASS_INPUT_TYPE_MIC )
+ {
+ // found the mic!
+ mic = n;
+ break;
+ }
+ n++;
+ }
+ if (mic != -1)
+ Console.WriteLine( "Found a MIC at input {0}", mic );
+ else
+ Console.WriteLine( "No MIC found!" );
+
+
+ Bass.BASS_RecordInit(-1)
+ Dim mic As Integer = -1
+ Dim n As Integer = 0
+ Dim settings As Integer = 0
+ Dim vol As Single = 0F
+ While settings <> -1
+ ' get the settings of that input
+ settings = Bass.BASS_RecordGetInput(n, vol)
+ If (settings And CInt(BASSInputType.BASS_INPUT_TYPE_MASK)) = CInt(BASSInputType.BASS_INPUT_TYPE_MIC) Then
+ ' found the mic!
+ mic = n
+ Exit While
+ End If
+ n += 1
+ End While
+ If mic <> -1 Then
+ Console.WriteLine("Found a MIC at input {0}", mic)
+ Else
+ Console.WriteLine("No MIC found!")
+ End If
+
+
+ Bass.BASS_RecordInit(-1); // init the default device
+ int mic = -1;
+ BASSInputType flags;
+ for (int n=0; (flags=Bass.BASS_RecordGetInputType(n)) != BASSInputType.BASS_INPUT_TYPE_ERROR; n++)
+ {
+ if ( (flags & BASSInputType.BASS_INPUT_TYPE_MASK) == BASSInputType.BASS_INPUT_TYPE_MIC )
+ {
+ // found the mic!
+ mic = n;
+ break;
+ }
+ }
+ if (mic != -1)
+ Console.WriteLine( "Found a MIC at input {0}", mic );
+ else
+ Console.WriteLine( "No MIC found!" );
+
+
+ Bass.BASS_RecordInit(- 1)
+ Dim mic As Integer = -1
+ Dim n As Integer = 0
+ Dim flags As BASSInputType = BASSInputType.BASS_INPUT_TYPE_UNDEF
+ While flags <> BASSInputType.BASS_INPUT_TYPE_ERROR
+ ' get the settings of that input
+ flags = Bass.BASS_RecordGetInputType(n)
+ If (flags And BASSInputType.BASS_INPUT_TYPE_MASK) = BASSInputType.BASS_INPUT_TYPE_MIC) Then
+ ' found the mic!
+ mic = n
+ Exit While
+ End If
+ n += 1
+ End While
+ If mic <> -1 Then
+ Console.WriteLine("Found a MIC at input {0}", mic)
+ Else
+ Console.WriteLine("No MIC found!")
+ End If
+
+
+ BASS_CHANNELINFO info = new BASS_CHANNELINFO();
+ Bass.BASS_ChannelGetInfo(_stream, info);
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As New BASS_CHANNELINFO()
+ Bass.BASS_ChannelGetInfo(_stream, info)
+ Console.WriteLine(info.ToString())
+
+
+ BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(_stream);
+ Console.WriteLine( info.ToString() );
+
+
+ Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(_stream)
+ Console.WriteLine(info.ToString())
+
+
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+ // create the stream
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ Bass.BASS_StreamFree(stream);
+
+
+ Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
+ ' create the stream
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Bass.BASS_StreamFree(stream)
+
+
+ private float _gainDB = 0f;
+ private int _stream = 0;
+ private DSPPROC _myDSPProc; // make it global, so that the GC can not remove it
+ ...
+ _gainDB = 6f; // amplify by +6dB
+ _stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_SAMPLE_FLOAT);
+ // set a DSP user callback method
+ _myDSPProc = new DSPPROC(MyDSPGain);
+ // set the user DSP callback
+ Bass.BASS_ChannelSetDSP(_stream, _myDSPProc, IntPtr.Zero, 0);
+ ...
+ // this is the actual processing method
+ private void MyDSPGain(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ // the global variable _gainDB contains the amplification value in dB!
+ if (_gainDB == 0f || length == 0 || buffer == IntPtr.Zero)
+ return;
+
+ // convert the _gainDB value to a float
+ float _gainAmplification = (float)Math.Pow(10d, _gainDB / 20d);
+ // number of bytes in 32-bit floats, since length is in bytes
+ int l4 = length/4;
+ float[] data = new float[l4];
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, data, 0, l4);
+ // apply gain, assumeing using 32-bit floats (no clipping here ;-)
+ for (int a=0; a<l4; a++)
+ data[a] = data[a] * _gainAmplification;
+ // copy back from unmanaged to managed memory
+ Marshal.Copy(data, 0, buffer, l4);
+ }
+
+
+ Private _gainDB As Single = 0F
+ Private _stream As Integer = 0
+ Private _myDSPProc As DSPPROC ' make it global, so that the GC can not remove it
+ ...
+ _gainDB = 6f; // amplify by +6dB
+ _stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,
+ BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_SAMPLE_FLOAT)
+ ' set a DSP user callback method
+ _myDSPProc = New DSPPROC(AddressOf MyDSPGain)
+ ' set the user DSP callback
+ Bass.BASS_ChannelSetDSP(_stream, _myDSPProc, IntPtr.Zero, 0)
+ ...
+ ' this is the actual processing method
+ Private Sub MyDSPGain(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ ' the global variable _gainDB contains the amplification value in dB!
+ If _gainDB = 0F OrElse length = 0 OrElse buffer = IntPtr.Zero Then
+ Return
+ End If
+ ' convert the _gainDB value to a float
+ Dim _gainAmplification As Single = CSng(Math.Pow(10.0, _gainDB / 20.0))
+ ' number of bytes in 32-bit floats, since length is in bytes
+ Dim l4 As Integer = length / 4
+ Dim data(l4 - 1) As Single
+ ' copy from managed to unmanaged memory
+ Marshal.Copy(buffer, data, 0, l4)
+ ' apply gain, assumeing using 32-bit floats (no clipping here ;-)
+ Dim a As Integer
+ For a = 0 To l4 - 1
+ data(a) = data(a) * _gainAmplification
+ Next a
+ ' copy back from unmanaged to managed memory
+ Marshal.Copy(data, 0, buffer, l4)
+ End Sub
+
+ This example is type safe but 'slow', since two copy operations are involved.
+ One from unmanaged BASS to managed .NET and when processing has been done locally from .NET back to BASS.
+ However, for VB.Net users this is almost the only way to do it.
+
+ private unsafe void MyDSPGain(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (_gainDB == 1f || length == 0 || buffer == IntPtr.Zero)
+ return;
+
+ // convert the _gainDB value to a float
+ float _gainAmplification = (float)Math.Pow(10d, _gainDB / 20d);
+ // length is in bytes, so the number of floats to process is length/4
+ int l4 = length / 4;
+ // cast the given buffer IntPtr to a native pointer to float values
+ float *data = (float*)buffer;
+ for (int a=0; a<l4; a++)
+ {
+ data[a] = data[a] * _gainAmplification;
+ // alternatively you can also use:
+ // *data = *data * _gainAmplification;
+ // data++;
+ }
+ }
+
+
+ idx = length*freq/Nyquist
+ where:
+ length : length of the returned FFT buffer (in samples)
+ freq : required frequency (Hz)
+ Nyquist : Nyquist's frequency of the signal (half the sampling rate) (in Hz)
+
+ Example: If the stream is 44100Hz, then 16500Hz will be around bin 191 of a 512 sample FFT (512*16500/44100).
+ Or, if you are using BASS_DATA_FFT4096 on a stream with a sample rate of 44100 a tone at 540Hz will be at: 540*4096/44100 = 50.15, so a bit of the energy will be in fft[51], but mostly in fft[50].
+ Note: With a sample rate of 44100 the Nyquist frequency is 22050Hz, which is the max. frequency. This is also why BASS_DATA_FFT4096 only returns 2048 values - fft[2048] would represent 22050Hz.
+
+ // a 30ms window in bytes to be filled with sample data
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03);
+
+ // first we need a mananged object where the sample data should be held
+ // only length/4 elements needed, since length is in byte and a float uses 4 bytes
+ float[] data = new float[length/4];
+
+ // create a pinned handle to a managed object
+ GCHandle hGC = GCHandle.Alloc(data, GCHandleType.Pinned);
+
+ // get the data
+ length = Bass.BASS_ChannelGetData(channel, hGC.AddrOfPinnedObject(), length);
+
+ // free the pinned handle
+ hGC.Free();
+
+
+ ' a 30ms window in bytes to be filled with sample data
+ Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
+
+ ' first we need a mananged object where the sample data should be held
+ ' only length/4 elements needed, since length is in byte and a float uses 4 bytes
+ Dim data(length/4 - 1) As Single
+
+ ' create a pinned handle to a managed object
+ Dim hGC As GCHandle = GCHandle.Alloc(data, GCHandleType.Pinned)
+
+ ' get the data
+ length = Bass.BASS_ChannelGetData(channel, hGC.AddrOfPinnedObject(), length)
+
+ ' free the pinned handle
+ hGC.Free()
+
+ A more simple way is to use the other overloads where you simply pass the array itself
+ (those overloads pass the buffer array as a reference type by value with automatic pinning,
+ which is as fast as the following example).
+
+ // a 30ms window in bytes to be filled with sample data
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03);
+
+ // first we need a mananged object where the sample data should be held
+ // only length/4 elements needed, since length is in byte and a float uses 4 bytes
+ float[] data = new float[length/4];
+
+ // start an unsafe code block allowing you to use native pointers
+ unsafe
+ {
+ // pointers to managed objects need to be fixed
+ fixed (float* buffer = data) // equivalent to buffer = &data[0]
+ {
+ length = Bass.BASS_ChannelGetData(channel, (IntPtr)buffer, length);
+ }
+ }
+
+ This is by far the fastest way to use BASS_ChannelGetData, but unfortunately not availabe with VB.Net.
+ However, the other overloads do automatically pin the buffer as needed and are as fast as this.
+
+ idx = length*freq/Nyquist
+ where:
+ length : length of the returned FFT buffer (in samples)
+ freq : required frequency (Hz)
+ Nyquist : Nyquist's frequency of the signal (half the sampling rate) (in Hz)
+
+ Example: If the stream is 44100Hz, then 16500Hz will be around bin 191 of a 512 sample FFT (512*16500/44100).
+ Or, if you are using BASS_DATA_FFT4096 on a stream with a sample rate of 44100 a tone at 540Hz will be at: 540*4096/44100 = 50.15, so a bit of the energy will be in fft[51], but mostly in fft[50].
+ Note: With a sample rate of 44100 the Nyquist frequency is 22050Hz, which is the max. frequency. This is also why BASS_DATA_FFT4096 only returns 2048 values - fft[2048] would represent 22050Hz.
+
+ // a 30ms window in bytes to be filled with sample data
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03);
+
+ // first we need a mananged object where the sample data should be placed
+ // length is in bytes, so the number of floats to process is length/4
+ float[] data = new float[length/4];
+
+ // get the sample data
+ length = Bass.BASS_ChannelGetData(channel, data, length);
+
+
+ ' a 30ms window in bytes to be filled with sample data
+ Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
+
+ ' first we need a mananged object where the sample data should be placed
+ ' length is in bytes, so the number of floats to process is length/4
+ Dim data(length/4 - 1) As Single
+
+ ' get the sample data
+ length = Bass.BASS_ChannelGetData(channel, data, length)
+
+ The next example will gather the immediate FFT data from a channel:
+
+ float[] fft = new float[2048];
+ Bass.BASS_ChannelGetData(channel, fft, (int)BASSData.BASS_DATA_FFT4096)
+ // assuming the channel's samplerate is 44.1kHz,
+ // this will return the frequency represented by bucket 51
+ int hz = Utils.FFTIndex2Frequency(51, 4096, 44100);
+
+
+ Dim fft(2048 - 1) As Single
+ Bass.BASS_ChannelGetData(channel, fft, CInt(BASSData.BASS_DATA_FFT4096))
+ ' assuming the channel's samplerate is 44.1kHz,
+ ' this will return the frequency represented by bucket 51
+ Dim hz As Integer = Utils.FFTIndex2Frequency(51, 4096, 44100)
+
+
+ // a 30ms window in bytes to be filled with sample data
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03);
+
+ // first we need a mananged object where the sample data should be placed
+ // length is in bytes, so the number of shorts to process is length/2
+ short[] data = new short[length/2];
+
+ // get the sample data
+ length = Bass.BASS_ChannelGetData(channel, data, length);
+
+
+ ' a 30ms window in bytes to be filled with sample data
+ Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
+
+ ' first we need a mananged object where the sample data should be placed
+ ' length is in bytes, so the number of floats to process is length/2
+ Dim data(length/2 -1) As Short
+
+ ' get the sample data
+ length = Bass.BASS_ChannelGetData(channel, data, length)
+
+
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03); // 30ms window
+ int[] data = new int[length/4]; // 2 x 16-bit and length in is bytes
+ length = Bass.BASS_ChannelGetData(channel, data, length);
+ // further processing of length/4 array elements...where each int value represents a stereo pair
+ // the HighWord contains the left channel
+ // the LowWord contains the right channel
+
+
+ Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
+ Dim data(length/4 - 1) As Integer ' 2 x 16-bit and length in is bytes
+ length = Bass.BASS_ChannelGetData(channel, data, length)
+ ' further processing of length/4 array elements...where each int value represents a stereo pair
+ ' the HighWord contains the left channel
+ ' the LowWord contains the right channel
+
+
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03); // 30ms window
+ byte[] data = new byte[length]; // 8-bit are bytes
+ length = Bass.BASS_ChannelGetData(channel, data, length);
+
+
+ Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
+ Dim data(length - 1) As Byte
+ length = Bass.BASS_ChannelGetData(channel, data, length)
+
+
+ int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03);
+
+
+ Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
+
+
+ // length in bytes
+ long len = Bass.BASS_ChannelGetLength(channel);
+ // position in bytes
+ long pos = Bass.BASS_ChannelGetPosition(channel);
+ // the total time length
+ double totaltime = Bass.BASS_ChannelBytes2Seconds(channel, len);
+ // the elapsed time length
+ double elapsedtime = Bass.BASS_ChannelBytes2Seconds(channel, pos);
+ double remainingtime = totaltime - elapsedtime;
+
+
+ ' length in bytes
+ Dim len As Long = Bass.BASS_ChannelGetLength(channel)
+ ' position in bytes
+ Dim pos As Long = Bass.BASS_ChannelGetPosition(channel)
+ ' the total time length
+ Dim totaltime As Double = Bass.BASS_ChannelBytes2Seconds(channel, len)
+ ' the elapsed time length
+ Dim elapsedtime As Double = Bass.BASS_ChannelBytes2Seconds(channel, pos)
+ Dim remainingtime As Double = totaltime - elapsedtime
+
+
+ BASSActive status = BASS_ChannelIsActive(stream);
+ if (status == BASSActive.BASS_ACTIVE_PLAYING)
+ {
+ // the stream is still playing
+ ...
+ }
+
+
+ Dim status As BASSActive = BASS_ChannelIsActive(stream)
+ If status = BASSActive.BASS_ACTIVE_PLAYING Then
+ ' the stream is still playing
+ ...
+ End If
+
+
+ Bass.BASS_ChannelLock(channel, true); // lock channel
+ Bass.BASS_ChannelSetDSP(channel, DspProc1, null, 0); // set 1st DSP
+ Bass.BASS_ChannelSetDSP(channel, DspProc2, null, 0); // set 2nd DSP
+ Bass.BASS_ChannelLock(channel, false); // unlock channel
+
+
+ Bass.BASS_ChannelLock(channel, True); // lock channel
+ Bass.BASS_ChannelSetDSP(channel, DspProc1, Nothing, 0); // set 1st DSP
+ Bass.BASS_ChannelSetDSP(channel, DspProc2, Nothing, 0); // set 2nd DSP
+ Bass.BASS_ChannelLock(channel, False); // unlock channel
+
+
+ // length in bytes
+ long len = Bass.BASS_ChannelGetLength(channel, BASSMode.BASS_POS_BYTES);
+ // the time length
+ double time = Bass.BASS_ChannelBytes2Seconds(channel, len);
+
+
+ ' length in bytes
+ Dim len As Long = Bass.BASS_ChannelGetLength(channel, BASSMode.BASS_POS_BYTES)
+ ' the time length
+ Dim time As Double = Bass.BASS_ChannelBytes2Seconds(channel, len)
+
+
+ // length in bytes
+ long len = Bass.BASS_ChannelGetLength(channel);
+ // the time length
+ double time = Bass.BASS_ChannelBytes2Seconds(channel, len);
+
+
+ ' length in bytes
+ Dim len As Long = Bass.BASS_ChannelGetLength(channel)
+ ' the time length
+ Dim time As Double = Bass.BASS_ChannelBytes2Seconds(channel, len)
+
+
+ private SYNCPROC _mySync;
+ ...
+ _mySync = new SYNCPROC(EndSync);
+ Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME,
+ 0, _mySync, IntPtr.Zero);
+ ...
+ private void EndSync(int handle, int channel, int data, IntPtr user)
+ {
+ // the 'channel' has ended - jump to the beginning
+ Bass.BASS_ChannelSetPosition(channel, 0L);
+ }
+
+
+ Private _mySync As SYNCPROC
+ ...
+ _mySync = New SYNCPROC(AddressOf EndSync)
+ Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_END Or BASSSync.BASS_SYNC_MIXTIME,
+ 0, _mySync, IntPtr.Zero)
+ ...
+ Private Sub EndSync(ByVal handle As Integer, ByVal channel As Integer,
+ ByVal data As Integer, ByVal user As IntPtr)
+ ' the 'channel' has ended - jump to the beginning
+ Bass.BASS_ChannelSetPosition(channel, 0L)
+ End Sub
+
+ Process metadata received from an internet stream:
+
+ private SYNCPROC _mySync;
+ ...
+ int stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, null, 0);
+ // set a sync to get notified on stream title updates
+ _mySync = new SYNCPROC(MetaSync);
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void MetaSync(int handle, int channel, int data, IntPtr user)
+ {
+ // BASS_SYNC_META is triggered
+ string[] tags = Bass.BASS_ChannelGetTagsMETA(channel);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+ }
+
+
+ Private _mySync As SYNCPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, Nothing, 0)
+ ' set a sync to get notified on stream title updates
+ _mySync = New SYNCPROC(AddressOf MetaSync)
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub MetaSync(ByVal handle As Integer, ByVal channel As Integer,
+ ByVal data As Integer, ByVal user As IntPtr)
+ ' BASS_SYNC_META is triggered
+ Dim tags() As String = Bass.BASS_ChannelGetTagsMETA(channel)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ End Sub
+
+
+ BASS_DX8_ECHO echo = new BASS_DX8_ECHO(90f, 50f, 500f, 500f, true);
+ int channel = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ int fxEchoHandle = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_ECHO, 1);
+ ...
+ // changing the echo effect, dry/wet mix...
+ echo.fWetDryMix = 50f;
+ Bass.BASS_FXSetParameters(fxEchoHandle, echo);
+
+
+ Dim echo As New BASS_DX8_ECHO(90F, 50F, 500F, 500F, True)
+ Dim channel As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim fxEchoHandle As Integer = Bass.BASS_ChannelSetFX(channel, BASSFXType.BASS_FX_ECHO, 1)
+ ...
+ ' changing the echo effect, dry/wet mix...
+ echo.fWetDryMix = 50F
+ Bass.BASS_FXSetParameters(fxEchoHandle, echo)
+
+
+ bool isRecordingDevice = false;
+ int device = Bass.BASS_ChannelGetDevice(stream);
+ if (device != -1 && Utils.HighWord(device) == 1)
+ isRecordingDevice = true;
+
+
+ Dim isRecordingDevice As Boolean = False
+ Dim device As Integer = Bass.BASS_ChannelGetDevice(stream)
+ If device <> - 1 AndAlso Utils.HighWord(device) = 1 Then
+ isRecordingDevice = True
+ End If
+
+
+ // init device 1 and 2
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ // now device 1 is the current one
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ // now device 2 is the current one
+ ...
+ // create the stream on device 1
+ Bass.BASS_SetDevice(1);
+ // now device 1 is the current one
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ // move the channel to device 2
+ Bass.BASS_ChannelSetDevice(stream, 2);
+
+
+ ' init device 1 and 2
+ Bass.BASS_Init(1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ ' now device 1 is the current one
+ Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ ' now device 2 is the current one
+ ' create the stream on device 1
+ Bass.BASS_SetDevice(1)
+ ' now device 1 is the current one
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ ' move the channel to device 2
+ Bass.BASS_ChannelSetDevice(stream, 2)
+
+
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 0.5f);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 0.5F)
+
+
+ float vol = 0f;
+ if (Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, ref vol))
+ Console.WriteLine("Volume={0}", vol);
+
+
+ Dim vol As Single = 0F
+ If Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, vol) Then
+ Console.WriteLine("Volume={0}", vol)
+ End If
+
+
+ if ((Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_SAMPLE_LOOP) == BASSFlag.BASS_SAMPLE_LOOP)
+ {
+ // loop flag was set, so remove it
+ Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_SAMPLE_LOOP);
+ }
+ else
+ {
+ // loop flag was not set, so set it
+ Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_SAMPLE_LOOP, BASSFlag.BASS_SAMPLE_LOOP);
+ }
+
+
+ If (Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_DEFAULT) And BASSFlag.BASS_SAMPLE_LOOP) = BASSFlag.BASS_SAMPLE_LOOP Then
+ ' loop flag was set, so remove it
+ Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_SAMPLE_LOOP)
+ Else
+ ' loop flag was not set, so set it
+ Bass.BASS_ChannelFlags(channel, BASSFlag.BASS_SAMPLE_LOOP, BASSFlag.BASS_SAMPLE_LOOP)
+ End If
+
+
+ int stream = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_STREAM_PRESCAN);
+ // pre-buffer
+ Bass.BASS_ChannelUpdate(stream, 0);
+ // start playback
+ Bass.BASS_ChannelPlay(stream, false);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("afile.mp3", 0, 0, BASSFlag.BASS_STREAM_PRESCAN)
+ ' pre-buffer
+ Bass.BASS_ChannelUpdate(stream, 0)
+ ' start playback
+ Bass.BASS_ChannelPlay(stream, False)
+
+
+ while (Bass.BASS_ChannelIsSliding(channel, BASSAttribute.BASS_ATTRIB_VOL))
+ {
+ Thread.Sleep(20); // wait 20ms
+ }
+
+
+ While Bass.BASS_ChannelIsSliding(channel, BASSAttribute.BASS_ATTRIB_VOL)
+ Thread.Sleep(20) ' wait 20ms
+ End While
+
+
+ Bass.BASS_ChannelSlideAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, 0f, 1000);
+
+
+ Bass.BASS_ChannelSlideAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, 0F, 1000)
+
+
+ BASS3DMode mode = BASS3DMode.BASS_3DMODE_NORMAL;
+ float min = 0f;
+ float max = 0f;
+ int iangle = 0;
+ int oangle = 0;
+ int outvol = 0;
+ bool ok = Bass.BASS_ChannelGet3DAttributes(handle, ref mode, ref min, ref max, ref iangle, ref oangle, ref outvol);
+
+
+ Dim mode As BASS3DMode = BASS3DMode.BASS_3DMODE_NORMAL
+ Dim min As Single = 0F
+ Dim max As Single = 0F
+ Dim iangle As Integer = 0
+ Dim oangle As Integer = 0
+ Dim outvol As Integer = 0
+ Dim ok As Boolean = Bass.BASS_ChannelGet3DAttributes(handle, mode, min, max, iangle, oangle, outvol)
+
+
+ object outvol = 0;
+ bool ok = Bass.BASS_ChannelGet3DAttributes(handle, null, null, null, null, null, outvol);
+ // cast the outvol back it it's normal value type (int)
+ int deltaVol = (int)outvol;
+
+
+ Dim outvol As BASobject = 0
+ Dim ok As Boolean = Bass.BASS_ChannelGet3DAttributes(handle, Nothing, Nothing, Nothing, Nothing, Nothing, outvol)
+ ' cast the outvol back it it's normal value type (int)
+ Dim deltaVol As Integer = CInt(outvol)
+
+
+ BASS_3DVECTOR pos = new BASS_3DVECTOR();
+ BASS_3DVECTOR orient = new BASS_3DVECTOR();
+ BASS_3DVECTOR vel = new BASS_3DVECTOR();
+ if (Bass.BASS_ChannelGet3DPosition(stream, pos, orient, vel))
+ {
+ Console.WriteLine("{0} : {1} : {2}", pos, orient, vel);
+ }
+
+
+ Dim pos As New BASS_3DVECTOR()
+ Dim orient As New BASS_3DVECTOR()
+ Dim vel As New BASS_3DVECTOR()
+ If Bass.BASS_ChannelGet3DPosition(stream, pos, orient, vel) Then
+ Console.WriteLine("{0} : {1} : {2}", pos, orient, vel)
+ End If
+
+
+ Bass.BASS_ChannelSetPosition(stream, Bass.BASS_ChannelSeconds2Bytes(stream, 10.20), BASSMode.BASS_POS_BYTES);
+
+
+ Bass.BASS_ChannelSetPosition(stream, Bass.BASS_ChannelSeconds2Bytes(stream, 10.20), BASSMode.BASS_POS_BYTES)
+
+ Set the position of a MOD music to row 20 of order 10:
+
+ Bass.BASS_ChannelSetPosition(music, Utils.MakeMusicPos(10,20), BASSMode.BASS_POS_MUSIC_ORDER );
+
+
+ Bass.BASS_ChannelSetPosition(music, Utils.MakeMusicPos(10,20), BASSMode.BASS_POS_MUSIC_ORDER )
+
+ Start playback of a MOD music from the beginning of the last order:
+
+ // get number of orders
+ int len = (int)Bass.BASS_ChannelGetLength(music, BASSMode.BASS_POS_MUSIC_ORDER);
+ // seek to last order
+ Bass.BASS_ChannelSetPosition(music, Utils.MakeMusicPos(len-1, 0), BASSMode.BASS_POS_MUSIC_ORDER);
+ Bass.BASS_ChannelPlay(music, false); // play
+
+
+ ' get number of orders
+ Dim len As Integer = CInt(Bass.BASS_ChannelGetLength(music, BASSMode.BASS_POS_MUSIC_ORDER))
+ ' seek to last order
+ Bass.BASS_ChannelSetPosition(music, Utils.MakeMusicPos(len-1, 0), BASSMode.BASS_POS_MUSIC_ORDER)
+ Bass.BASS_ChannelPlay(music, False) ' play
+
+
+ Bass.BASS_ChannelSetPosition(stream, Bass.BASS_ChannelSeconds2Bytes(stream, 10.20));
+
+
+ Bass.BASS_ChannelSetPosition(stream, Bass.BASS_ChannelSeconds2Bytes(stream, 10.20))
+
+
+ long pos = Bass.BASS_ChannelGetPosition(stream, BASSMode.BASS_POS_BYTES);
+
+
+ Dim pos As Long = Bass.BASS_ChannelGetPosition(stream, BASSMode.BASS_POS_BYTES)
+
+
+ long pos = Bass.BASS_ChannelGetPosition(stream);
+
+
+ Dim pos As Long = Bass.BASS_ChannelGetPosition(stream)
+
+
+ int level = Bass.BASS_ChannelGetLevel(channel);
+ int left = Utils.LowWord32(level); // the left level
+ int right = Utils.HighWord32(level); // the right level
+
+
+ Dim level As Integer = Bass.BASS_ChannelGetLevel(channel)
+ Dim left As Integer = Utils.LowWord32(level) ' the left level
+ Dim right As Integer = Utils.HighWord32(level) ' the right level
+
+
+ float[] level = new float[2]; // dealing with stereo
+ if (Bass.BASS_ChannelGetLevel(channel, level))
+ {
+ float left = level[0]; // the left level
+ float right = level[1]; // the right level
+ }
+
+
+ Dim level(2) As Single ' dealing with stereo
+ If Bass.BASS_ChannelGetLevel(channel, level) Then
+ Dim left As Single = level(0) ' the left level
+ Dim right As Single = level(1) ' the right level
+ End If
+
+
+ // link stream2 to stream1
+ Bass.BASS_ChannelSetLink(stream1, stream2);
+ // start both streams together
+ Bass.BASS_ChannelPlay(stream1, false);
+
+
+ ' link stream2 to stream1
+ Bass.BASS_ChannelSetLink(stream1, stream2)
+ ' start both streams together
+ Bass.BASS_ChannelPlay(stream1, False)
+
+
+ int channel = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT);
+ IntPtr tag = Bass.BASS_ChannelGetTags(channel, BASSTag.BASS_TAG_OGG);
+ string[] tags = Utils.IntPtrToArrayNullTermUtf8(tag);
+ if (tags != null)
+ {
+ foreach (string tag in tags)
+ Console.Writeln("Tag: {0}\n", tag);
+ }
+
+
+ Dim channel As Integer = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT)
+ Dim tag As IntPtr = Bass.BASS_ChannelGetTags(channel, BASSTag.BASS_TAG_OGG)
+ Dim tags As String() = Utils.IntPtrToArrayNullTermUtf8(tag)
+ If Not (tags Is Nothing) Then
+ Dim tag As String
+ For Each tag In tags
+ Console.Writeln("Tag: {0}" + ControlChars.Lf, tag)
+ Next tag
+ End If
+
+ Getting MOD Music Instruments:
+
+ IntPtr p = BASS_ChannelGetTags(handle, (BASSTag)(BASSTag.BASS_TAG_MUSIC_INST + instrument));
+ if (p != IntPtr.Zero)
+ string instr = Marshal.PtrToStringAnsi(p);
+
+
+ Dim p As IntPtr = BASS_ChannelGetTags(handle, CType(BASSTag.BASS_TAG_MUSIC_INST + instrument, BASSTag))
+ If p <> IntPtr.Zero Then
+ Dim instr As String = Marshal.PtrToStringAnsi(p)
+ End If
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsID3V1(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsID3V1(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsID3V2(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsID3V2(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ Bass.BASS_PlugInLoad("bass_ape.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.ape", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsAPE(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Bass.BASS_PlugInLoad("bass_ape.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.ape", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsAPE(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ Bass.BASS_PlugInLoad("basswv.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.wv", 0, 0, BASSFlag.BASS_DEFAULT);
+ BASS_TAG_APE_BINARY[] binTags = Bass.BASS_ChannelGetTagsAPEBinary(stream);
+
+
+ Bass.BASS_PlugInLoad("basswv.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.wv", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim binTags As BASS_TAG_APE_BINARY() = Bass.BASS_ChannelGetTagsAPEBinary(stream)
+
+
+ Bass.BASS_PlugInLoad("basswv.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.wv", 0, 0, BASSFlag.BASS_DEFAULT);
+ AddOn.Tags.TagPicture[] pics = Bass.BASS_ChannelGetTagsAPEPictures(stream);
+
+
+ Bass.BASS_PlugInLoad("basswv.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.wv", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim pics As AddOn.Tags.TagPicture() = Bass.BASS_ChannelGetTagsAPEPictures(stream)
+
+
+ Bass.BASS_PlugInLoad("basswma.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.wma", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsWMA(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Bass.BASS_PlugInLoad("basswma.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.wma", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsWMA(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ Bass.BASS_PlugInLoad("bass_aac.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.m4a", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsMP4(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Bass.BASS_PlugInLoad("bass_aac.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.m4a", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsMP4(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.m4a", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsMF(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.m4a", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsMF(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ Bass.BASS_PlugInLoad("bassflac.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.flac", 0, 0, BASSFlag.BASS_DEFAULT);
+ BASS_TAG_FLAC_PICTURE[] pics = Bass.BASS_ChannelGetTagsFLACPictures(stream);
+
+
+ Bass.BASS_PlugInLoad("bassflac.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.flac", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim pics As BASS_TAG_FLAC_PICTURE() = Bass.BASS_ChannelGetTagsFLACPictures(stream)
+
+
+ Bass.BASS_PlugInLoad("bassflac.dll");
+ ...
+ int stream = Bass.BASS_StreamCreateFile("test.flac", 0, 0, BASSFlag.BASS_DEFAULT);
+ BASS_TAG_FLAC_CUE cuesheet = Bass.BASS_ChannelGetTagsFLACCuesheet(stream);
+
+
+ Bass.BASS_PlugInLoad("bassflac.dll")
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.flac", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim cuesheet As BASS_TAG_FLAC_CUE = Bass.BASS_ChannelGetTagsFLACCuesheet(stream)
+
+
+ int stream = Bass.BASS_StreamCreateURL("http://www.radio42.com/playHiFi.pls", 0,
+ BASSFlag.BASS_STREAM_STATUS, null, IntPtr.Zero);
+ string[] tags = Bass.BASS_ChannelGetTagsICY(stream);
+ if (tags == null)
+ {
+ // try http...
+ tags = Bass.BASS_ChannelGetTagsHTTP(stream);
+ }
+ if (tags != null)
+ {
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+ }
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateURL("http://www.radio42.com/playHiFi.pls", 0,
+ BASSFlag.BASS_STREAM_STATUS, Nothing, IntPtr.Zero)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
+ If tags Is Nothing Then
+ ' try http...
+ tags = Bass.BASS_ChannelGetTagsHTTP(stream)
+ End If
+ If Not (tags Is Nothing) Then
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+ End If
+
+
+ int stream = Bass.BASS_StreamCreateURL("http://www.radio42.com/playHiFi.pls", 0,
+ BASSFlag.BASS_STREAM_STATUS, null, IntPtr.Zero);
+ string[] tags = Bass.BASS_ChannelGetTagsICY(stream);
+ if (tags == null)
+ {
+ // try http...
+ tags = Bass.BASS_ChannelGetTagsHTTP(stream);
+ }
+ if (tags != null)
+ {
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+ }
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateURL("http://www.radio42.com/playHiFi.pls", 0,
+ BASSFlag.BASS_STREAM_STATUS, Nothing, IntPtr.Zero)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsICY(stream)
+ If tags Is Nothing Then
+ ' try http...
+ tags = Bass.BASS_ChannelGetTagsHTTP(stream)
+ End If
+ If Not (tags Is Nothing) Then
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+ End If
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsOGG(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.ogg", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsOGG(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_DEFAULT);
+ string[] tags = Bass.BASS_ChannelGetTagsRIFF(stream);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsRIFF(stream)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+
+
+ int stream = Bass.BASS_StreamCreateURL("http://www.radio42.com/playHiFi.pls", 0,
+ BASSFlag.BASS_STREAM_STATUS, null, IntPtr.Zero);
+ string[] tags = Bass.BASS_ChannelGetTagsMETA(stream);
+ if (tags != null)
+ {
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+ }
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateURL("http://www.radio42.com/playHiFi.pls", 0,
+ BASSFlag.BASS_STREAM_STATUS, Nothing, IntPtr.Zero)
+ Dim tags As String() = Bass.BASS_ChannelGetTagsMETA(stream)
+ If Not (tags Is Nothing) Then
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ Next tag
+ End If
+
+
+ string name = String.Empty;
+ int i = 0;
+ while ( true )
+ {
+ name = Bass.BASS_ChannelGetMusicSample( mod, i );
+ if ( name != null )
+ Console.Writeln( String.Format( "Sample {0}={1}", i, name ) );
+ else
+ break;
+ i++;
+ }
+
+
+ Dim name As String = [String].Empty
+ Dim i As Integer = 0
+ While True
+ name = Bass.BASS_ChannelGetMusicSample([mod], i)
+ If Not (name Is Nothing) Then
+ Console.Writeln([String].Format("Sample {0}={1}", i, name))
+ Else
+ Exit While
+ End If
+ i += 1
+ End While
+
+
+ int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
+ BASS_DX8_ECHO echo = new BASS_DX8_ECHO();
+ // add the effect to the DSP chain
+ int fxHandle = Bass.BASS_ChannelSetFX(stream, BASSFXType.BASS_FX_ECHO, 0);
+ echo.Preset_Long();
+ // apply the effect parameters
+ Bass.BASS_FXSetParameters(fxHandle, echo);
+ // play the channel
+ Bass.BASS_ChannelPlay(stream, false);
+
+
+ Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT)
+ Dim echo As New BASS_DX8_ECHO()
+ ' add the effect to the DSP chain
+ Dim fxHandle As Integer = Bass.BASS_ChannelSetFX(stream, BASSFXType.BASS_FX_ECHO, 0)
+ echo.Preset_Long()
+ ' apply the effect parameters
+ Bass.BASS_FXSetParameters(fxHandle, echo)
+ ' play the channel
+ Bass.BASS_ChannelPlay(stream, False)
+
+
+ BASS_DX8_ECHO echo = new BASS_DX8_ECHO();
+ Bass.BASS_FXGetParameters(_fxEchoHandle, echo);
+ Console.WriteLine( "Panning={0}", echo.lPanDelay );
+
+
+ Dim echo As New BASS_DX8_ECHO()
+ Bass.BASS_FXGetParameters(_fxEchoHandle, echo)
+ Console.WriteLine("Panning={0}", echo.lPanDelay)
+
+
+ Bass.LoadMe();
+ BassWma.LoadMe();
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ Bass.LoadMe( @"C:\Development\BASS\_libs" );
+ BassWma.LoadMe( @"C:\Development\BASS\_libs" );
+ ...
+ // when not used anymore...
+ BassWma.FreeMe();
+ Bass.FreeMe();
+
+
+ // set the scaler
+ Bass.BASS_ChannelSetAttribute(music, BASSAttribute.BASS_ATTRIB_MUSIC_PSCALER, 10f);
+ int pos = Bass.BASS_MusicGetOrderPosition(music);
+ // the order
+ int order = Utils.LowWord32(pos);
+ // the row
+ int row = HighWord32(pos) / 10;
+ // the 10th of a row
+ int row10th = HighWord32(pos) % 10;
+
+
+ ' set the scaler
+ Bass.BASS_ChannelSetAttribute(music, BASSAttribute.BASS_ATTRIB_MUSIC_PSCALER, 10F)
+ Dim pos As Integer = Bass.BASS_MusicGetOrderPosition(music)
+ ' the order
+ Dim order As Integer = Utils.LowWord32(pos)
+ ' the row
+ Dim row As Integer = HighWord32(pos) / 10
+ ' the 10th of a row
+ Dim row10th As Integer = HighWord32(pos) Mod 10
+
+
+ int channels = 0;
+ float dummy;
+ while (Bass.BASS_ChannelGetAttribute(music, (BASSAttribute)((int)BASS_ATTRIB_MUSIC_VOL_CHAN + channels), ref dummy))
+ {
+ channels++;
+ }
+
+
+ Dim channels As Integer = 0
+ Dim dummy As Single
+ While Bass.BASS_ChannelGetAttribute(music, CType(CInt(BASS_ATTRIB_MUSIC_VOL_CHAN) + channels, BASSAttribute), dummy)
+ channels += 1
+ End While
+
+
+ int instruments = 0;
+ float dummy;
+ while (Bass.BASS_ChannelGetAttribute(music, (BASSAttribute)((int)BASSAttribute.BASS_ATTRIB_MUSIC_VOL_INST + instruments), ref dummy))
+ {
+ instruments++;
+ }
+
+
+ Dim instruments As Integer = 0
+ Dim dummy As Single
+ While Bass.BASS_ChannelGetAttribute(music, CType(CInt(BASSAttribute.BASS_ATTRIB_MUSIC_VOL_INST) + instruments, BASSAttribute), dummy)
+ instruments += 1
+ End While
+
+
+ float ppqn;
+ Bass.BASS_ChannelGetAttribute(midi, BASSAttribute.BASS_ATTRIB_MIDI_PPQN, ref ppqn);
+ long tick = Bass.BASS_ChannelGetPosition(midi, BASSMode.BASS_POS_MIDI_TICK);
+ float beat = tick / ppqn;
+
+
+ Dim ppqn As Single
+ Bass.BASS_ChannelGetAttribute(midi, BASSAttribute.BASS_ATTRIB_MIDI_PPQN, ppqn)
+ Dim tick As Long = Bass.BASS_ChannelGetPosition(midi, BASSMode.BASS_POS_MIDI_TICK)
+ Dim beat As Single = tick / ppqn
+
+
+ int tracks = 0;
+ float dummy;
+ while (Bass.BASS_ChannelGetAttribute(midi, (BASSAttribute)((int)BASSAttribute.BASS_ATTRIB_MIDI_TRACK_VOL + tracks), ref dummy))
+ {
+ tracks++;
+ }
+
+
+ Dim tracks As Integer = 0
+ Dim dummy As Single
+ While Bass.BASS_ChannelGetAttribute(midi, CType(CInt(BASSAttribute.BASS_ATTRIB_MIDI_TRACK_VOL) + tracks, BASSAttribute), dummy)
+ tracks += 1
+ End While
+
+
+ private void MidiSync(int handle, int channel, int data, IntPtr user)
+ {
+ BASS_MIDI_MARK mark = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_MARKER, data);
+ ...
+ }
+
+
+ Private Sub MidiSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ Dim mark As BASS_MIDI_MARK = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_MARKER, data)
+ ...
+ End Sub
+
+
+ private void MidiSync(int handle, int channel, int data, IntPtr user)
+ {
+ BASS_MIDI_MARK mark = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_CUE, data);
+ ...
+ }
+
+
+ Private Sub MidiSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ Dim mark As BASS_MIDI_MARK = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_CUE, data)
+ ...
+ End Sub
+
+
+ private void MidiSync(int handle, int channel, int data, IntPtr user)
+ {
+ BASS_MIDI_MARK mark = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_LYRIC, data);
+ ...
+ }
+
+
+ Private Sub MidiSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ Dim mark As BASS_MIDI_MARK = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_MIDI_MARK_LYRIC, data)
+ ...
+ End Sub
+
+
+ private void MidiSync(int handle, int channel, int data, IntPtr user)
+ {
+ BASS_MIDI_MARK mark = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_SYNC_MIDI_TEXT, data);
+ ...
+ }
+
+
+ Private Sub MidiSync(handle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ Dim mark As BASS_MIDI_MARK = BassMidi.BASS_MIDI_StreamGetMark(channel, BASSMIDIMarker.BASS_SYNC_MIDI_TEXT, data)
+ ...
+ End Sub
+
+
+ using Un4seen.Bass;
+ ...
+ private BASS_FILEPROCS _myStreamCreateUser;
+ private FileStream _fs;
+ ...
+ Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
+ // creating the user file callback delegates
+ _myStreamCreateUser = new BASS_FILEPROCS(
+ new FILECLOSEPROC(MyFileProcUserClose),
+ new FILELENPROC(MyFileProcUserLength),
+ new FILEREADPROC(MyFileProcUserRead),
+ new FILESEEKPROC(MyFileProcUserSeek));
+ // open the file...
+ _fs = File.OpenRead("test.mp3");
+ // create the stream (the PRESCAN flag shows you what BASS is doing at the beginning to scan the entire file)
+ // if that generates to much output for you, you can simply remove it
+ int stream = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_AUTOFREE, _myStreamCreateUser, IntPtr.Zero);
+ // play the channel
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void MyFileProcUserClose(IntPtr user)
+ {
+ if (_fs == null)
+ return;
+ _fs.Close();
+ Console.WriteLine("File Closed");
+ }
+
+ private long MyFileProcUserLength(IntPtr user)
+ {
+ if (_fs == null)
+ return 0L;
+ return _fs.Length;
+ }
+
+ private int MyFileProcUserRead(IntPtr buffer, int length, IntPtr user)
+ {
+ if (_fs == null)
+ return 0;
+ try
+ {
+ // at first we need to create a byte[] with the size of the requested length
+ byte[] data = new byte[length];
+ // read the file into data
+ int bytesread = _fs.Read(data, 0, length);
+ // and now we need to copy the data to the buffer
+ // we write as many bytes as we read via the file operation
+ Marshal.Copy(data, 0, buffer, bytesread);
+ return bytesread;
+ }
+ catch { return 0; }
+ }
+
+ private bool MyFileProcUserSeek(long offset, IntPtr user)
+ {
+ if (_fs == null)
+ return false;
+ try
+ {
+ long pos = _fs.Seek(offset, SeekOrigin.Begin);
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+
+ Imports Un4seen.Bass
+ ...
+ Private _myStreamCreateUser As BASS_FILEPROCS
+ Private _fs As FileStream
+ ...
+ Bass.BASS_Init(- 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
+ ' creating the user file callback delegates
+ _myStreamCreateUser = New BASS_FILEPROCS(
+ New FILECLOSEPROC(AddressOf MyFileProcUserClose),
+ New FILELENPROC(AddressOf MyFileProcUserLength),
+ New FILEREADPROC(AddressOf MyFileProcUserRead),
+ New FILESEEKPROC(AddressOf MyFileProcUserSeek))
+ ' open the file...
+ _fs = File.OpenRead("test.mp3")
+ ' create the stream (the PRESCAN flag shows you what BASS is doing at the beginning to scan the entire file)
+ ' if that generates to much output for you, you can simply remove it
+ Dim stream As Integer = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, BASSFlag.BASS_STREAM_PRESCAN Or BASSFlag.BASS_STREAM_AUTOFREE, _myStreamCreateUser, IntPtr.Zero)
+ ' play the channel
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub MyFileProcUserClose(user As IntPtr)
+ If _fs Is Nothing Then
+ Return
+ End If
+ _fs.Close()
+ End Sub
+
+ Private Function MyFileProcUserLength(user As IntPtr) As Long
+ If _fs Is Nothing Then
+ Return 0L
+ End If
+ Return _fs.Length
+ End Function
+
+ Private Function MyFileProcUserRead(buffer As IntPtr, length As Integer, user As IntPtr) As Integer
+ If _fs Is Nothing Then
+ Return 0
+ End If
+ Try
+ ' at first we need to create a byte[] with the size of the requested length
+ Dim data(length - 1) As Byte
+ ' read the file into data
+ Dim bytesread As Integer = _fs.Read(data, 0, length)
+ ' and now we need to copy the data to the buffer
+ ' we write as many bytes as we read via the file operation
+ Marshal.Copy(data, 0, buffer, bytesread)
+ Return bytesread
+ Catch
+ Return 0
+ End Try
+ End Function
+
+ Private Function MyFileProcUserSeek(offset As Long, user As IntPtr) As Boolean
+ If _fs Is Nothing Then
+ Return False
+ End If
+ Try
+ Dim pos As Long = _fs.Seek(offset, SeekOrigin.Begin)
+ Return True
+ Catch
+ Return False
+ End Try
+ End Function
+
+
+ BASS_CHANNELINFO info = new BASS_CHANNELINFO();
+ Bass.BASS_ChannelGetInfo(channel, info); // get info
+ if (info.ctype == BassChannel.BASS_CTYPE_STREAM_MP3)
+ {
+ // it's an MP3!
+ }
+
+
+ BASS_3DVECTOR position = new BASS_3DVECTOR(camera.RealPosition.x, camera.RealPosition.y, camera.RealPosition.z);
+ BASS_3DVECTOR direction = new BASS_3DVECTOR(camera.RealDirection.x, camera.RealDirection.y, camera.RealDirection.z);
+ BASS_3DVECTOR up = new BASS_3DVECTOR(-camera.RealUp.x, -camera.RealUp.y, -camera.RealUp.z);
+
+ if (!Bass.BASS_Set3DPosition(position, velocity, direction, up))
+ throw new AudioException("Could not set the 3d position of the listener", "listener", Bass.BASS_ErrorGetCode());
+
+ Bass.BASS_Apply3D();
+
+
+ Dim position As New BASS_3DVECTOR(camera.RealPosition.x, camera.RealPosition.y, camera.RealPosition.z)
+ Dim direction As New BASS_3DVECTOR(camera.RealDirection.x, camera.RealDirection.y, camera.RealDirection.z)
+ Dim up As New BASS_3DVECTOR(-camera.RealUp.x, -camera.RealUp.y, -camera.RealUp.z)
+
+ If Not Bass.BASS_Set3DPosition(position, velocity, direction, up) Then
+ Throw New AudioException("Could not set the 3d position of the listener", "listener", Bass.BASS_ErrorGetCode())
+ End If
+
+ Bass.BASS_Apply3D()
+
+
+ private int[] _fxEQ = {0, 0, 0};
+ ...
+ // 3-band EQ
+ BASS_DX8_PARAMEQ eq = new BASS_DX8_PARAMEQ();
+ _fxEQ[0] = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
+ _fxEQ[1] = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
+ _fxEQ[2] = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0);
+ eq.fBandwidth = 18f;
+ eq.fCenter = 100f;
+ eq.fGain = 0f;
+ Bass.BASS_FXSetParameters(_fxEQ[0], eq);
+ eq.fCenter = 1000f;
+ Bass.BASS_FXSetParameters(_fxEQ[1], eq);
+ eq.fCenter = 8000f;
+ Bass.BASS_FXSetParameters(_fxEQ[2], eq);
+ ...
+ private void UpdateEQ(int band, float gain)
+ {
+ BASS_DX8_PARAMEQ eq = new BASS_DX8_PARAMEQ();
+ if (Bass.BASS_FXGetParameters(_fxEQ[band], eq))
+ {
+ eq.fGain = gain;
+ Bass.BASS_FXSetParameters(_fxEQ[band], eq);
+ }
+ }
+
+
+ Private _fxEQ As Integer() = {0, 0, 0}
+ ...
+ ' 3-band EQ
+ Dim eq As New BASS_DX8_PARAMEQ()
+ _fxEQ(0) = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0)
+ _fxEQ(1) = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0)
+ _fxEQ(2) = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_DX8_PARAMEQ, 0)
+ eq.fBandwidth = 18F
+ eq.fCenter = 100F
+ Bass.BASS_FXSetParameters(_fxEQ(0), eq)
+ eq.fCenter = 1000F
+ Bass.BASS_FXSetParameters(_fxEQ(1), eq)
+ eq.fCenter = 8000F
+ Bass.BASS_FXSetParameters(_fxEQ(2), eq)
+ ...
+ Private Sub UpdateEQ(band As Integer, gain As Single)
+ Dim eq As New BASS_DX8_PARAMEQ()
+ If Bass.BASS_FXGetParameters(_fxEQ(band), eq) Then
+ eq.fGain = gain
+ Bass.BASS_FXSetParameters(_fxEQ(band), eq)
+ End If
+ End Sub
+
+
+ IntPtr p = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3);
+ if (p != IntPtr.Zero)
+ {
+ BASS_TAG_ID3 id3 = (BASS_TAG_ID3)Marshal.PtrToStructure(p, typeof(BASS_TAG_ID3));
+ ...
+ }
+
+
+ Dim p As IntPtr = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3)
+ If p <> IntPtr.Zero Then
+ Dim id3 As BASS_TAG_ID3 = DirectCast(Marshal.PtrToStructure(p, GetType(BASS_TAG_ID3)), BASS_TAG_ID3)
+ ...
+ End If
+
+
+ IntPtr p = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_RIFF_BEXT);
+ if (p != IntPtr.Zero)
+ {
+ BASS_TAG_BEXT bext = (BASS_TAG_BEXT)Marshal.PtrToStructure(p, typeof(BASS_TAG_BEXT));
+ string codingHist = bext.GetCodingHistory(p);
+ ...
+ }
+
+
+ Dim p As IntPtr = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_RIFF_BEXT)
+ If p <> IntPtr.Zero Then
+ Dim bext As BASS_TAG_BEXT = DirectCast(Marshal.PtrToStructure(p, GetType(BASS_TAG_BEXT)), BASS_TAG_BEXT)
+ Dim codingHist As String = bext.GetCodingHistory(p)
+ ...
+ End If
+
+
+ IntPtr p = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_RIFF_CART);
+ if (p != IntPtr.Zero)
+ {
+ BASS_TAG_CART cart = (BASS_TAG_CART)Marshal.PtrToStructure(p, typeof(BASS_TAG_CART));
+ string tagText = cart.GetTagText(p);
+ ...
+ }
+
+
+ Dim p As IntPtr = Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_RIFF_CART)
+ If p <> IntPtr.Zero Then
+ Dim cart As BASS_TAG_CART = DirectCast(Marshal.PtrToStructure(p, GetType(BASS_TAG_CART)), BASS_TAG_CART)
+ Dim tagText As String = cart.GetTagText(p)
+ ...
+ End If
+
+ Bass.BASS_ChannelGetTags( stream, (BASSTag)(BASSTag.BASS_TAG_APE_BINARY + 1) )
to get the 2nd binary tag.
+
+ BASS_TAG_APE_BINARY apeBin;
+ for (int n = 0; (apeBin = BASS_TAG_APE_BINARY.GetTag(stream, n)) != null; n++)
+ {
+ Console.WriteLine(apeBin);
+ // access the binary data
+ byte[] data = apeBin.Data;
+ }
+
+
+ Dim apeBin As BASS_TAG_APE_BINARY
+ Dim n As Integer
+ For n = 0 To (apeBin BASS_TAG_APE_BINARY.GetTag(stream, n)) <> Nothing Step n + 1
+ Console.WriteLine(apeBin)
+ ' access the binary data
+ Dim data() As Byte = apeBin.Data
+ Next
+
+
+ BASS_TAG_APE_BINARY apeBin;
+ for (int n = 0; (apeBin = BASS_TAG_APE_BINARY.GetTag(stream, n)) != null; n++)
+ {
+ Console.WriteLine(apeBin);
+ // access the binary data
+ byte[] data = apeBin.Data;
+ }
+
+
+ Dim apeBin As BASS_TAG_APE_BINARY
+ Dim n As Integer
+ For n = 0 To (apeBin BASS_TAG_APE_BINARY.GetTag(stream, n)) <> Nothing Step n + 1
+ Console.WriteLine(apeBin)
+ ' access the binary data
+ Dim data() As Byte = apeBin.Data
+ Next
+
+ Bass.BASS_ChannelGetTags( stream, (BASSTag)(BASSTag.BASS_TAG_FLAC_PICTURE + 1) )
to get the 2nd picture.
+
+ BASS_TAG_FLAC_PICTURE flacPic;
+ for (int n = 0; (flacPic = BASS_TAG_FLAC_PICTURE.GetTag(stream, n)) != null; n++)
+ {
+ Console.WriteLine(flacPic);
+ // access the image picture
+ Image img = flacPic.Picture;
+ // access the raw image data
+ byte[] data = flacPic.Data;
+ }
+
+
+ Dim flacPic As BASS_TAG_FLAC_PICTURE
+ Dim n As Integer
+ For n = 0 To (flacPic BASS_TAG_FLAC_PICTURE.GetTag(stream, n)) <> Nothing Step n + 1
+ Console.WriteLine(flacPic)
+ ' access the image picture
+ Dim img As Image = flacPic.Picture
+ ' access the raw image data
+ Dim data() As Byte = flacPic.Data
+ Next
+
+
+ BASS_TAG_FLAC_PICTURE flacPic;
+ for (int n = 0; (flacPic = BASS_TAG_FLAC_PICTURE.GetTag(stream, n)) != null; n++)
+ {
+ Console.WriteLine(flacPic);
+ // access the image picture
+ Image img = flacPic.Picture;
+ // access the raw image data
+ byte[] data = flacPic.Data;
+ }
+
+
+ Dim flacPic As BASS_TAG_FLAC_PICTURE
+ Dim n As Integer
+ For n = 0 To (flacPic BASS_TAG_FLAC_PICTURE.GetTag(stream, n)) <> Nothing Step n + 1
+ Console.WriteLine(flacPic)
+ ' access the image picture
+ Dim img As Image = flacPic.Picture
+ ' access the raw image data
+ Dim data() As Byte = flacPic.Data
+ Next
+
+
+ BASS_TAG_FLAC_CUE cuesheet = BASS_TAG_FLAC_CUE.GetTag(stream);
+
+
+ Dim cuesheet As BASS_TAG_FLAC_CUE = BASS_TAG_FLAC_CUE.GetTag(stream)
+
+
+ BASS_TAG_FLAC_CUE cuesheet = BASS_TAG_FLAC_CUE.GetTag(stream);
+
+
+ Dim cuesheet As BASS_TAG_FLAC_CUE = BASS_TAG_FLAC_CUE.GetTag(stream)
+
+
+ BASS_TAG_FLAC_CUE cuesheet = BASS_TAG_FLAC_CUE.GetTag(stream);
+
+
+ Dim cuesheet As BASS_TAG_FLAC_CUE = BASS_TAG_FLAC_CUE.GetTag(stream)
+
+
+ BASS_TAG_FLAC_CUE cuesheet = BASS_TAG_FLAC_CUE.GetTag(stream);
+
+
+ Dim cuesheet As BASS_TAG_FLAC_CUE = BASS_TAG_FLAC_CUE.GetTag(stream)
+
+
+ private STREAMPROC _myStreamCreate; // make it global, so that the GC can not remove it
+ private byte[] _data; // local data buffer
+ ...
+ _myStreamCreate = new STREAMPROC(MyFileProc);
+ FileStream _fs = File.OpenRead("test.raw");
+ int channel = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(channel, false);
+ ...
+ private int MyFileProc(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ // implementing the callback for BASS_StreamCreate...
+ // here we need to deliver PCM sample data
+ // increase the data buffer as needed
+ if (_data == null || _data.Length < length)
+ _data = new byte[length];
+ int bytesread = _fs.Read( _data, 0, length );
+ Marshal.Copy( _data, 0, buffer, bytesread );
+ if ( bytesread < length )
+ {
+ bytesread |= (int)BASSStreamProc.BASS_STREAMPROC_END; // set indicator flag
+ _fs.Close();
+ }
+ return bytesread;
+ }
+
+
+ Private _myStreamCreate As STREAMPROC ' make it global, so that the GC can not remove it
+ Private _data As Byte() = Nothing ' our local buffer
+ ...
+ _myStreamCreate = New STREAMPROC(AddressOf MyFileProc)
+ Dim fs As FileStream = File.OpenRead("test.raw")
+ Dim channel As Integer = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(channel, False)
+ ...
+ Private Function MyFileProc(ByVal handle As Integer, ByVal buffer As IntPtr,
+ ByVal length As Integer, ByVal user As IntPtr) As Integer
+ ' implementing the callback for BASS_StreamCreate...
+ ' here we need to deliver PCM sample data
+ ' increase the data buffer as needed
+ If _data = Nothing OrElse _data.Length < length Then
+ _data = New Byte(length) {}
+ End If
+ Dim bytesread As Integer = _fs.Read(_data, 0, length)
+ Marshal.Copy(_data, 0, buffer, bytesread)
+ If bytesread < length Then
+ bytesread = bytesread Or CInt(BASSStreamProc.BASS_STREAMPROC_END) ' set indicator flag
+ _fs.Close()
+ EndIf
+ Return bytesread
+ End Function
+
+ If you're into C# you might also make use of native pointers in an unsafe code block:
+
+ unsafe private int MyFileProcUnsafe(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ // simply cast the given IntPtr to a native pointer to byte values
+ byte *data = (byte*)buffer;
+ // read the file into the data pointer directly
+ int bytesread = length;
+ for (int a=0; a < length; a++)
+ {
+ int val = _fs.ReadByte();
+ if (val != -1)
+ {
+ data[a] = (byte)val; // set the value
+ }
+ else
+ {
+ bytesread = a;
+ break;
+ }
+ }
+ // end of the file/stream?
+ if ( bytesread < length )
+ {
+ bytesread |= (int)BASSStreamProc.BASS_STREAMPROC_END; // set indicator flag
+ _fs.Close();
+ }
+ return bytesread;
+ }
+
+ However, even if we directly access memory here, this is not really faster in that case, since we read the file byte per byte and also in a way perform a copy (we just use a single int buffer called val).
+ So in essence when you need to read from a file you should take care, that the file access and read operation is fast an additional Marshal.Copy wouldn't count much in terms of performance.
+ The only advantage we get here is actually, that we use less memory.
+
+ private DSPPROC _myDSPAddr; // make it global, so that the GC can not remove it
+ private float[] _data; // local data buffer
+ ...
+ _myDSPAddr = new DSPPROC(MyDSPCallback);
+ Bass.BASS_ChannelSetDSP(_stream, _myDSPAddr, IntPtr.Zero, 2);
+ ...
+ private void MyDSPCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (length == 0 || buffer == IntPtr.Zero)
+ return;
+ // number of bytes in 32-bit floats, since length is in bytes
+ int l4 = length/4;
+ // increase the data buffer as needed
+ if (_data == null || _data.Length < l4)
+ _data = new float[l4];
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _data, 0, l4);
+
+ // ... do your processing here
+
+ // copy back from unmanaged to managed memory
+ Marshal.Copy(_data, 0, buffer, l4);
+ }
+
+
+ Private _myDSPAddr As DSPPROC ' make it global, so that the GC can not remove it
+ Private _data As Single() = Nothing ' our local buffer
+ ...
+ _myDSPAddr = New DSPPROC(AddressOf MyDSPCallback)
+ Bass.BASS_ChannelSetDSP(_stream, _myDSPAddr, IntPtr.Zero, 2)
+ ...
+ Private Sub MyGain(handle As Integer, channel As Integer,
+ buffer As IntPtr, length As Integer, user As IntPtr)
+ If length = 0 OrElse buffer = IntPtr.Zero Then
+ Return
+ End If
+ ' number of bytes in 32-bit floats, since length is in bytes
+ Dim l4 As Integer = length / 4
+ ' increase the data buffer as needed
+ If _data Is Nothing OrElse _data.Length < l4 Then
+ _data = New Single(l4) {}
+ End If
+ ' copy from unmanaged to managed memory
+ Marshal.Copy(buffer, _data, 0, l4)
+
+ // ... do your processing here
+
+ ' copy back from unmanaged to managed memory
+ Marshal.Copy(_data, 0, buffer, l4)
+ End Sub
+
+ If you're using C# you might even use unsafe code blocks to directly access memory via pointers, like in C/C++:
+
+ myDSPAddr = new DSPPROC(MyDSPGainUnsafe);
+ Bass.BASS_ChannelSetDSP(_stream, myDSPAddr, IntPtr.Zero, 2);
+ ...
+ // the unsafe callback
+ private DSPPROC myDSPAddr; // make it global, so that the Garbage Collector can not remove it
+ private void MyDSPGainUnsafe(int handle, int channel, IntPtr buffer, int length, IntPtr user)
+ {
+ if (_gainAmplification == 1f || length == 0 || buffer == IntPtr.Zero)
+ return;
+ // length is in bytes, so the number of floats to process is:
+ // length/4 : byte = 8-bit, float = 32-bit
+ int l4 = length/4;
+ unsafe
+ {
+ float *data = (float*)buffer;
+ for (int a=0; a<l4; a++)
+ {
+ data[a] *= _gainAmplification;
+ }
+ }
+ }
+
+ Using unsafe code is fast and efficient (especially in DSP routines), but is not type safe (e.g. no overflow handling, no type checking etc.) - so you just need to know what you are doing.
+
+ private FileStream _fs = null;
+ private DOWNLOADPROC _myDownloadProc;
+ private byte[] _data; // local data buffer
+ ...
+ _myDownloadProc = new DOWNLOADPROC(MyDownload);
+ int stream = Bass.BASS_StreamCreateURL("http://www.asite.com/afile.mp3", 0,
+ BASSFlag.BASS_DEFAULT, _myDownloadProc, IntPtr.Zero);
+ ...
+ private void MyDownload(IntPtr buffer, int length, IntPtr user)
+ {
+ if (_fs == null)
+ {
+ // create the file
+ _fs = File.OpenWrite( "output.mp3" );
+ }
+ if (buffer == IntPtr.Zero)
+ {
+ // finished downloading
+ _fs.Flush();
+ _fs.Close();
+ }
+ else
+ {
+ // increase the data buffer as needed
+ if (_data == null || _data.Length < length)
+ _data = new byte[length];
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _data, 0, length);
+ // write to file
+ _fs.Write( _data, 0, length );
+ }
+ }
+
+
+ Private _fs As FileStream = Nothing
+ Private _myDownloadProc As DOWNLOADPROC
+ Private _data() As Byte ' local data buffer
+ ...
+ _myDownloadProc = New DOWNLOADPROC(AddressOf MyDownload)
+ Dim stream As Integer = Bass.BASS_StreamCreateURL("http://www.asite.com/afile.mp3", 0,
+ BASSFlag.BASS_DEFAULT, _myDownloadProc, IntPtr.Zero)
+ ...
+ Private Sub MyDownload(buffer As IntPtr, length As Integer, user As IntPtr)
+ If _fs Is Nothing Then
+ ' create the file
+ _fs = File.OpenWrite("output.mp3")
+ End If
+ If buffer = IntPtr.Zero Then
+ ' finished downloading
+ _fs.Flush()
+ _fs.Close()
+ Else
+ ' increase the data buffer as needed
+ If _data Is Nothing OrElse _data.Length < length Then
+ _data = New Byte(length) {}
+ End If
+ ' copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _data, 0, length)
+ ' write to file
+ _fs.Write(_data, 0, length)
+ End If
+ End Sub
+
+ Note: If you are into C# the above example can also make use of usafe code blocks using native pointers to read the data from BASS and to write it to a file:
+
+ // within your download callback method...
+ // assuming you have created a: BinaryWriter bw = new BinaryWriter(_fs);
+ unsafe
+ {
+ // simply cast the given IntPtr to a native pointer to short values
+ // assuming you receive 16-bit sample data here
+ short *data = (short*)buffer;
+ for (int a = 0; a < length/2; a++)
+ {
+ // write the received sample data to a local file
+ bw.Write( data[a] );
+ }
+ }
+
+
+ private volatile bool _order10 = false; // the order 10 flag
+ private SYNCPROC _mySyncProc;
+ ...
+ // set the one-time order 10 sync
+ _mySyncProc = new SYNCPROC(MySync);
+ Bass.BASS_ChannelSetSync(music, BASSSync.BASS_SYNC_MUSICPOS | BASSSync.BASS_SYNC_ONETIME,
+ Utils.MakeLong64(10,0), _mySyncProc, IntPtr.Zero);
+ while (!_order10)
+ {
+ // order 10 has not arrived, so do some processing
+ Thread.Sleep(0);
+ }
+ // order 10 has arrived!
+ ...
+ // the sync callback
+ private void MySync(int syncHandle, int channel, int data, IntPtr user)
+ {
+ _order10 = true; // set the order 10 flag
+ }
+
+
+ Private _order10 As Boolean = False ' the order 10 flag
+ Private _mySyncProc As SYNCPROC
+ ...
+ ' set the one-time order 10 sync
+ _mySyncProc = New SYNCPROC(AddressOf MySync)
+ Bass.BASS_ChannelSetSync(music, BASSSync.BASS_SYNC_MUSICPOS Or BASSSync.BASS_SYNC_ONETIME,
+ Utils.MakeLong64(10, 0), _mySyncProc, IntPtr.Zero)
+ While Not _order10
+ ' order 10 has not arrived, so do some processing
+ Thread.Sleep(0)
+ End While
+ ' order 10 has arrived!
+ ...
+ ' the sync callback
+ Private Sub MySync(syncHandle As Integer, channel As Integer, data As Integer, user As IntPtr)
+ _order10 = True ' set the order 10 flag
+ End Sub
+
+ Process metadata received from an internet stream:
+
+ private SYNCPROC _mySync;
+ ...
+ int stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, null, 0);
+ // set a sync to get notified on stream title updates
+ _mySync = new SYNCPROC(MetaSync);
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero);
+ Bass.BASS_ChannelPlay(stream, false);
+ ...
+ private void MetaSync(int handle, int channel, int data, IntPtr user)
+ {
+ // BASS_SYNC_META is triggered
+ string[] tags = Bass.BASS_ChannelGetTagsMETA(channel);
+ foreach (string tag in tags)
+ Console.WriteLine(tag);
+ }
+
+
+ Private _mySync As SYNCPROC
+ ...
+ Dim stream As Integer = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, Nothing, 0)
+ ' set a sync to get notified on stream title updates
+ _mySync = New SYNCPROC(AddressOf MetaSync)
+ Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero)
+ Bass.BASS_ChannelPlay(stream, False)
+ ...
+ Private Sub MetaSync(ByVal handle As Integer, ByVal channel As Integer,
+ ByVal data As Integer, ByVal user As IntPtr)
+ ' BASS_SYNC_META is triggered
+ Dim tags() As String = Bass.BASS_ChannelGetTagsMETA(channel)
+ Dim tag As String
+ For Each tag In tags
+ Console.WriteLine(tag)
+ End Sub
+
+ Perform a loop between a start and end position:
+
+ private int _loopSync = 0;
+ private SYNCPROC _loopSyncCallback;
+ ...
+ long loopStartPos = 1024; // set to whatever you need
+ long loopEndPos = 20480; // set to whatever you need
+ _loopSyncCallback = new SYNCPROC(LoopSync);
+ _loopSync = Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
+ loopEndPos, _loopSyncCallback, new IntPtr(loopStartPos));
+ ...
+ // to remove the loop call this
+ Bass.Bass.BASS_ChannelRemoveSync(stream, _loopSync);
+ ...
+ // the sync callback
+ private void LoopSync(int syncHandle, int channel, int data, IntPtr user)
+ {
+ // move the position to the start (which is given in the user data)
+ Bass.BASS_ChannelSetPosition(channel, user.ToInt64());
+ }
+
+
+ Private _loopSync As Integer = 0
+ Private _loopSyncCallback As SYNCPROC
+ ...
+ Dim loopStartPos As Long = 1024 ' set to whatever you need
+ Dim loopEndPos As Long = 20480 ' set to whatever you need
+ _loopSyncCallback = New SYNCPROC(AddressOf LoopSync);
+ _loopSync = Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_POS Or BASSSync.BASS_SYNC_MIXTIME,
+ loopEndPos, _loopSyncCallback, New IntPtr(loopStartPos))
+ ...
+ ' to remove the loop call this
+ Bass.Bass.BASS_ChannelRemoveSync(stream, _loopSync)
+ ...
+ ' the sync callback
+ Private Sub LoopSync(ByVal handle As Integer, ByVal channel As Integer,
+ ByVal data As Integer, ByVal user As IntPtr)
+ ' move the position to the start (which is given in the user data)
+ Bass.BASS_ChannelSetPosition(channel, user.ToInt64())
+ End Sub
+
+
+ private RECORDPROC _myRecProc; // make it global, so that the GC can not remove it
+ private int _byteswritten = 0;
+ private byte[] _recbuffer; // local recording buffer
+ ...
+ if ( Bass.BASS_RecordInit(-1) )
+ {
+ _myRecProc = new RECORDPROC(MyRecording);
+ int recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero);
+ ...
+ // start recording
+ Bass.BASS_ChannelPlay(recHandle, false);
+ }
+ ...
+ private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ bool cont = true;
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // increase the rec buffer as needed
+ if (_recbuffer == null || _recbuffer.Length < length)
+ _recbuffer = new byte[length];
+ // copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _recbuffer, 0, length);
+ _byteswritten += length;
+ // write to file
+ ...
+ // stop recording after a certain amout (just to demo)
+ if (_byteswritten > 800000)
+ cont = false; // stop recording
+ }
+ return cont;
+ }
+
+
+ Private _myRecProc As RECORDPROC ' make it global, so that the GC can not remove it
+ Private _byteswritten As Integer = 0
+ Private _recbuffer() As Byte ' local recording buffer
+ ...
+ If Bass.BASS_RecordInit(-1) Then
+ _myRecProc = New RECORDPROC(AddressOf MyRecording)
+ Dim recHandle As Integer = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero)
+ ...
+ ' start recording
+ Bass.BASS_ChannelPlay(recHandle, False)
+ End If
+ ...
+ Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
+ Dim cont As Boolean = True
+ If length > 0 AndAlso buffer <> IntPtr.Zero Then
+ ' increase the rec buffer as needed
+ If _recbuffer Is Nothing OrElse _recbuffer.Length < length Then
+ _recbuffer = New Byte(length) {}
+ End If
+ ' copy from managed to unmanaged memory
+ Marshal.Copy(buffer, _recbuffer, 0, length)
+ _byteswritten += length
+ ' write to file
+ ...
+ ' stop recording after a certain amout (just to demo)
+ If _byteswritten > 800000 Then
+ cont = False ' stop recording
+ End If
+ End If
+ Return cont
+ End Function
+
+ If you are into C# you might also use an unsafe codeblock with native pointer access
+ (which might be must faster than the above - depending on what you are doing with the data):
+
+ private unsafe bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
+ {
+ bool cont = true;
+ if (length > 0 && buffer != IntPtr.Zero)
+ {
+ // assuming 16-bit sample data here
+ short *data = (short*)buffer;
+ ...
+
+ // stop recording after a certain amout (just to demo)
+ if (_byteswritten > 800000)
+ cont = false; // stop recording
+ }
+ return cont;
+ }
+
+
+ int len = 0;
+ string title = String.Empty;
+ if ( BassWinamp.BASS_WINAMP_GetFileInfo("testfile.mp3", ref title, ref len) )
+ {
+ Console.WriteLine( "Title={0}, Length={1}ms", title, len );
+ }
+
+
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+ if (pluginHandle != 0)
+ {
+ BassWinamp.BASS_WINAMP_InfoDlg( "test.mp3", this.Handle );
+ }
+
+
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+ if (pluginHandle != 0)
+ {
+ Console.WriteLine( BassWinamp.BASS_WINAMP_GetName(pluginHandle) );
+ }
+
+
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+ if (pluginHandle != 0)
+ {
+ Console.WriteLine( BassWinamp.BASS_WINAMP_GetExtentionsFilter(pluginHandle) );
+ }
+
+
+ string[] waPlugIns = BassWinamp.BASS_WINAMP_FindPlugins( @"C:\Programme\Winamp\Plugins", BASSWINAMPFindPlugin.BASS_WINAMP_FIND_INPUT | BASSWINAMPFindPlugin.BASS_WINAMP_FIND_RECURSIVE );
+ foreach (string waPlugIn in waPlugIns)
+ {
+ Console.WriteLine( waPlugIn );
+ }
+
+
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+
+ Typically you will use one of the returned strings of
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+ if (pluginHandle != 0)
+ {
+ BassWinamp.BASS_WINAMP_ConfigPlugin( pluginHandle, this.Handle );
+ }
+
+
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+ if (pluginHandle != 0)
+ {
+ BassWinamp.BASS_WINAMP_AboutPlugin( pluginHandle, this.Handle );
+ }
+
+
+ int pluginHandle = BassWinamp.BASS_WINAMP_LoadPlugin( @"C:\Programme\Winamp\Plugins\in_mp3.dll" );
+ if (pluginHandle != 0)
+ {
+ int waStream = BassWinamp.BASS_WINAMP_StreamCreate( "test.mp3", BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_STREAM_AUTOFREE );
+ if (waStream != 0)
+ {
+ Bass.BASS_ChannelPlay( waStream, false );
+ }
+ }
+
+