User defined callback function to encode sample data.
DWORD CALLBACK EncoderProc( HENCODE handle, DWORD channel, void *buffer, DWORD length, DWORD maxout, void *user );
handle | The encoder handle. |
channel | The channel that the encoder is set on. |
buffer | Buffer containing the sample data on input, and containing the encoded data on output. |
length | The number of bytes in the buffer... -1 = the encoder is being freed (no data in the buffer). |
maxout | The maximum amount of encoded data that can be placed in the buffer. |
user | The user instance data given when BASS_Encode_StartUser was called. |
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; }