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.


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 {
        int samples=length/lame_get_num_channels(lame)/sizeof(short);
        outlen=lame_encode_buffer_interleaved(lame, buffer, samples, buffer, maxout); // encode the data
    if (outlen<0) return 0; // failed, no output
    return outlen;

See also