BASS.NET API for the Un4seen BASS Audio LibraryWMENCODEPROC DelegateBASS.NET API for the Un4seen BASS Audio Library
Encoded data processing callback function.

Namespace: Un4seen.Bass.AddOn.Wma
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.12.0
Syntax

public delegate void WMENCODEPROC(
	int handle,
	BASSWMAEncodeCallback type,
	IntPtr buffer,
	int length,
	IntPtr user
)

Parameters

handle
Type: SystemInt32
The encoder handle (as returned by BASS_WMA_EncodeOpen(Int32, Int32, BASSWMAEncode, Int32, WMENCODEPROC, IntPtr)).
type
Type: Un4seen.Bass.AddOn.WmaBASSWMAEncodeCallback
The type of data to process, one of the following (see BASSWMAEncodeCallback):

BASS_WMA_ENCODE_HEAD : The data in the buffer is the header.

BASS_WMA_ENCODE_DATA : The data in the buffer is encoded sample data.

BASS_WMA_ENCODE_DONE : The encoding has finished... buffer and length will both be intPtr.Zero resp. 0.

buffer
Type: SystemIntPtr
The pointer to the data to process. The buffer can contain the sample data or the header (see above). The sample data is in standard Windows PCM format - 8-bit samples are unsigned, 16-bit samples are signed.
length
Type: SystemInt32
The number of bytes in the buffer.
user
Type: SystemIntPtr
The user instance data given when BASS_WMA_EncodeOpen(Int32, Int32, BASSWMAEncode, Int32, WMENCODEPROC, IntPtr) was called.
Remarks

When encoding begins, an initial header is given. When encoding is completed, an updated header is given (with the duration info, etc.). When encoding to a file (whether that's on disk or not), the initial header should be replaced by the updated one.

NOTE: When you pass an instance of a callback delegate to one of the BASS functions, this delegate object will not be reference counted. This means .NET would not know, that it might still being used by BASS. The Garbage Collector might (re)move the delegate instance, if the variable holding the delegate is not declared as global. So make sure to always keep your delegate instance in a variable which lives as long as BASS needs it, e.g. use a global variable or member.

Examples

VB
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
// 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);
  }
}
NOTE: This is just an example. It's obviously simpler to use BASS_WMA_EncodeOpenFile(Int32, Int32, BASSWMAEncode, Int32, String) to encode to a file.
See Also

Reference