This overload represents the Unicode version for the file name. The BASS_UNICODE flag will automatically be added if missing.
Namespace: Un4seen.Bass.AddOn.Enc
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
public static int BASS_Encode_StartACMFile( int handle, IntPtr form, BASSEncode flags, string filename )
Parameters
- handle
- Type: SystemInt32
The channel handle... a HSTREAM, HMUSIC, or HRECORD. - form
- Type: SystemIntPtr
ACM codec output format (buffer as returned by BASS_Encode_GetACMFormat(Int32, IntPtr, Int32, String, BASSACMFormat)). - flags
- Type: Un4seen.Bass.AddOn.EncBASSEncode
A combination of these flags BASSEncode:BASS_ENCODE_NOHEAD Don't write a WAVE header to the file. BASS_ENCODE_RF64 Write an RF64 header instead of a standard RIFF header, allowing the file to go beyond 4GB in size. This flag is ignored if the BASS_ENCODE_NOHEAD flag is used. BASS_ENCODE_QUEUE Queue data to feed the encoder asynchronously. This prevents the data source (DSP system or BASS_Encode_Write(Int32, IntPtr, Int32) call) getting blocked by the encoder, but if data is queud more quickly than the encoder can process it, that could result in lost data. BASS_ENCODE_PAUSE Start the encoder paused. BASS_ENCODE_AUTOFREE Automatically free the encoder when the source channel is freed. - filename
- Type: SystemString
The filename to write.
Return Value
Type: Int32The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
Unless the BASS_ENCODE_NOHEAD flag is specified, a WAVE header and the form contents will be written to the file. This is generally required for the file to be playable, but in some cases (eg. MP3) it's not. Standard RIFF WAV files are limited to a little over 4GB in size, so BASSenc will automatically stop encoding at that point. That size limit can be overcome with an RF64 file. When writing an RF64 WAV file, a standard RIFF header will still be written initially, which will only be replaced by an RF64 header at the end if the file size has exceeded the standard limit.
Internally, the sending of sample data to the encoder is implemented via a DSP callback on the channel. That means when you play the channel (or call BASS_ChannelGetData(Int32, IntPtr, Int32) if it's a decoding channel), the sample data will be sent to the encoder at the same time. The encoding is performed in the DSP callback. There isn't a separate process doing the encoding, as when using an external encoder via BASS_Encode_Start(Int32, String, BASSEncode, ENCODEPROC, IntPtr).
By default, the encoder DSP has a priority setting of -1000, which determines where in the DSP chain the encoding is performed. That can be changed using the BASS_CONFIG_ENCODE_PRIORITY config option (see BASS_SetConfig(BASSConfig, Int32)).
Besides the automatic DSP system, data can also be manually fed to the encoder via the BASS_Encode_Write(Int32, IntPtr, Int32) function. Both methods can be used together, but in general, the "automatic" system ought be paused when using the "manual" system, by use of the BASS_ENCODE_PAUSE flag or the BASS_Encode_SetPaused(Int32, Boolean) function.
When done encoding, use BASS_Encode_Stop(Int32) to close the encoder.
Multiple encoders can be set on a channel. For simplicity, the encoder functions will accept either an encoder handle or a channel handle. When using a channel handle, the function is applied to all encoders that are set on that channel.
ERROR CODE | Description |
---|---|
BASS_ERROR_HANDLE | handle is not valid. |
BASS_ERROR_NOTAVAIL | The codec specified in form couldn't be initialized. |
BASS_ERROR_CREATE | The file couldn't be created. |
BASS_ERROR_UNKNOWN | Some other mystery problem! |
// 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" ); }