User defined callback function to encode sample data.

    HENCODE handle,
    DWORD channel,
    void *buffer,
    DWORD length,
    DWORD maxout,
    void *user


handleThe encoder handle.
channelThe channel that the encoder is set on.
bufferBuffer containing the sample data on input, and containing the encoded data on output.
lengthThe number of bytes in the buffer... -1 = the encoder is being freed (no data in the buffer).
maxoutThe maximum amount of encoded data that can be placed in the buffer.
userThe user instance data given when BASS_Encode_StartUser was called.

Return value

The number of bytes of encoded data placed in buffer... -1 = stop encoding.


If the encoder output exceeds the outmax value then only the first outmax bytes should be delivered and the remainder retained. The function will be called again immediately to get the remainder. Instead of returning the data in buffer, it is also possible to provide the encoded data via BASS_Encode_UserOutput, which also adds the ability to update previous data (eg. headers).


Use the LAME library to encode the sample data.
DWORD CALLBACK LameEncoderProc(HENCODE handle, DWORD channel, void *buffer, DWORD length, DWORD maxout, void *user)
    lame_t lame=(lame_t)user; // LAME instance
    int outlen;
    if (length==(DWORD)-1) { // closing
        outlen=lame_encode_flush(lame, buffer, maxout); // flush the encoder
    } else if (lame_get_num_channels(lame)==1) {
        outlen=lame_encode_buffer(lame, buffer, NULL, length/sizeof(short), buffer, maxout); // encode mono data
    } else {
        outlen=lame_encode_buffer_interleaved(lame, buffer, length/sizeof(short)/2, buffer, maxout); // encode stereo data
    if (outlen<0) return 0; // failed, no output
    return outlen;

See also

BASS_Encode_StartUser, BASS_Encode_UserOutput