Convert floating-point sample data to 8/16/24/32 bit integer. If the encoder does not support 32-bit floating-point sample data, one of these flags can be used to have the sample data converted to integer before it is fed to the encoder. These flags are ignored if the channel is not floating-point and the BASS_CONFIG_FLOATDSP option is not enabled.

BASS_ENCODE_FP_AUTO

Convert floating-point sample data back to the channel's format (8/16 bit integer) if the data is only floating-point due to the BASS_CONFIG_FLOATDSP option being enabled.

Queue data to feed the encoder asynchronously. This prevents the data source (DSP system or BASS_Encode_Write 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_LIMIT

Limit the encoding rate to real-time speed, by introducing a delay when the rate is too high. With BASS 2.4.6 or above, this flag is ignored when the encoder is fed in a playback buffer update cycle (including BASS_Update and BASS_ChannelUpdate calls), to avoid possibly causing playback buffer underruns. Except for in those instances, this flag is applied automatically when the encoder is feeding a Shoutcast or Icecast server.

BASS_ENCODE_CAST_NOLIMIT

Don't limit the encoding rate to real-time speed when feeding a Shoutcast or Icecast server. This flag overrides the BASS_ENCODE_LIMIT flag.

BASS_ENCODE_PAUSE

Start the encoder in a paused state.

BASS_ENCODE_AUTOFREE

Automatically free the encoder when the source channel is freed. If queuing is enabled, any remaining queued data will be sent to the encoder before it is freed.

BASS_UNICODE

cmdline is in UTF-16 form. Otherwise it is ANSI on Windows or Windows CE, and UTF-8 on other platforms.

proc

Optional callback function to receive the encoded data... NULL = no callback. To have the encoded data received by a callback function, the encoder needs to be told to output to STDOUT.

user

User instance data to pass to the callback function.

limit

The number of bytes of sample data to encode... 0 = unlimited. If one of the BASS_ENCODE_FP flags is used, the limit is applied after the effect of that, ie. the limit is based on the file's sample format rather than the source's.

Return value

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

Error codes

BASS_ERROR_HANDLE

handle is not valid.

BASS_ERROR_FILEOPEN

The encoder could not be started. Check that the executable exists.

BASS_ERROR_CREATE

The PCM file could not be created.

BASS_ERROR_NOTAVAIL

External encoders are not supported.

BASS_ERROR_UNKNOWN

Some other mystery problem!

Remarks

This function is identical to BASS_Encode_Start, with the additional ability to limit the amount of sample data that is fed to the encoder. This can be useful in situations where the encoder needs to know in advance how much data it will be receiving. For example, when using a callback function with a file format that stores the length in the header, as the header cannot then be updated at the end of encoding. The length is communicated to the encoder via the WAVE header, so it requires that the BASS_ENCODE_NOHEAD flag is not used.

Once the limit is hit, the encoder will "die". BASS_Encode_SetNotify can be used to be notified of that occurrence.

Example

Start encoding a channel to an MP3 file (output.mp3) using LAME with the standard preset settings, limiting it to 1000000 bytes of sample data.