The toolame API

This is the interface for encoding PCM audio to MPEG Audio Layer 2.

See simplefrontend/simplefrontend.c for a very simple application
using the API.


Steps to encode PCM to MP2
========================================================
1. Grab a set of default options by calling:
       toolame_options *toolame_init(void);

       e.g.  toolame_options *encodeOptions;
             encodeOptions = toolame_init();

2. Adjust those options to suit your requirements. 
   See toolame.h for a full list of options.
       e.g. toolame_setSampleFreq(encodeOptions, 32000);
            toolame_setBitrate(encodeOptions, 160);

3. Initialise toolame library with these options by calling:
       int toolame_init_params(toolame_options *glopts);

       e.g. toolame_init_params(encodeOptions)
  
       NB: The return value should be checked to see if the options were valid.
           Currently only ever returns 0

4. Encode PCM audio to MP2 by calling:
	  int toolame_encode_buffer(
		toolame_options *glopts,   // the set of options you're using
		short int leftpcm[],       // the left and right audio channels
		short int rightpcm[],
		int num_samples,           // the number of samples in each channel
		unsigned char *mp2buffer,  // a pointer to a buffer for the MP2 audio data
					   // NB User must allocate space!
		int mp2buffer_size,	   // The size of the mp2buffer that the user allocated
		int *mp2fill_size);	   // The number of bytes written into the buffer by the library

	  This function returns the number of complete MPEG audio frames written into mp2buffer.
	  Multiple calls can be made to this function. 
	  It is the users responsibility to 
	     allocate the mp2buffer
	     read the pcmaudio from somewhere with new samples always staring from the beginning of the buffer
	     write the mp2buffer contents to somewhere (it is overwritten with each call)
	     
5. Flush the encoder by calling: 
	 int toolame_encode_flush(
	     toolame_options *glopts, 
	     unsigned char *mp2buffer, 
	     int mp2buffer_size, 
	     int *mp2fill_size);

	  When encoding is finished, unless there was exactly a multiple of 1152 samples/channel
	  sent to the encoder, there will be some remaining audio that is not encoded. This function
	  encodes this last bit of audio by padding out with zeros until there is 1152 samples per channel
	  in the PCM audio buffers and then encoding this.
	  This function returns the number of frames encoded. It will only be 0 or 1 frames.

6.  The user must "de-initialise" the encoder at the end by calling:
	void toolame_deinit(toolame_options *glopts);

	This function must be called to free all the memory and structures 
	associated with this set of encoding parameters.
	POST: glopts = NULL