BASS.NET API for the Un4seen BASS Audio LibraryBassEncBASS_Encode_StartACMFile Method (Int32, ACMFORMAT, BASSEncode, String)BASS.NET API for the Un4seen BASS Audio Library
Sets up an encoder on a channel, using an ACM codec and writing the output to a file.

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.12.0
Syntax

public static int BASS_Encode_StartACMFile(
	int handle,
	ACMFORMAT form,
	BASSEncode flags,
	string filename
)

Parameters

handle
Type: SystemInt32
The channel handle... a HSTREAM, HMUSIC, or HRECORD.
form
Type: Un4seen.Bass.AddOn.EncACMFORMAT
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_NOHEADDon't write a WAVE header to the file.
BASS_ENCODE_RF64Write 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_QUEUEQueue 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_PAUSEStart the encoder paused.
BASS_ENCODE_AUTOFREEAutomatically free the encoder when the source channel is freed.
filename
Type: SystemString
The filename to write.

Return Value

Type: Int32
The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

The ACM encoder allows installed ACM (Audio Compression Manager) codecs to be used for encoding. The codec used is determined by the contents of the form parameter. The BASS_Encode_GetACMFormat(Int32, IntPtr, Int32, String, BASSACMFormat) function can be used to initialize that.

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 CODEDescription
BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTAVAILThe codec specified in form couldn't be initialized.
BASS_ERROR_CREATEThe file couldn't be created.
BASS_ERROR_UNKNOWNSome other mystery problem!

Examples

Setup an ACM encoder with a callback to process the encoded data:
VB
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
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" );
}
See Also

Reference