Namespace: Un4seen.Bass.AddOn.Wma
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
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.
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.
// 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); } }