| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
| 3 |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| 4 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 5 |
<head> |
| 6 |
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> |
| 7 |
<meta name="generator" content="AsciiDoc 8.6.10" /> |
| 8 |
<title>The libtwolame API</title> |
| 9 |
<link rel="stylesheet" href="./asciidoc.css" type="text/css" /> |
| 10 |
|
| 11 |
|
| 12 |
<link rel="stylesheet" href="./twolame.css" type="text/css" /> |
| 13 |
<script type="text/javascript" src="./asciidoc.js"></script> |
| 14 |
<script type="text/javascript"> |
| 15 |
/*<![CDATA[*/ |
| 16 |
asciidoc.install(); |
| 17 |
/*]]>*/ |
| 18 |
</script> |
| 19 |
</head> |
| 20 |
<body class="article"> |
| 21 |
<div id="header"> |
| 22 |
<h1>The libtwolame API</h1> |
| 23 |
<span id="revnumber">version 0.4.0</span> |
| 24 |
</div> |
| 25 |
<div id="content"> |
| 26 |
<div id="preamble"> |
| 27 |
<div class="sectionbody"> |
| 28 |
<div class="paragraph"><p>This is the interface for encoding PCM audio to MPEG Audio Layer 2.</p></div> |
| 29 |
<div class="paragraph"><p>It is <em>very</em> similar to the libmp3lame API.</p></div> |
| 30 |
<div class="paragraph"><p>See simplefrontend/simplefrontend.c for a very simple application |
| 31 |
using the API.</p></div> |
| 32 |
</div> |
| 33 |
</div> |
| 34 |
<div class="sect1"> |
| 35 |
<h2 id="_steps_to_encode_pcm_to_mp2">Steps to encode PCM to MP2</h2> |
| 36 |
<div class="sectionbody"> |
| 37 |
<div class="olist arabic"><ol class="arabic"> |
| 38 |
<li> |
| 39 |
<p> |
| 40 |
Grab a set of default options by calling: |
| 41 |
</p> |
| 42 |
<div class="literalblock"> |
| 43 |
<div class="content"> |
| 44 |
<pre><code>twolame_options *encodeOptions; |
| 45 |
encodeOptions = twolame_init();</code></pre> |
| 46 |
</div></div> |
| 47 |
</li> |
| 48 |
<li> |
| 49 |
<p> |
| 50 |
Adjust those options to suit your requirements. |
| 51 |
See twolame.h for a full list of options. eg. |
| 52 |
</p> |
| 53 |
<div class="literalblock"> |
| 54 |
<div class="content"> |
| 55 |
<pre><code>twolame_set_out_samplerate(encodeOptions, 32000); |
| 56 |
twolame_set_bitrate(encodeOptions, 160);</code></pre> |
| 57 |
</div></div> |
| 58 |
</li> |
| 59 |
<li> |
| 60 |
<p> |
| 61 |
Initialise twolame library with these options by calling: |
| 62 |
</p> |
| 63 |
<div class="literalblock"> |
| 64 |
<div class="content"> |
| 65 |
<pre><code>twolame_init_params(encodeOptions);</code></pre> |
| 66 |
</div></div> |
| 67 |
<div class="literalblock"> |
| 68 |
<div class="content"> |
| 69 |
<pre><code>NOTE: The return value should be checked to see if the options were valid. |
| 70 |
Currently only ever returns 0</code></pre> |
| 71 |
</div></div> |
| 72 |
</li> |
| 73 |
<li> |
| 74 |
<p> |
| 75 |
Encode PCM audio to MP2 by calling: |
| 76 |
</p> |
| 77 |
<div class="literalblock"> |
| 78 |
<div class="content"> |
| 79 |
<pre><code>int twolame_encode_buffer( |
| 80 |
twolame_options *glopts, // the set of options you're using |
| 81 |
const short int leftpcm[], // the left and right audio channels |
| 82 |
const short int rightpcm[], |
| 83 |
int num_samples, // the number of samples in each channel |
| 84 |
unsigned char *mp2buffer, // a pointer to a buffer for the MP2 audio data |
| 85 |
// NB User must allocate space! |
| 86 |
int mp2buffer_size); // The size of the mp2buffer that the user allocated |
| 87 |
int *mp2fill_size);</code></pre> |
| 88 |
</div></div> |
| 89 |
<div class="literalblock"> |
| 90 |
<div class="content"> |
| 91 |
<pre><code>This function returns the number of bytes written into mp2buffer by the library MPEG. |
| 92 |
One frame of MPEG audio will be returned for every 1152 samples of PCM audio. |
| 93 |
Multiple calls can be made to this function. |
| 94 |
It is the users responsibility to:</code></pre> |
| 95 |
</div></div> |
| 96 |
<div class="ulist"><ul> |
| 97 |
<li> |
| 98 |
<p> |
| 99 |
allocate the mp2buffer |
| 100 |
</p> |
| 101 |
</li> |
| 102 |
<li> |
| 103 |
<p> |
| 104 |
read the pcmaudio from somewhere with new samples always staring from |
| 105 |
the beginning of the buffer |
| 106 |
</p> |
| 107 |
</li> |
| 108 |
<li> |
| 109 |
<p> |
| 110 |
write the mp2buffer contents to somewhere (it is overwritten with each call) |
| 111 |
</p> |
| 112 |
</li> |
| 113 |
</ul></div> |
| 114 |
</li> |
| 115 |
<li> |
| 116 |
<p> |
| 117 |
Flush the encoder by calling: |
| 118 |
</p> |
| 119 |
<div class="literalblock"> |
| 120 |
<div class="content"> |
| 121 |
<pre><code>int twolame_encode_flush( |
| 122 |
twolame_options *glopts, |
| 123 |
unsigned char *mp2buffer, |
| 124 |
int mp2buffer_size);</code></pre> |
| 125 |
</div></div> |
| 126 |
<div class="literalblock"> |
| 127 |
<div class="content"> |
| 128 |
<pre><code>When encoding is finished, unless there was exactly a multiple of 1152 samples/channel |
| 129 |
sent to the encoder, there will be some remaining audio that is not encoded. This function |
| 130 |
encodes this last bit of audio by padding out with zeros until there is 1152 samples per channel |
| 131 |
in the PCM audio buffers and then encoding this.</code></pre> |
| 132 |
</div></div> |
| 133 |
<div class="literalblock"> |
| 134 |
<div class="content"> |
| 135 |
<pre><code>This function returns the number of bytes written into mp2buffer by the library MPEG.</code></pre> |
| 136 |
</div></div> |
| 137 |
</li> |
| 138 |
<li> |
| 139 |
<p> |
| 140 |
The user must "de-initialise" the encoder at the end by calling: |
| 141 |
</p> |
| 142 |
<div class="literalblock"> |
| 143 |
<div class="content"> |
| 144 |
<pre><code>void twolame_close(twolame_options **glopts);</code></pre> |
| 145 |
</div></div> |
| 146 |
<div class="literalblock"> |
| 147 |
<div class="content"> |
| 148 |
<pre><code>This function must be called to free all the memory and structures |
| 149 |
associated with this set of encoding parameters. |
| 150 |
POST: glopts = NULL</code></pre> |
| 151 |
</div></div> |
| 152 |
</li> |
| 153 |
</ol></div> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
</div> |
| 157 |
<div id="footnotes"><hr /></div> |
| 158 |
<div id="footer"> |
| 159 |
<div id="footer-text"> |
| 160 |
Version 0.4.0<br /> |
| 161 |
Last updated |
| 162 |
2019-10-11 17:26:25 BST |
| 163 |
</div> |
| 164 |
</div> |
| 165 |
</body> |
| 166 |
</html> |