├── .gitignore ├── .jsdocrc ├── .jshintrc ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── appveyor.yml ├── dist └── alawmulaw.js ├── docs ├── index.html ├── index.js.html ├── lib_alaw.js.html ├── lib_mulaw.js.html ├── module-alawmulaw.html ├── module-alawmulaw_alaw.html ├── module-alawmulaw_mulaw.html ├── scripts │ ├── collapse.js │ ├── linenumber.js │ ├── nav.js │ ├── polyfill.js │ ├── prettify │ │ ├── Apache-License-2.0.txt │ │ ├── lang-css.js │ │ └── prettify.js │ └── search.js └── styles │ ├── jsdoc.css │ └── prettify.css ├── externs └── alawmulaw.js ├── index.d.ts ├── index.js ├── lib ├── alaw.js └── mulaw.js ├── package-lock.json ├── package.json ├── rollup.config.js └── test ├── dist ├── AMD │ ├── app.js │ ├── app │ │ └── main.js │ ├── index.html │ └── lib │ │ └── require.js ├── TypeScript │ ├── main.js │ └── main.ts └── browser.html ├── loader.js └── src ├── decode.js └── encode.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.DS_Store 3 | .nyc_output 4 | node_modules -------------------------------------------------------------------------------- /.jsdocrc: -------------------------------------------------------------------------------- 1 | { 2 | "templates": { 3 | "default": { 4 | "includeDate": false 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esversion": 6, 3 | "bitwise": false 4 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.reapeaks 3 | *.DS_Store 4 | 5 | # Development folders 6 | .nyc_output/ 7 | docs/ 8 | test/ 9 | 10 | # Development files 11 | .gitignore 12 | .jshintrc 13 | .npmignore 14 | .travis.yml 15 | appveyor.yml 16 | rollup.config.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | os: 3 | - linux 4 | - osx 5 | node_js: 6 | - "8" 7 | - "9" 8 | - "10" 9 | - "12" 10 | script: 11 | - npm run build 12 | after_success: 13 | - npm run coverage -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 6.0.0 - 2019-12-31 4 | - New package structure: 5 | * dist file is "./dist/alawmulaw.js", a UMD served as "main" 6 | * ES6 source is "./index.js", served as "module" 7 | - Fix: clip mulaw samples after add bias (https://github.com/rochars/alawmulaw/issues/2) 8 | 9 | ## v5.0.2 (2018-07-08) 10 | - Fix: UMD dist for browsers. 11 | 12 | ## v5.0.1 (2018-07-08) 13 | - UMD dist transpiled to ES5 14 | - Different mu-Law algorithm; should sound the same. 15 | 16 | ## v5.0.0 (2018-07-01) 17 | - Add TypeScript declaration 18 | - Using typed arrays for input and ouput 19 | - ES module API changed; export {alaw, mulaw} instead of default alawmulaw 20 | 21 | ## v4.1.0 (2018-06-25) 22 | - Allow better use of this lib as a dependency: 23 | - package.json refactored with bundlers and ES6 envs in mind 24 | 25 | ## v4.0.0 (2018-06-22) 26 | - ES6 module. 27 | 28 | ## v3.0.0 (2018-06-17) 29 | - New dist file: ./dist/alawmulaw.min.js. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2019 Rafael da Silva Rocha. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alawmulaw 2 | Copyright (c) 2018-2019 Rafael da Silva Rocha. 3 | https://github.com/rochars/alawmulaw 4 | 5 | [![NPM version](https://img.shields.io/npm/v/alawmulaw.svg?style=for-the-badge)](https://www.npmjs.com/package/alawmulaw) [![Docs](https://img.shields.io/badge/docs-online-blue.svg?style=for-the-badge)](https://rochars.github.io/alawmulaw/index.html) [![Tests](https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge)](https://rawgit.com/rochars/alawmulaw/master/test/dist/browser.html) 6 | [![Codecov](https://img.shields.io/codecov/c/github/rochars/alawmulaw.svg?style=flat-square)](https://codecov.io/gh/rochars/alawmulaw) [![Unix Build](https://img.shields.io/travis/rochars/alawmulaw.svg?style=flat-square)](https://travis-ci.org/rochars/alawmulaw) [![Windows Build](https://img.shields.io/appveyor/ci/rochars/alawmulaw.svg?style=flat-square&logo=appveyor)](https://ci.appveyor.com/project/rochars/alawmulaw) [![Scrutinizer](https://img.shields.io/scrutinizer/g/rochars/alawmulaw.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/rochars/alawmulaw/) 7 | 8 | A-Law and mu-Law codecs in JavaScript. 9 | 10 | ## Install 11 | ``` 12 | npm install alawmulaw 13 | ``` 14 | 15 | ## Use 16 | 17 | ### Browser 18 | Use the **alawmulaw.js** file in the */dist* folder: 19 | ```html 20 | 21 | 34 | ``` 35 | 36 | Or get it from the [jsDelivr](https://www.jsdelivr.com) CDN: 37 | ```html 38 | 39 | ``` 40 | 41 | Or get it from [unpkg](https://www.unpkg.com): 42 | ```html 43 | 44 | ``` 45 | 46 | ### Node 47 | Require from 'alawmulaw' 48 | ```javascript 49 | const alawmulaw = require('alawmulaw'); 50 | 51 | // Encode all the samples in a file 52 | // Only 16-bit samples are supported 53 | let aLawSamples = alawmulaw.alaw.encode(pcmSamples); 54 | ``` 55 | 56 | ## API 57 | 58 | ### alawmulaw.alaw 59 | ```javascript 60 | 61 | /** 62 | * Encode a 16-bit linear PCM sample as 8-bit A-Law. 63 | * @param {number} sample A 16-bit PCM sample 64 | * @return {number} 65 | */ 66 | export function encodeSample(sample) {} 67 | 68 | /** 69 | * Decode a 8-bit A-Law sample as 16-bit PCM. 70 | * @param {number} aLawSample The 8-bit A-Law sample 71 | * @return {number} 72 | */ 73 | export function decodeSample(aLawSample) {} 74 | 75 | /** 76 | * Encode 16-bit linear PCM samples as 8-bit A-Law samples. 77 | * @param {!Int16Array} samples A array of 16-bit PCM samples. 78 | * @return {!Uint8Array} 79 | */ 80 | export function encode(samples) {} 81 | 82 | /** 83 | * Decode 8-bit A-Law samples into 16-bit linear PCM samples. 84 | * @param {!Uint8Array} samples A array of 8-bit A-Law samples. 85 | * @return {!Int16Array} 86 | */ 87 | export function decode(samples) {} 88 | ``` 89 | 90 | ### alawmulaw.mulaw 91 | ```javascript 92 | /** 93 | * Encode a 16-bit linear PCM sample as 8-bit mu-Law. 94 | * @param {number} sample A 16-bit PCM sample 95 | * @return {number} 96 | */ 97 | export function encodeSample(sample) {} 98 | 99 | /** 100 | * Decode a 8-bit mu-Law sample as 16-bit PCM. 101 | * @param {number} muLawSample The 8-bit mu-Law sample 102 | * @return {number} 103 | */ 104 | export function decodeSample(muLawSample) {} 105 | 106 | /** 107 | * Encode 16-bit linear PCM samples into 8-bit mu-Law samples. 108 | * @param {!Int16Array} samples A array of 16-bit PCM samples. 109 | * @return {!Uint8Array} 110 | */ 111 | export function encode(samples) {} 112 | 113 | /** 114 | * Decode 8-bit mu-Law samples into 16-bit PCM samples. 115 | * @param {!Uint8Array} samples A array of 8-bit mu-Law samples. 116 | * @return {!Int16Array} 117 | */ 118 | export function decode(samples) {} 119 | ``` 120 | 121 | ## References 122 | https://github.com/torvalds/linux/blob/master/sound/core/oss/mulaw.c 123 | https://github.com/deftio/companders 124 | http://dystopiancode.blogspot.com.br/2012/02/pcm-law-and-u-law-companding-algorithms.html 125 | 126 | ### LICENSE 127 | Copyright (c) 2018-2019 Rafael da Silva Rocha. 128 | 129 | Permission is hereby granted, free of charge, to any person obtaining 130 | a copy of this software and associated documentation files (the 131 | "Software"), to deal in the Software without restriction, including 132 | without limitation the rights to use, copy, modify, merge, publish, 133 | distribute, sublicense, and/or sell copies of the Software, and to 134 | permit persons to whom the Software is furnished to do so, subject to 135 | the following conditions: 136 | 137 | The above copyright notice and this permission notice shall be 138 | included in all copies or substantial portions of the Software. 139 | 140 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 141 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 142 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 143 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 144 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 145 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 146 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 147 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: "8" 4 | - nodejs_version: "9" 5 | - nodejs_version: "10" 6 | - nodejs_version: "12" 7 | 8 | install: 9 | - ps: Install-Product node $env:nodejs_version 10 | - npm -g install npm@latest 11 | - npm install 12 | 13 | test_script: 14 | - node --version 15 | - npm --version 16 | - cmd: npm run build 17 | 18 | build: off 19 | 20 | version: "{build}" 21 | 22 | matrix: 23 | fast_finish: true -------------------------------------------------------------------------------- /dist/alawmulaw.js: -------------------------------------------------------------------------------- 1 | (function(d,e){"object"===typeof exports&&"undefined"!==typeof module?e(exports):"function"===typeof define&&define.amd?define(["exports"],e):(d=d||self,e(d.alawmulaw={}))})(this,function(d){function e(a){a=-32768==a?-32767:a;var c=~a>>8&128;c||(a*=-1);32635>8&127];a=b<<4|a>>b+3&15}else a>>=4;return a^c^85}function f(a){var c=0;a^=85;a&128&&(a&=-129,c=-1);var b=((a&240)>>4)+4;a=4!=b?1<>8&128; 2 | 0!=c&&(a=-a);a+=132;32635>7&255];return~(c|b<<4|a>>b+3&15)}function h(a){a=~a;var c=a>>4&7;c=m[c]+((a&15)< 2 | 3 | 4 | 5 | 6 | Home - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 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 |

alawmulaw

61 |

Copyright (c) 2018-2019 Rafael da Silva Rocha.
62 | https://github.com/rochars/alawmulaw

63 |

NPM version Docs Tests
64 | Codecov Unix Build Windows Build Scrutinizer

65 |

A-Law and mu-Law codecs in JavaScript.

66 |

Install

67 |
npm install alawmulaw
 68 | 
69 |

Use

70 |

Browser

71 |

Use the alawmulaw.js file in the /dist folder:

72 |
<script src="alawmulaw.js"></script>
 73 | <script>
 74 |     // A-Law
 75 |     samples = alawmulaw.alaw.encode(samples);
 76 |     samples = alawmulaw.alaw.decode(samples);
 77 |     sample = alawmulaw.alaw.encodeSample(sample);
 78 |     sample = alawmulaw.alaw.decodeSample(sample);
 79 | 
 80 |     // mu-Law
 81 |     samples = alawmulaw.mulaw.encode(samples);
 82 |     samples = alawmulaw.mulaw.decode(samples);
 83 |     sample = alawmulaw.mulaw.encodeSample(sample);
 84 |     sample = alawmulaw.mulaw.decodeSample(sample);
 85 | </script>
 86 | 
87 |

Or get it from the jsDelivr CDN:

88 |
<script src="https://cdn.jsdelivr.net/npm/alawmulaw"></script>
 89 | 
90 |

Or get it from unpkg:

91 |
<script src="https://unpkg.com/alawmulaw"></script>
 92 | 
93 |

Node

94 |

Require from 'alawmulaw'

95 |
const alawmulaw = require('alawmulaw');
 96 | 
 97 | // Encode all the samples in a file
 98 | // Only 16-bit samples are supported
 99 | let aLawSamples = alawmulaw.alaw.encode(pcmSamples);
100 | 
101 |

API

102 |

alawmulaw.alaw

103 |

104 | /**
105 |  * Encode a 16-bit linear PCM sample as 8-bit A-Law.
106 |  * @param {number} sample A 16-bit PCM sample
107 |  * @return {number}
108 |  */
109 | export function encodeSample(sample) {}
110 | 
111 | /**
112 |  * Decode a 8-bit A-Law sample as 16-bit PCM.
113 |  * @param {number} aLawSample The 8-bit A-Law sample
114 |  * @return {number}
115 |  */
116 | export function decodeSample(aLawSample) {}
117 | 
118 | /**
119 |  * Encode 16-bit linear PCM samples as 8-bit A-Law samples.
120 |  * @param {!Int16Array} samples A array of 16-bit PCM samples.
121 |  * @return {!Uint8Array}
122 |  */
123 | export function encode(samples) {}
124 | 
125 | /**
126 |  * Decode 8-bit A-Law samples into 16-bit linear PCM samples.
127 |  * @param {!Uint8Array} samples A array of 8-bit A-Law samples.
128 |  * @return {!Int16Array}
129 |  */
130 | export function decode(samples) {}
131 | 
132 |

alawmulaw.mulaw

133 |
/**
134 |  * Encode a 16-bit linear PCM sample as 8-bit mu-Law.
135 |  * @param {number} sample A 16-bit PCM sample
136 |  * @return {number}
137 |  */
138 | export function encodeSample(sample) {}
139 | 
140 | /**
141 |  * Decode a 8-bit mu-Law sample as 16-bit PCM.
142 |  * @param {number} muLawSample The 8-bit mu-Law sample
143 |  * @return {number}
144 |  */
145 | export function decodeSample(muLawSample) {}
146 | 
147 | /**
148 |  * Encode 16-bit linear PCM samples into 8-bit mu-Law samples.
149 |  * @param {!Int16Array} samples A array of 16-bit PCM samples.
150 |  * @return {!Uint8Array}
151 |  */
152 | export function encode(samples) {}
153 | 
154 | /**
155 |  * Decode 8-bit mu-Law samples into 16-bit PCM samples.
156 |  * @param {!Uint8Array} samples A array of 8-bit mu-Law samples.
157 |  * @return {!Int16Array}
158 |  */
159 | export function decode(samples) {}
160 | 
161 |

References

162 |

https://github.com/torvalds/linux/blob/master/sound/core/oss/mulaw.c
163 | https://github.com/deftio/companders
164 | http://dystopiancode.blogspot.com.br/2012/02/pcm-law-and-u-law-companding-algorithms.html

165 |

LICENSE

166 |

Copyright (c) 2018-2019 Rafael da Silva Rocha.

167 |

Permission is hereby granted, free of charge, to any person obtaining 168 | a copy of this software and associated documentation files (the 169 | "Software"), to deal in the Software without restriction, including 170 | without limitation the rights to use, copy, modify, merge, publish, 171 | distribute, sublicense, and/or sell copies of the Software, and to 172 | permit persons to whom the Software is furnished to do so, subject to 173 | the following conditions:

174 |

The above copyright notice and this permission notice shall be 175 | included in all copies or substantial portions of the Software.

176 |

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 177 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 178 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 179 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 180 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 181 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 182 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

183 |
184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
194 | 195 |
196 | 197 |

198 | index.js 199 |

200 | 201 | 202 |
203 | 204 |
205 | 206 |
207 | 208 | 209 | 210 |
211 | 212 | 213 |
Source:
214 |
217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | 253 | 254 |
The alawmulaw API.
255 | 256 | 257 | 258 | 259 |
260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 |
282 | 283 |
284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 |
292 | 293 |
294 | 295 |

296 | lib/alaw.js 297 |

298 | 299 | 300 |
301 | 302 |
303 | 304 |
305 | 306 | 307 | 308 |
309 | 310 | 311 |
Source:
312 |
315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 |
347 | 348 | 349 | 350 | 351 | 352 |
A-Law codec.
353 | 354 | 355 | 356 | 357 |
358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 |
380 | 381 |
382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 |
390 | 391 |
392 | 393 |

394 | lib/mulaw.js 395 |

396 | 397 | 398 |
399 | 400 |
401 | 402 |
403 | 404 | 405 | 406 |
407 | 408 | 409 |
Source:
410 |
413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 |
445 | 446 | 447 | 448 | 449 | 450 |
mu-Law codec.
451 | 452 | 453 | 454 | 455 |
456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 |
478 | 479 |
480 | 481 | 482 | 483 | 484 | 485 | 486 |
487 | 488 |
489 | 490 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | -------------------------------------------------------------------------------- /docs/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | index.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

index.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/*
 46 |  * alawmulaw: A-Law and mu-Law codecs in JavaScript.
 47 |  * https://github.com/rochars/alawmulaw
 48 |  *
 49 |  * Copyright (c) 2018 Rafael da Silva Rocha.
 50 |  *
 51 |  * Permission is hereby granted, free of charge, to any person obtaining
 52 |  * a copy of this software and associated documentation files (the
 53 |  * "Software"), to deal in the Software without restriction, including
 54 |  * without limitation the rights to use, copy, modify, merge, publish,
 55 |  * distribute, sublicense, and/or sell copies of the Software, and to
 56 |  * permit persons to whom the Software is furnished to do so, subject to
 57 |  * the following conditions:
 58 |  *
 59 |  * The above copyright notice and this permission notice shall be
 60 |  * included in all copies or substantial portions of the Software.
 61 |  *
 62 |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 63 |  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 64 |  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 65 |  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 66 |  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 67 |  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 68 |  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 69 |  *
 70 |  */
 71 | 
 72 | /**
 73 |  * @fileoverview The alawmulaw API.
 74 |  */
 75 | 
 76 | /**
 77 |  * @module alawmulaw
 78 |  */
 79 | 
 80 | import * as alaw from './lib/alaw';
 81 | import * as mulaw from './lib/mulaw';
 82 | 
 83 | export {alaw, mulaw};
 84 | 
85 |
86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 |
96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /docs/lib_alaw.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | lib/alaw.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

lib/alaw.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/*
 46 |  * alawmulaw: A-Law and mu-Law codecs in JavaScript.
 47 |  * https://github.com/rochars/alawmulaw
 48 |  *
 49 |  * Copyright (c) 2018 Rafael da Silva Rocha.
 50 |  *
 51 |  * Permission is hereby granted, free of charge, to any person obtaining
 52 |  * a copy of this software and associated documentation files (the
 53 |  * "Software"), to deal in the Software without restriction, including
 54 |  * without limitation the rights to use, copy, modify, merge, publish,
 55 |  * distribute, sublicense, and/or sell copies of the Software, and to
 56 |  * permit persons to whom the Software is furnished to do so, subject to
 57 |  * the following conditions:
 58 |  *
 59 |  * The above copyright notice and this permission notice shall be
 60 |  * included in all copies or substantial portions of the Software.
 61 |  *
 62 |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 63 |  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 64 |  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 65 |  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 66 |  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 67 |  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 68 |  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 69 |  *
 70 |  */
 71 | 
 72 | /**
 73 |  * @fileoverview A-Law codec.
 74 |  */
 75 | 
 76 | /** @module alawmulaw/alaw */
 77 | 
 78 | /** @type {!Array<number>} */
 79 | const LOG_TABLE = [
 80 |   1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 
 81 |   6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 
 82 |   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 
 83 |   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 
 84 | ];
 85 | 
 86 | /**
 87 |  * Encode a 16-bit linear PCM sample as 8-bit A-Law.
 88 |  * @param {number} sample A 16-bit PCM sample
 89 |  * @return {number}
 90 |  */
 91 | export function encodeSample(sample) {
 92 |   /** @type {number} */
 93 |   let compandedValue; 
 94 |   sample = (sample ==-32768) ? -32767 : sample;
 95 |   /** @type {number} */
 96 |   let sign = ((~sample) >> 8) & 0x80; 
 97 |   if (!sign) {
 98 |     sample = sample * -1; 
 99 |   }
100 |   if (sample > 32635) {
101 |     sample = 32635; 
102 |   }
103 |   if (sample >= 256)  {
104 |     /** @type {number} */
105 |     let exponent = LOG_TABLE[(sample >> 8) & 0x7F];
106 |     /** @type {number} */
107 |     let mantissa = (sample >> (exponent + 3) ) & 0x0F; 
108 |     compandedValue = ((exponent << 4) | mantissa); 
109 |   } else {
110 |     compandedValue = sample >> 4; 
111 |   } 
112 |   return compandedValue ^ (sign ^ 0x55);
113 | }
114 | 
115 | /**
116 |  * Decode a 8-bit A-Law sample as 16-bit PCM.
117 |  * @param {number} aLawSample The 8-bit A-Law sample
118 |  * @return {number}
119 |  */
120 | export function decodeSample(aLawSample) {
121 |   /** @type {number} */
122 |   let sign = 0;
123 |   aLawSample ^= 0x55;
124 |   if (aLawSample & 0x80) {
125 |     aLawSample &= ~(1 << 7);
126 |     sign = -1;
127 |   }
128 |   /** @type {number} */
129 |   let position = ((aLawSample & 0xF0) >> 4) + 4;
130 |   /** @type {number} */
131 |   let decoded = 0;
132 |   if (position != 4) {
133 |     decoded = ((1 << position) |
134 |       ((aLawSample & 0x0F) << (position - 4)) |
135 |       (1 << (position - 5)));
136 |   } else {
137 |     decoded = (aLawSample << 1)|1;
138 |   }
139 |   decoded = (sign === 0) ? (decoded) : (-decoded);
140 |   return (decoded * 8) * -1;
141 | }
142 | 
143 | /**
144 |  * Encode 16-bit linear PCM samples as 8-bit A-Law samples.
145 |  * @param {!Int16Array} samples A array of 16-bit PCM samples.
146 |  * @return {!Uint8Array}
147 |  */
148 | export function encode(samples) {
149 |   /** @type {!Uint8Array} */
150 |   let aLawSamples = new Uint8Array(samples.length);
151 |   for (let i=0; i<samples.length; i++) {
152 |     aLawSamples[i] = encodeSample(samples[i]);
153 |   }
154 |   return aLawSamples;
155 | }
156 | 
157 | /**
158 |  * Decode 8-bit A-Law samples into 16-bit linear PCM samples.
159 |  * @param {!Uint8Array} samples A array of 8-bit A-Law samples.
160 |  * @return {!Int16Array}
161 |  */
162 | export function decode(samples) {
163 |   /** @type {!Int16Array} */
164 |   let pcmSamples = new Int16Array(samples.length);
165 |   for (let i=0; i<samples.length; i++) {
166 |     pcmSamples[i] = decodeSample(samples[i]);
167 |   }
168 |   return pcmSamples;
169 | }
170 | 
171 |
172 |
173 | 174 | 175 | 176 | 177 | 178 | 179 |
180 | 181 |
182 | 183 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /docs/lib_mulaw.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | lib/mulaw.js - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

lib/mulaw.js

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
/*
 46 |  * alawmulaw: A-Law and mu-Law codecs in JavaScript.
 47 |  * https://github.com/rochars/alawmulaw
 48 |  *
 49 |  * Copyright (c) 2018-2019 Rafael da Silva Rocha.
 50 |  *
 51 |  * Permission is hereby granted, free of charge, to any person obtaining
 52 |  * a copy of this software and associated documentation files (the
 53 |  * "Software"), to deal in the Software without restriction, including
 54 |  * without limitation the rights to use, copy, modify, merge, publish,
 55 |  * distribute, sublicense, and/or sell copies of the Software, and to
 56 |  * permit persons to whom the Software is furnished to do so, subject to
 57 |  * the following conditions:
 58 |  *
 59 |  * The above copyright notice and this permission notice shall be
 60 |  * included in all copies or substantial portions of the Software.
 61 |  *
 62 |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 63 |  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 64 |  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 65 |  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 66 |  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 67 |  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 68 |  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 69 |  *
 70 |  */
 71 | 
 72 | /**
 73 |  * @fileoverview mu-Law codec.
 74 |  */
 75 | 
 76 | /** @module alawmulaw/mulaw */
 77 | 
 78 | /**
 79 |  * @type {number}
 80 |  * @private
 81 |  */
 82 | const BIAS = 0x84;
 83 | /**
 84 |  * @type {number}
 85 |  * @private
 86 |  */
 87 | const CLIP = 32635;
 88 | /**
 89 |  * @type {Array<number>}
 90 |  * @private
 91 |  */
 92 | const encodeTable = [
 93 |     0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
 94 |     4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
 95 |     5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
 96 |     5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
 97 |     6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 98 |     6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 99 |     6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
100 |     6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
101 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
102 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
103 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
104 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
105 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
106 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
107 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
108 |     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7];
109 | /**
110 |  * @type {Array<number>}
111 |  * @private
112 |  */
113 | const decodeTable = [0,132,396,924,1980,4092,8316,16764];
114 | 
115 | /**
116 |  * Encode a 16-bit linear PCM sample as 8-bit mu-Law.
117 |  * @param {number} sample A 16-bit PCM sample
118 |  * @return {number}
119 |  */
120 | export function encodeSample(sample) {
121 |   /** @type {number} */
122 |   let sign;
123 |   /** @type {number} */
124 |   let exponent;
125 |   /** @type {number} */
126 |   let mantissa;
127 |   /** @type {number} */
128 |   let muLawSample;
129 |   /** get the sample into sign-magnitude **/
130 |   sign = (sample >> 8) & 0x80;
131 |   if (sign != 0) sample = -sample;
132 |   /** convert from 16 bit linear to ulaw **/
133 |   sample = sample + BIAS;
134 |   if (sample > CLIP) sample = CLIP;
135 |   exponent = encodeTable[(sample>>7) & 0xFF];
136 |   mantissa = (sample >> (exponent+3)) & 0x0F;
137 |   muLawSample = ~(sign | (exponent << 4) | mantissa);
138 |   /** return the result **/
139 |   return muLawSample;
140 | }
141 | 
142 | /**
143 |  * Decode a 8-bit mu-Law sample as 16-bit PCM.
144 |  * @param {number} muLawSample The 8-bit mu-Law sample
145 |  * @return {number}
146 |  */
147 | export function decodeSample(muLawSample) {
148 |   /** @type {number} */
149 |   let sign;
150 |   /** @type {number} */
151 |   let exponent;
152 |   /** @type {number} */
153 |   let mantissa;
154 |   /** @type {number} */
155 |   let sample;
156 |   muLawSample = ~muLawSample;
157 |   sign = (muLawSample & 0x80);
158 |   exponent = (muLawSample >> 4) & 0x07;
159 |   mantissa = muLawSample & 0x0F;
160 |   sample = decodeTable[exponent] + (mantissa << (exponent+3));
161 |   if (sign != 0) sample = -sample;
162 |   return sample;
163 | }
164 | 
165 | /**
166 |  * Encode 16-bit linear PCM samples into 8-bit mu-Law samples.
167 |  * @param {!Int16Array} samples A array of 16-bit PCM samples.
168 |  * @return {!Uint8Array}
169 |  */
170 | export function encode(samples) {
171 |   /** @type {!Uint8Array} */
172 |   let muLawSamples = new Uint8Array(samples.length);
173 |   for (let i=0; i<samples.length; i++) {
174 |     muLawSamples[i] = encodeSample(samples[i]);
175 |   }
176 |   return muLawSamples;
177 | }
178 | 
179 | /**
180 |  * Decode 8-bit mu-Law samples into 16-bit PCM samples.
181 |  * @param {!Uint8Array} samples A array of 8-bit mu-Law samples.
182 |  * @return {!Int16Array}
183 |  */
184 | export function decode(samples) {
185 |   /** @type {!Int16Array} */
186 |   let pcmSamples = new Int16Array(samples.length);
187 |   for (let i=0; i<samples.length; i++) {
188 |     pcmSamples[i] = decodeSample(samples[i]);
189 |   }
190 |   return pcmSamples;
191 | }
192 | 
193 |
194 |
195 | 196 | 197 | 198 | 199 | 200 | 201 |
202 | 203 |
204 | 205 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /docs/module-alawmulaw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | alawmulaw - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

alawmulaw

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 |
82 | 83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 |
91 | 92 |
93 | 94 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /docs/module-alawmulaw_alaw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | alawmulaw/alaw - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

alawmulaw/alaw

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 |

Members

76 | 77 | 78 | 79 |

(inner, constant, non-null) LOG_TABLE :Array.<number>

80 | 81 | 82 | 83 | 84 | 85 |
86 | 87 | 88 |
Source:
89 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |
124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
Type:
132 |
    133 |
  • 134 | 135 | Array.<number> 136 | 137 | 138 |
  • 139 |
140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 |

Methods

151 | 152 | 153 | 154 | 155 | 156 | 157 |

(static) decode(samplesnon-null) → (non-null) {Int16Array}

158 | 159 | 160 | 161 | 162 | 163 | 164 |
165 | 166 | 167 |
Source:
168 |
171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 |
203 | 204 | 205 | 206 | 207 | 208 |
209 | Decode 8-bit A-Law samples into 16-bit linear PCM samples. 210 |
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 |
Parameters:
223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 |
NameTypeDescription
samples 251 | 252 | 253 | Uint8Array 254 | 255 | 256 | 257 | A array of 8-bit A-Law samples.
269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 |
Returns:
286 | 287 | 288 | 289 | 290 |
291 |
292 | Type 293 |
294 |
295 | 296 | Int16Array 297 | 298 | 299 |
300 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 |

(static) decodeSample(aLawSample) → {number}

312 | 313 | 314 | 315 | 316 | 317 | 318 |
319 | 320 | 321 |
Source:
322 |
325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 |
357 | 358 | 359 | 360 | 361 | 362 |
363 | Decode a 8-bit A-Law sample as 16-bit PCM. 364 |
365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 |
Parameters:
377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 |
NameTypeDescription
aLawSample 405 | 406 | 407 | number 408 | 409 | 410 | 411 | The 8-bit A-Law sample
423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 |
Returns:
440 | 441 | 442 | 443 | 444 |
445 |
446 | Type 447 |
448 |
449 | 450 | number 451 | 452 | 453 |
454 |
455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 |

(static) encode(samplesnon-null) → (non-null) {Uint8Array}

466 | 467 | 468 | 469 | 470 | 471 | 472 |
473 | 474 | 475 |
Source:
476 |
479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 |
511 | 512 | 513 | 514 | 515 | 516 |
517 | Encode 16-bit linear PCM samples as 8-bit A-Law samples. 518 |
519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 |
Parameters:
531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 |
NameTypeDescription
samples 559 | 560 | 561 | Int16Array 562 | 563 | 564 | 565 | A array of 16-bit PCM samples.
577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 |
Returns:
594 | 595 | 596 | 597 | 598 |
599 |
600 | Type 601 |
602 |
603 | 604 | Uint8Array 605 | 606 | 607 |
608 |
609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 |

(static) encodeSample(sample) → {number}

620 | 621 | 622 | 623 | 624 | 625 | 626 |
627 | 628 | 629 |
Source:
630 |
633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 |
665 | 666 | 667 | 668 | 669 | 670 |
671 | Encode a 16-bit linear PCM sample as 8-bit A-Law. 672 |
673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 |
Parameters:
685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 |
NameTypeDescription
sample 713 | 714 | 715 | number 716 | 717 | 718 | 719 | A 16-bit PCM sample
731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 |
Returns:
748 | 749 | 750 | 751 | 752 |
753 |
754 | Type 755 |
756 |
757 | 758 | number 759 | 760 | 761 |
762 |
763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 |
775 | 776 |
777 | 778 | 779 | 780 | 781 | 782 | 783 |
784 | 785 |
786 | 787 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | -------------------------------------------------------------------------------- /docs/module-alawmulaw_mulaw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | alawmulaw/mulaw - Documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 32 | 33 |
34 | 35 |

alawmulaw/mulaw

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 |

Members

76 | 77 | 78 | 79 |

(inner) sample

80 | 81 | 82 | 83 | 84 | 85 |
86 | 87 | 88 |
Source:
89 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |
124 | 125 | 126 | 127 | 128 | 129 |
130 | convert from 16 bit linear to ulaw 131 |
132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 |

(inner) sign

143 | 144 | 145 | 146 | 147 | 148 |
149 | 150 | 151 |
Source:
152 |
155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 |
187 | 188 | 189 | 190 | 191 | 192 |
193 | get the sample into sign-magnitude 194 |
195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 |

Methods

208 | 209 | 210 | 211 | 212 | 213 | 214 |

(static) decode(samplesnon-null) → (non-null) {Int16Array}

215 | 216 | 217 | 218 | 219 | 220 | 221 |
222 | 223 | 224 |
Source:
225 |
228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 |
260 | 261 | 262 | 263 | 264 | 265 |
266 | Decode 8-bit mu-Law samples into 16-bit PCM samples. 267 |
268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 |
Parameters:
280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 |
NameTypeDescription
samples 308 | 309 | 310 | Uint8Array 311 | 312 | 313 | 314 | A array of 8-bit mu-Law samples.
326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 |
Returns:
343 | 344 | 345 | 346 | 347 |
348 |
349 | Type 350 |
351 |
352 | 353 | Int16Array 354 | 355 | 356 |
357 |
358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 |

(static) decodeSample(muLawSample) → {number}

369 | 370 | 371 | 372 | 373 | 374 | 375 |
376 | 377 | 378 |
Source:
379 |
382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 |
414 | 415 | 416 | 417 | 418 | 419 |
420 | Decode a 8-bit mu-Law sample as 16-bit PCM. 421 |
422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 |
Parameters:
434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 |
NameTypeDescription
muLawSample 462 | 463 | 464 | number 465 | 466 | 467 | 468 | The 8-bit mu-Law sample
480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 |
Returns:
497 | 498 | 499 | 500 | 501 |
502 |
503 | Type 504 |
505 |
506 | 507 | number 508 | 509 | 510 |
511 |
512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 |

(static) encode(samplesnon-null) → (non-null) {Uint8Array}

523 | 524 | 525 | 526 | 527 | 528 | 529 |
530 | 531 | 532 |
Source:
533 |
536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 |
568 | 569 | 570 | 571 | 572 | 573 |
574 | Encode 16-bit linear PCM samples into 8-bit mu-Law samples. 575 |
576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 |
Parameters:
588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 |
NameTypeDescription
samples 616 | 617 | 618 | Int16Array 619 | 620 | 621 | 622 | A array of 16-bit PCM samples.
634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 |
Returns:
651 | 652 | 653 | 654 | 655 |
656 |
657 | Type 658 |
659 |
660 | 661 | Uint8Array 662 | 663 | 664 |
665 |
666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 |

(static) encodeSample(sample) → {number}

677 | 678 | 679 | 680 | 681 | 682 | 683 |
684 | 685 | 686 |
Source:
687 |
690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 |
722 | 723 | 724 | 725 | 726 | 727 |
728 | Encode a 16-bit linear PCM sample as 8-bit mu-Law. 729 |
730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 |
Parameters:
742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 |
NameTypeDescription
sample 770 | 771 | 772 | number 773 | 774 | 775 | 776 | A 16-bit PCM sample
788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 |
Returns:
805 | 806 | 807 | 808 | 809 |
810 |
811 | Type 812 |
813 |
814 | 815 | number 816 | 817 | 818 |
819 |
820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 |
832 | 833 |
834 | 835 | 836 | 837 | 838 | 839 | 840 |
841 | 842 |
843 | 844 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | -------------------------------------------------------------------------------- /docs/scripts/collapse.js: -------------------------------------------------------------------------------- 1 | function hideAllButCurrent(){ 2 | //by default all submenut items are hidden 3 | //but we need to rehide them for search 4 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) { 5 | parent.style.display = "none"; 6 | }); 7 | 8 | //only current page (if it exists) should be opened 9 | var file = window.location.pathname.split("/").pop().replace(/\.html/, ''); 10 | document.querySelectorAll("nav > ul > li > a").forEach(function(parent) { 11 | var href = parent.attributes.href.value.replace(/\.html/, ''); 12 | if (file === href) { 13 | parent.parentNode.querySelectorAll("ul li").forEach(function(elem) { 14 | elem.style.display = "block"; 15 | }); 16 | } 17 | }); 18 | } 19 | 20 | hideAllButCurrent(); -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/nav.js: -------------------------------------------------------------------------------- 1 | function scrollToNavItem() { 2 | var path = window.location.href.split('/').pop().replace(/\.html/, ''); 3 | document.querySelectorAll('nav a').forEach(function(link) { 4 | var href = link.attributes.href.value.replace(/\.html/, ''); 5 | if (path === href) { 6 | link.scrollIntoView({block: 'center'}); 7 | return; 8 | } 9 | }) 10 | } 11 | 12 | scrollToNavItem(); 13 | -------------------------------------------------------------------------------- /docs/scripts/polyfill.js: -------------------------------------------------------------------------------- 1 | //IE Fix, src: https://www.reddit.com/r/programminghorror/comments/6abmcr/nodelist_lacks_foreach_in_internet_explorer/ 2 | if (typeof(NodeList.prototype.forEach)!==typeof(alert)){ 3 | NodeList.prototype.forEach=Array.prototype.forEach; 4 | } -------------------------------------------------------------------------------- /docs/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /docs/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p ul > li:not(.level-hide)").forEach(function(elem) { 16 | elem.style.display = "block"; 17 | }); 18 | 19 | if (typeof hideAllButCurrent === "function"){ 20 | //let's do what ever collapse wants to do 21 | hideAllButCurrent(); 22 | } else { 23 | //menu by default should be opened 24 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { 25 | elem.style.display = "block"; 26 | }); 27 | } 28 | } else { 29 | //we are searching 30 | document.documentElement.setAttribute(searchAttr, ''); 31 | 32 | //show all parents 33 | document.querySelectorAll("nav > ul > li").forEach(function(elem) { 34 | elem.style.display = "block"; 35 | }); 36 | //hide all results 37 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) { 38 | elem.style.display = "none"; 39 | }); 40 | //show results matching filter 41 | document.querySelectorAll("nav > ul > li > ul a").forEach(function(elem) { 42 | if (!contains(elem.parentNode, search)) { 43 | return; 44 | } 45 | elem.parentNode.style.display = "block"; 46 | }); 47 | //hide parents without children 48 | document.querySelectorAll("nav > ul > li").forEach(function(parent) { 49 | var countSearchA = 0; 50 | parent.querySelectorAll("a").forEach(function(elem) { 51 | if (contains(elem, search)) { 52 | countSearchA++; 53 | } 54 | }); 55 | 56 | var countUl = 0; 57 | var countUlVisible = 0; 58 | parent.querySelectorAll("ul").forEach(function(ulP) { 59 | // count all elements that match the search 60 | if (contains(ulP, search)) { 61 | countUl++; 62 | } 63 | 64 | // count all visible elements 65 | var children = ulP.children 66 | for (i=0; i ul { 227 | padding: 0 10px; 228 | } 229 | 230 | nav > ul > li > a { 231 | color: #606; 232 | margin-top: 10px; 233 | } 234 | 235 | nav ul ul a { 236 | color: hsl(207, 1%, 60%); 237 | border-left: 1px solid hsl(207, 10%, 86%); 238 | } 239 | 240 | nav ul ul a, 241 | nav ul ul a:active { 242 | padding-left: 20px 243 | } 244 | 245 | nav h2 { 246 | font-size: 13px; 247 | margin: 10px 0 0 0; 248 | padding: 0; 249 | } 250 | 251 | nav > h2 > a { 252 | margin: 10px 0 -10px; 253 | color: #606 !important; 254 | } 255 | 256 | footer { 257 | color: hsl(0, 0%, 28%); 258 | margin-left: 250px; 259 | display: block; 260 | padding: 15px; 261 | font-style: italic; 262 | font-size: 90%; 263 | } 264 | 265 | .ancestors { 266 | color: #999 267 | } 268 | 269 | .ancestors a { 270 | color: #999 !important; 271 | } 272 | 273 | .clear { 274 | clear: both 275 | } 276 | 277 | .important { 278 | font-weight: bold; 279 | color: #950B02; 280 | } 281 | 282 | .yes-def { 283 | text-indent: -1000px 284 | } 285 | 286 | .type-signature { 287 | color: #CA79CA 288 | } 289 | 290 | .type-signature:last-child { 291 | color: #eee; 292 | } 293 | 294 | .name, .signature { 295 | font-family: Consolas, Monaco, 'Andale Mono', monospace 296 | } 297 | 298 | .signature { 299 | color: #fc83ff; 300 | } 301 | 302 | .details { 303 | margin-top: 6px; 304 | border-left: 2px solid #DDD; 305 | line-height: 20px; 306 | font-size: 14px; 307 | } 308 | 309 | .details dt { 310 | width: auto; 311 | float: left; 312 | padding-left: 10px; 313 | } 314 | 315 | .details dd { 316 | margin-left: 70px; 317 | margin-top: 6px; 318 | margin-bottom: 6px; 319 | } 320 | 321 | .details ul { 322 | margin: 0 323 | } 324 | 325 | .details ul { 326 | list-style-type: none 327 | } 328 | 329 | .details pre.prettyprint { 330 | margin: 0 331 | } 332 | 333 | .details .object-value { 334 | padding-top: 0 335 | } 336 | 337 | .description { 338 | margin-bottom: 1em; 339 | margin-top: 1em; 340 | } 341 | 342 | .code-caption { 343 | font-style: italic; 344 | font-size: 107%; 345 | margin: 0; 346 | } 347 | 348 | .prettyprint { 349 | font-size: 14px; 350 | overflow: auto; 351 | } 352 | 353 | .prettyprint.source { 354 | width: inherit; 355 | line-height: 18px; 356 | display: block; 357 | background-color: #0d152a; 358 | color: #aeaeae; 359 | } 360 | 361 | .prettyprint code { 362 | line-height: 18px; 363 | display: block; 364 | background-color: #0d152a; 365 | color: #4D4E53; 366 | } 367 | 368 | .prettyprint > code { 369 | padding: 15px; 370 | } 371 | 372 | .prettyprint .linenums code { 373 | padding: 0 15px 374 | } 375 | 376 | .prettyprint .linenums li:first-of-type code { 377 | padding-top: 15px 378 | } 379 | 380 | .prettyprint code span.line { 381 | display: inline-block 382 | } 383 | 384 | .prettyprint.linenums { 385 | padding-left: 70px; 386 | -webkit-user-select: none; 387 | -moz-user-select: none; 388 | -ms-user-select: none; 389 | user-select: none; 390 | } 391 | 392 | .prettyprint.linenums ol { 393 | padding-left: 0 394 | } 395 | 396 | .prettyprint.linenums li { 397 | border-left: 3px #34446B solid; 398 | } 399 | 400 | .prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { 401 | background-color: #34446B; 402 | } 403 | 404 | .prettyprint.linenums li * { 405 | -webkit-user-select: text; 406 | -moz-user-select: text; 407 | -ms-user-select: text; 408 | user-select: text; 409 | } 410 | 411 | table { 412 | border-spacing: 0; 413 | border: 1px solid #ddd; 414 | border-collapse: collapse; 415 | border-radius: 3px; 416 | box-shadow: 0 1px 3px rgba(0,0,0,0.1); 417 | width: 100%; 418 | font-size: 14px; 419 | margin: 1em 0; 420 | } 421 | 422 | td, th { 423 | margin: 0px; 424 | text-align: left; 425 | vertical-align: top; 426 | padding: 10px; 427 | display: table-cell; 428 | } 429 | 430 | thead tr, thead tr { 431 | background-color: #fff; 432 | font-weight: bold; 433 | border-bottom: 1px solid #ddd; 434 | } 435 | 436 | .params .type { 437 | white-space: nowrap; 438 | } 439 | 440 | .params code { 441 | white-space: pre; 442 | } 443 | 444 | .params td, .params .name, .props .name, .name code { 445 | color: #4D4E53; 446 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 447 | font-size: 100%; 448 | } 449 | 450 | .params td { 451 | border-top: 1px solid #eee 452 | } 453 | 454 | .params td.description > p:first-child, .props td.description > p:first-child { 455 | margin-top: 0; 456 | padding-top: 0; 457 | } 458 | 459 | .params td.description > p:last-child, .props td.description > p:last-child { 460 | margin-bottom: 0; 461 | padding-bottom: 0; 462 | } 463 | 464 | span.param-type, .params td .param-type, .param-type dd { 465 | color: #606; 466 | font-family: Consolas, Monaco, 'Andale Mono', monospace 467 | } 468 | 469 | .param-type dt, .param-type dd { 470 | display: inline-block 471 | } 472 | 473 | .param-type { 474 | margin: 14px 0; 475 | } 476 | 477 | .disabled { 478 | color: #454545 479 | } 480 | 481 | /* navicon button */ 482 | .navicon-button { 483 | display: none; 484 | position: relative; 485 | padding: 2.0625rem 1.5rem; 486 | transition: 0.25s; 487 | cursor: pointer; 488 | -webkit-user-select: none; 489 | -moz-user-select: none; 490 | -ms-user-select: none; 491 | user-select: none; 492 | opacity: .8; 493 | } 494 | .navicon-button .navicon:before, .navicon-button .navicon:after { 495 | transition: 0.25s; 496 | } 497 | .navicon-button:hover { 498 | transition: 0.5s; 499 | opacity: 1; 500 | } 501 | .navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { 502 | transition: 0.25s; 503 | } 504 | .navicon-button:hover .navicon:before { 505 | top: .825rem; 506 | } 507 | .navicon-button:hover .navicon:after { 508 | top: -.825rem; 509 | } 510 | 511 | /* navicon */ 512 | .navicon { 513 | position: relative; 514 | width: 2.5em; 515 | height: .3125rem; 516 | background: #000; 517 | transition: 0.3s; 518 | border-radius: 2.5rem; 519 | } 520 | .navicon:before, .navicon:after { 521 | display: block; 522 | content: ""; 523 | height: .3125rem; 524 | width: 2.5rem; 525 | background: #000; 526 | position: absolute; 527 | z-index: -1; 528 | transition: 0.3s 0.25s; 529 | border-radius: 1rem; 530 | } 531 | .navicon:before { 532 | top: .625rem; 533 | } 534 | .navicon:after { 535 | top: -.625rem; 536 | } 537 | 538 | /* open */ 539 | .nav-trigger:checked + label:not(.steps) .navicon:before, 540 | .nav-trigger:checked + label:not(.steps) .navicon:after { 541 | top: 0 !important; 542 | } 543 | 544 | .nav-trigger:checked + label .navicon:before, 545 | .nav-trigger:checked + label .navicon:after { 546 | transition: 0.5s; 547 | } 548 | 549 | /* Minus */ 550 | .nav-trigger:checked + label { 551 | -webkit-transform: scale(0.75); 552 | transform: scale(0.75); 553 | } 554 | 555 | /* × and + */ 556 | .nav-trigger:checked + label.plus .navicon, 557 | .nav-trigger:checked + label.x .navicon { 558 | background: transparent; 559 | } 560 | 561 | .nav-trigger:checked + label.plus .navicon:before, 562 | .nav-trigger:checked + label.x .navicon:before { 563 | -webkit-transform: rotate(-45deg); 564 | transform: rotate(-45deg); 565 | background: #FFF; 566 | } 567 | 568 | .nav-trigger:checked + label.plus .navicon:after, 569 | .nav-trigger:checked + label.x .navicon:after { 570 | -webkit-transform: rotate(45deg); 571 | transform: rotate(45deg); 572 | background: #FFF; 573 | } 574 | 575 | .nav-trigger:checked + label.plus { 576 | -webkit-transform: scale(0.75) rotate(45deg); 577 | transform: scale(0.75) rotate(45deg); 578 | } 579 | 580 | .nav-trigger:checked ~ nav { 581 | left: 0 !important; 582 | } 583 | 584 | .nav-trigger:checked ~ .overlay { 585 | display: block; 586 | } 587 | 588 | .nav-trigger { 589 | position: fixed; 590 | top: 0; 591 | clip: rect(0, 0, 0, 0); 592 | } 593 | 594 | .overlay { 595 | display: none; 596 | position: fixed; 597 | top: 0; 598 | bottom: 0; 599 | left: 0; 600 | right: 0; 601 | width: 100%; 602 | height: 100%; 603 | background: hsla(0, 0%, 0%, 0.5); 604 | z-index: 1; 605 | } 606 | 607 | /* nav level */ 608 | .level-hide { 609 | display: none; 610 | } 611 | html[data-search-mode] .level-hide { 612 | display: block; 613 | } 614 | 615 | 616 | @media only screen and (min-width: 320px) and (max-width: 680px) { 617 | body { 618 | overflow-x: hidden; 619 | } 620 | 621 | nav { 622 | background: #FFF; 623 | width: 250px; 624 | height: 100%; 625 | position: fixed; 626 | top: 0; 627 | right: 0; 628 | bottom: 0; 629 | left: -250px; 630 | z-index: 3; 631 | padding: 0 10px; 632 | transition: left 0.2s; 633 | } 634 | 635 | .navicon-button { 636 | display: inline-block; 637 | position: fixed; 638 | top: 1.5em; 639 | right: 0; 640 | z-index: 2; 641 | } 642 | 643 | #main { 644 | width: 100%; 645 | min-width: 360px; 646 | } 647 | 648 | #main h1.page-title { 649 | margin: 1em 0; 650 | } 651 | 652 | #main section { 653 | padding: 0; 654 | } 655 | 656 | footer { 657 | margin-left: 0; 658 | } 659 | } 660 | 661 | /** Add a '#' to static members */ 662 | [data-type="member"] a::before { 663 | content: '#'; 664 | display: inline-block; 665 | margin-left: -14px; 666 | margin-right: 5px; 667 | } 668 | 669 | #disqus_thread{ 670 | margin-left: 30px; 671 | } 672 | -------------------------------------------------------------------------------- /docs/styles/prettify.css: -------------------------------------------------------------------------------- 1 | .pln { 2 | color: #ddd; 3 | } 4 | 5 | /* string content */ 6 | .str { 7 | color: #61ce3c; 8 | } 9 | 10 | /* a keyword */ 11 | .kwd { 12 | color: #fbde2d; 13 | } 14 | 15 | /* a comment */ 16 | .com { 17 | color: #aeaeae; 18 | } 19 | 20 | /* a type name */ 21 | .typ { 22 | color: #8da6ce; 23 | } 24 | 25 | /* a literal value */ 26 | .lit { 27 | color: #fbde2d; 28 | } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #ddd; 33 | } 34 | 35 | /* lisp open bracket */ 36 | .opn { 37 | color: #000000; 38 | } 39 | 40 | /* lisp close bracket */ 41 | .clo { 42 | color: #000000; 43 | } 44 | 45 | /* a markup tag name */ 46 | .tag { 47 | color: #8da6ce; 48 | } 49 | 50 | /* a markup attribute name */ 51 | .atn { 52 | color: #fbde2d; 53 | } 54 | 55 | /* a markup attribute value */ 56 | .atv { 57 | color: #ddd; 58 | } 59 | 60 | /* a declaration */ 61 | .dec { 62 | color: #EF5050; 63 | } 64 | 65 | /* a variable name */ 66 | .var { 67 | color: #c82829; 68 | } 69 | 70 | /* a function name */ 71 | .fun { 72 | color: #4271ae; 73 | } 74 | 75 | /* Specify class=linenums on a pre to get line numbering */ 76 | ol.linenums { 77 | margin-top: 0; 78 | margin-bottom: 0; 79 | } 80 | -------------------------------------------------------------------------------- /externs/alawmulaw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 Rafael da Silva Rocha. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /** 26 | * @fileoverview Externs for alawmulaw 5.0 27 | * 28 | * @see https://github.com/rochars/alawmulaw 29 | * @externs 30 | */ 31 | 32 | var alawmulaw = {}; 33 | var alaw = {}; 34 | var mulaw = {}; 35 | 36 | // A-Law 37 | /** 38 | * Encode a 16-bit linear PCM sample as 8-bit A-Law. 39 | * @param {number} sample A 16-bit PCM sample 40 | * @return {number} 41 | */ 42 | alaw.encodeSample = function(sample) {} 43 | 44 | /** 45 | * Decode a 8-bit A-Law sample as 16-bit PCM. 46 | * @param {number} aLawSample The 8-bit A-Law sample 47 | * @return {number} 48 | */ 49 | alaw.decodeSample = function(aLawSample) {} 50 | 51 | /** 52 | * Encode 16-bit linear PCM samples as 8-bit A-Law samples. 53 | * @param {!Int16Array} samples A array of 16-bit PCM samples. 54 | * @return {!Uint8Array} 55 | */ 56 | alaw.encode = function(samples) {} 57 | 58 | /** 59 | * Decode 8-bit A-Law samples into 16-bit linear PCM samples. 60 | * @param {!Uint8Array} samples A array of 8-bit A-Law samples. 61 | * @return {!Int16Array} 62 | */ 63 | alaw.decode = function(samples) {} 64 | 65 | // mu-Law 66 | /** 67 | * Encode a 16-bit linear PCM sample as 8-bit mu-Law. 68 | * @param {number} sample A 16-bit PCM sample 69 | * @return {number} 70 | */ 71 | mulaw.encodeSample = function(sample) {} 72 | 73 | /** 74 | * Decode a 8-bit mu-Law sample as 16-bit PCM. 75 | * @param {number} muLawSample The 8-bit mu-Law sample 76 | * @return {number} 77 | */ 78 | mulaw.decodeSample = function(muLawSample) {} 79 | 80 | /** 81 | * Encode 16-bit linear PCM samples into 8-bit mu-Law samples. 82 | * @param {!Int16Array} samples A array of 16-bit PCM samples. 83 | * @return {!Uint8Array} 84 | */ 85 | mulaw.encode = function(samples) {} 86 | 87 | /** 88 | * Decode 8-bit mu-Law samples into 16-bit PCM samples. 89 | * @param {!Uint8Array} samples A array of 8-bit mu-Law samples. 90 | * @return {!Int16Array} 91 | */ 92 | mulaw.decode = function(samples) {} -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for alawmulaw 6.0.0 2 | // Project: https://github.com/rochars/alawmulaw 3 | // Definitions by: Rafael da Silva Rocha 4 | // Definitions: https://github.com/rochars/alawmulaw 5 | 6 | export module alaw { 7 | function decode(samples: Uint8Array): Int16Array; 8 | function decodeSample(sample: number): number; 9 | function encode(samples: Int16Array): Uint8Array; 10 | function encodeSample(sample: number): number; 11 | } 12 | 13 | export module mulaw { 14 | function decode(samples: Uint8Array): Int16Array; 15 | function decodeSample(sample: number): number; 16 | function encode(samples: Int16Array): Uint8Array; 17 | function encodeSample(sample: number): number; 18 | } 19 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * alawmulaw: A-Law and mu-Law codecs in JavaScript. 3 | * https://github.com/rochars/alawmulaw 4 | * 5 | * Copyright (c) 2018 Rafael da Silva Rocha. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining 8 | * a copy of this software and associated documentation files (the 9 | * "Software"), to deal in the Software without restriction, including 10 | * without limitation the rights to use, copy, modify, merge, publish, 11 | * distribute, sublicense, and/or sell copies of the Software, and to 12 | * permit persons to whom the Software is furnished to do so, subject to 13 | * the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | * 26 | */ 27 | 28 | /** 29 | * @fileoverview The alawmulaw API. 30 | */ 31 | 32 | /** 33 | * @module alawmulaw 34 | */ 35 | 36 | import * as alaw from './lib/alaw'; 37 | import * as mulaw from './lib/mulaw'; 38 | 39 | export {alaw, mulaw}; 40 | -------------------------------------------------------------------------------- /lib/alaw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * alawmulaw: A-Law and mu-Law codecs in JavaScript. 3 | * https://github.com/rochars/alawmulaw 4 | * 5 | * Copyright (c) 2018 Rafael da Silva Rocha. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining 8 | * a copy of this software and associated documentation files (the 9 | * "Software"), to deal in the Software without restriction, including 10 | * without limitation the rights to use, copy, modify, merge, publish, 11 | * distribute, sublicense, and/or sell copies of the Software, and to 12 | * permit persons to whom the Software is furnished to do so, subject to 13 | * the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be 16 | * included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | * 26 | */ 27 | 28 | /** 29 | * @fileoverview A-Law codec. 30 | */ 31 | 32 | /** @module alawmulaw/alaw */ 33 | 34 | /** @type {!Array} */ 35 | const LOG_TABLE = [ 36 | 1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 37 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 38 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 39 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 40 | ]; 41 | 42 | /** 43 | * Encode a 16-bit linear PCM sample as 8-bit A-Law. 44 | * @param {number} sample A 16-bit PCM sample 45 | * @return {number} 46 | */ 47 | export function encodeSample(sample) { 48 | /** @type {number} */ 49 | let compandedValue; 50 | sample = (sample ==-32768) ? -32767 : sample; 51 | /** @type {number} */ 52 | let sign = ((~sample) >> 8) & 0x80; 53 | if (!sign) { 54 | sample = sample * -1; 55 | } 56 | if (sample > 32635) { 57 | sample = 32635; 58 | } 59 | if (sample >= 256) { 60 | /** @type {number} */ 61 | let exponent = LOG_TABLE[(sample >> 8) & 0x7F]; 62 | /** @type {number} */ 63 | let mantissa = (sample >> (exponent + 3) ) & 0x0F; 64 | compandedValue = ((exponent << 4) | mantissa); 65 | } else { 66 | compandedValue = sample >> 4; 67 | } 68 | return compandedValue ^ (sign ^ 0x55); 69 | } 70 | 71 | /** 72 | * Decode a 8-bit A-Law sample as 16-bit PCM. 73 | * @param {number} aLawSample The 8-bit A-Law sample 74 | * @return {number} 75 | */ 76 | export function decodeSample(aLawSample) { 77 | /** @type {number} */ 78 | let sign = 0; 79 | aLawSample ^= 0x55; 80 | if (aLawSample & 0x80) { 81 | aLawSample &= ~(1 << 7); 82 | sign = -1; 83 | } 84 | /** @type {number} */ 85 | let position = ((aLawSample & 0xF0) >> 4) + 4; 86 | /** @type {number} */ 87 | let decoded = 0; 88 | if (position != 4) { 89 | decoded = ((1 << position) | 90 | ((aLawSample & 0x0F) << (position - 4)) | 91 | (1 << (position - 5))); 92 | } else { 93 | decoded = (aLawSample << 1)|1; 94 | } 95 | decoded = (sign === 0) ? (decoded) : (-decoded); 96 | return (decoded * 8) * -1; 97 | } 98 | 99 | /** 100 | * Encode 16-bit linear PCM samples as 8-bit A-Law samples. 101 | * @param {!Int16Array} samples A array of 16-bit PCM samples. 102 | * @return {!Uint8Array} 103 | */ 104 | export function encode(samples) { 105 | /** @type {!Uint8Array} */ 106 | let aLawSamples = new Uint8Array(samples.length); 107 | for (let i=0; i} 46 | * @private 47 | */ 48 | const encodeTable = [ 49 | 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, 50 | 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 51 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 52 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 53 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 54 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 55 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 56 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 57 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 58 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 59 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 60 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 61 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 62 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 63 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 64 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]; 65 | /** 66 | * @type {Array} 67 | * @private 68 | */ 69 | const decodeTable = [0,132,396,924,1980,4092,8316,16764]; 70 | 71 | /** 72 | * Encode a 16-bit linear PCM sample as 8-bit mu-Law. 73 | * @param {number} sample A 16-bit PCM sample 74 | * @return {number} 75 | */ 76 | export function encodeSample(sample) { 77 | /** @type {number} */ 78 | let sign; 79 | /** @type {number} */ 80 | let exponent; 81 | /** @type {number} */ 82 | let mantissa; 83 | /** @type {number} */ 84 | let muLawSample; 85 | /** get the sample into sign-magnitude **/ 86 | sign = (sample >> 8) & 0x80; 87 | if (sign != 0) sample = -sample; 88 | /** convert from 16 bit linear to ulaw **/ 89 | sample = sample + BIAS; 90 | if (sample > CLIP) sample = CLIP; 91 | exponent = encodeTable[(sample>>7) & 0xFF]; 92 | mantissa = (sample >> (exponent+3)) & 0x0F; 93 | muLawSample = ~(sign | (exponent << 4) | mantissa); 94 | /** return the result **/ 95 | return muLawSample; 96 | } 97 | 98 | /** 99 | * Decode a 8-bit mu-Law sample as 16-bit PCM. 100 | * @param {number} muLawSample The 8-bit mu-Law sample 101 | * @return {number} 102 | */ 103 | export function decodeSample(muLawSample) { 104 | /** @type {number} */ 105 | let sign; 106 | /** @type {number} */ 107 | let exponent; 108 | /** @type {number} */ 109 | let mantissa; 110 | /** @type {number} */ 111 | let sample; 112 | muLawSample = ~muLawSample; 113 | sign = (muLawSample & 0x80); 114 | exponent = (muLawSample >> 4) & 0x07; 115 | mantissa = muLawSample & 0x0F; 116 | sample = decodeTable[exponent] + (mantissa << (exponent+3)); 117 | if (sign != 0) sample = -sample; 118 | return sample; 119 | } 120 | 121 | /** 122 | * Encode 16-bit linear PCM samples into 8-bit mu-Law samples. 123 | * @param {!Int16Array} samples A array of 16-bit PCM samples. 124 | * @return {!Uint8Array} 125 | */ 126 | export function encode(samples) { 127 | /** @type {!Uint8Array} */ 128 | let muLawSamples = new Uint8Array(samples.length); 129 | for (let i=0; i", 7 | "license": "MIT", 8 | "main": "./dist/alawmulaw.js", 9 | "module": "./index.js", 10 | "types": "./index.d.ts", 11 | "engines": { 12 | "node": ">=8" 13 | }, 14 | "keywords": [ 15 | "A-Law", 16 | "mu-Law", 17 | "audio", 18 | "codec", 19 | "encode", 20 | "decode", 21 | "compander", 22 | "companding", 23 | "PCM", 24 | "streaming" 25 | ], 26 | "repository": { 27 | "type": "git", 28 | "url": "git://github.com/rochars/alawmulaw.git" 29 | }, 30 | "bugs": { 31 | "url": "https://github.com/rochars/alawmulaw/issues" 32 | }, 33 | "directories": { 34 | "dist": "dist", 35 | "externs": "externs", 36 | "lib": "lib" 37 | }, 38 | "files": [ 39 | "dist", 40 | "externs", 41 | "lib", 42 | "index.js", 43 | "index.d.ts", 44 | "LICENSE", 45 | "CHANGELOG.md", 46 | "README.md" 47 | ], 48 | "scripts": { 49 | "lint": "jshint index.js lib", 50 | "test": "nyc ./node_modules/mocha/bin/_mocha test/src --recursive -R dot", 51 | "test-umd": "node ./node_modules/mocha/bin/_mocha test/src --umd --recursive -R dot", 52 | "test-tsc": "tsc ./test/dist/TypeScript/main.ts && node -r esm ./test/dist/TypeScript/main.js", 53 | "test-dist": "npm run test-umd && npm run test-tsc", 54 | "pack": "npm run test && rollup -c && npm run test-dist", 55 | "doc": "./node_modules/.bin/jsdoc -c .jsdocrc index.js lib -d docs -r README.md -t node_modules/docdash", 56 | "build": "npm run lint && npm run pack && npm run doc", 57 | "coverage": "nyc report --reporter=lcov > coverage.lcov && codecov" 58 | }, 59 | "devDependencies": { 60 | "@ampproject/rollup-plugin-closure-compiler": "^0.13.0", 61 | "chai": "^4.2.0", 62 | "codecov": "^3.6.1", 63 | "docdash": "^1.1.1", 64 | "esm": "^3.2.25", 65 | "jsdoc": "^3.6.3", 66 | "jshint": "^2.10.3", 67 | "mocha": "^6.2.2", 68 | "mocha-lcov-reporter": "^1.3.0", 69 | "nyc": "^14.1.1", 70 | "rollup": "^1.27.14", 71 | "typescript": "^3.7.4" 72 | }, 73 | "dependencies": {} 74 | } 75 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 Rafael da Silva Rocha. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /** 26 | * @fileoverview rollup configuration file. 27 | * @see https://github.com/rochars/alawmulaw 28 | */ 29 | 30 | import compiler from '@ampproject/rollup-plugin-closure-compiler'; 31 | 32 | export default [ 33 | { 34 | input: 'index.js', 35 | output: [ 36 | { 37 | file: 'dist/alawmulaw.js', 38 | name: 'alawmulaw', 39 | format: 'umd' 40 | }, 41 | ], 42 | plugins: [ 43 | compiler({ 44 | language_in: 'ECMASCRIPT6', 45 | language_out: 'ECMASCRIPT3', 46 | compilation_level: 'SIMPLE', 47 | warning_level: 'VERBOSE', 48 | externs: ['externs/alawmulaw.js'] 49 | }) 50 | ] 51 | } 52 | ]; 53 | -------------------------------------------------------------------------------- /test/dist/AMD/app.js: -------------------------------------------------------------------------------- 1 | // For any third party dependencies, like jQuery, place them in the lib folder. 2 | 3 | // Configure loading modules from the lib directory, 4 | // except for 'app' ones, which are in a sibling 5 | // directory. 6 | requirejs.config({ 7 | baseUrl: 'lib', 8 | paths: { 9 | app: '../app' 10 | } 11 | }); 12 | 13 | // Start loading the main app file. Put all of 14 | // your application logic in there. 15 | requirejs(['app/main']); 16 | -------------------------------------------------------------------------------- /test/dist/AMD/app/main.js: -------------------------------------------------------------------------------- 1 | define(function (require) { 2 | var alaw = require('../../../../dist/alawmulaw.js').alaw; 3 | console.log(alaw); 4 | document.write('OK'); 5 | }); 6 | -------------------------------------------------------------------------------- /test/dist/AMD/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/dist/TypeScript/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* 3 | * Copyright (c) 2018-2019 Rafael da Silva Rocha. 4 | */ 5 | exports.__esModule = true; 6 | /** 7 | * @fileoverview TypeScript declaration tests. 8 | * @see https://github.com/rochars/alawmulaw 9 | */ 10 | var index_js_1 = require("../../../index.js"); 11 | console.log(index_js_1.alaw); 12 | console.log(index_js_1.mulaw); 13 | console.log(index_js_1.alaw.encodeSample(0)); 14 | -------------------------------------------------------------------------------- /test/dist/TypeScript/main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019 Rafael da Silva Rocha. 3 | */ 4 | 5 | /** 6 | * @fileoverview TypeScript declaration tests. 7 | * @see https://github.com/rochars/alawmulaw 8 | */ 9 | 10 | import {alaw, mulaw} from '../../../index.js'; 11 | 12 | console.log(alaw); 13 | console.log(mulaw); 14 | console.log(alaw.encodeSample(0)); 15 | -------------------------------------------------------------------------------- /test/dist/browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | alawmulaw: browser tests 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |

alawmulaw

14 |

Copyright (c) 2018-2019 Rafael da Silva Rocha.
15 | https://github.com/rochars/uint-buffer

16 |
17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 |
25 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /test/loader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-2019 Rafael da Silva Rocha. 3 | * https://github.com/rochars/alawmulaw 4 | * 5 | */ 6 | 7 | let alawmulaw; 8 | 9 | if (process.argv[3] == '--umd') { 10 | console.log('umd'); 11 | alawmulaw = require('../dist/alawmulaw.js'); 12 | 13 | // source 14 | } else { 15 | console.log('source'); 16 | require = require("esm")(module); 17 | global.module = module; 18 | alawmulaw = require('../index.js'); 19 | } 20 | 21 | module.exports = alawmulaw; 22 | -------------------------------------------------------------------------------- /test/src/decode.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2018 Rafael da Silva Rocha. 3 | * 4 | */ 5 | 6 | var chai = chai || require("chai"); 7 | var alawmulaw = alawmulaw || require('../../test/loader.js'); 8 | var assert = chai.assert; 9 | 10 | describe('decode A-Law', function() { 11 | it("alaw decode Uint8Array([128])", function() { 12 | assert.deepEqual(new Int16Array([5504]), alawmulaw.alaw.decode(new Uint8Array([128]))); 13 | }); 14 | it("alaw decode Uint8Array([255])", function() { 15 | assert.deepEqual(new Int16Array([848]), alawmulaw.alaw.decode(new Uint8Array([255]))); 16 | }); 17 | it("alaw.decode Uint8Array([0, 255])", function() { 18 | assert.deepEqual(new Int16Array([-5504, 848]), alawmulaw.alaw.decode(new Uint8Array([0, 255]))); 19 | }); 20 | 21 | it("alaw.decodeSample 0", function() { 22 | assert.deepEqual(-5504, alawmulaw.alaw.decodeSample(0)); 23 | }); 24 | it("alaw.decodeSample 255", function() { 25 | assert.deepEqual(848, alawmulaw.alaw.decodeSample(255)); 26 | }); 27 | it("alaw.decodeSample 128", function() { 28 | assert.deepEqual(5504, alawmulaw.alaw.decodeSample(128)); 29 | }); 30 | }); 31 | 32 | describe('decode mu-Law', function() { 33 | it("mulaw.decode Uint8Array([128])", function() { 34 | assert.deepEqual(new Int16Array([32124]), alawmulaw.mulaw.decode(new Uint8Array([128]))); 35 | }); 36 | it("mulaw.decode Uint8Array([255])", function() { 37 | assert.deepEqual(new Int16Array([0]), alawmulaw.mulaw.decode(new Uint8Array([255]))); 38 | }); 39 | it("mulaw.decode Uint8Array([0, 255])", function() { 40 | assert.deepEqual(new Int16Array([-32124, 0]), alawmulaw.mulaw.decode(new Uint8Array([0, 255]))); 41 | }); 42 | 43 | it("mulaw.decode 128", function() { 44 | assert.deepEqual(32124, alawmulaw.mulaw.decodeSample(128)); 45 | }); 46 | it("mulaw.decode 255", function() { 47 | assert.deepEqual(0, alawmulaw.mulaw.decodeSample(255)); 48 | }); 49 | it("mulaw.decode 0", function() { 50 | assert.deepEqual(-32124, alawmulaw.mulaw.decodeSample(0)); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /test/src/encode.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2018 Rafael da Silva Rocha. 3 | * 4 | */ 5 | 6 | var chai = chai || require("chai"); 7 | var alawmulaw = alawmulaw || require('../../test/loader.js'); 8 | var assert = chai.assert; 9 | 10 | describe('encode A-Law', function() { 11 | it("Should encode 16-bit values as 8-bit A-Law with encode()", function() { 12 | assert.deepEqual(new Uint8Array([213, 250]), alawmulaw.alaw.encode(new Int16Array([0, 1000]))); 13 | }); 14 | it("Should encode 16-bit values as 8-bit A-Law with encode()", function() { 15 | assert.deepEqual(new Uint8Array([250]), alawmulaw.alaw.encode(new Int16Array([1000]))); 16 | }); 17 | it("Should encode 16-bit values as 8-bit A-Law with encode()", function() { 18 | assert.deepEqual(new Uint8Array([122]), alawmulaw.alaw.encode(new Int16Array([-1000]))); 19 | }); 20 | 21 | it("Should encode 16-bit values as 8-bit A-Law with encodeSample()", function() { 22 | assert.deepEqual(213, alawmulaw.alaw.encodeSample(0)); 23 | }); 24 | it("Should encode 16-bit values as 8-bit A-Law with encodeSample()", function() { 25 | assert.deepEqual(250, alawmulaw.alaw.encodeSample(1000)); 26 | }); 27 | it("Should encode 16-bit values as 8-bit A-Law with encodeSample()", function() { 28 | assert.deepEqual(122, alawmulaw.alaw.encodeSample(-1000)); 29 | }); 30 | }); 31 | 32 | describe('encode mu-Law', function() { 33 | it("Should encode 16-bit values as 8-bit mu-Law with encode()", function() { 34 | assert.deepEqual(new Uint8Array([255, 206]), alawmulaw.mulaw.encode(new Int16Array([0, 1000]))); 35 | }); 36 | it("Should encode 16-bit values as 8-bit mu-Law with encode()", function() { 37 | assert.deepEqual(new Uint8Array([206]), alawmulaw.mulaw.encode(new Int16Array([1000]))); 38 | }); 39 | it("Should encode 16-bit values as 8-bit mu-Law with encode()", function() { 40 | assert.deepEqual(new Uint8Array([78]), alawmulaw.mulaw.encode(new Int16Array([-1000]))); 41 | }); 42 | 43 | it("Should encode 16-bit values as 8-bit mu-Law encodeSample", function() { 44 | assert.deepEqual(-1, alawmulaw.mulaw.encodeSample(0)); 45 | }); 46 | it("Should encode 16-bit values as 8-bit mu-Law encodeSample", function() { 47 | assert.deepEqual(-50, alawmulaw.mulaw.encodeSample(1000)); 48 | }); 49 | it("Should encode 16-bit values as 8-bit mu-Law encodeSample", function() { 50 | assert.deepEqual(-178, alawmulaw.mulaw.encodeSample(-1000)); 51 | }); 52 | }); 53 | --------------------------------------------------------------------------------