File: api.txt

package info (click to toggle)
twolame 0.3.13-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,800 kB
  • sloc: sh: 11,099; ansic: 9,332; perl: 286; makefile: 171
file content (81 lines) | stat: -rw-r--r-- 2,748 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
The libtwolame API
==================

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

It is 'very' similar to the libmp3lame API.

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:

		twolame_options *encodeOptions;
		encodeOptions = twolame_init();


2. Adjust those options to suit your requirements. 
   See twolame.h for a full list of options. eg.
   
		twolame_set_out_samplerate(encodeOptions, 32000);
		twolame_set_bitrate(encodeOptions, 160);


3. Initialise twolame library with these options by calling:
	
		twolame_init_params(encodeOptions);
  
   NOTE: 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 twolame_encode_buffer(
         twolame_options *glopts,   // the set of options you're using
         const short int leftpcm[], // the left and right audio channels
         const 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);
		
   This function returns the number of bytes written into mp2buffer by the library MPEG.
   One frame of MPEG audio will be returned for every 1152 samples of PCM audio.
   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 twolame_encode_flush(
	     twolame_options *glopts, 
	     unsigned char *mp2buffer, 
	     int mp2buffer_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 bytes written into mp2buffer by the library MPEG.

	
6.  The user must "de-initialise" the encoder at the end by calling:

	void twolame_close(twolame_options **glopts);

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