1 | # alawmulaw
|
2 | JavaScript A-Law and mu-Law codecs.
|
3 | Copyright (c) 2018 Rafael da Silva Rocha.
|
4 | https://github.com/rochars/alawmulaw
|
5 |
|
6 | References:
|
7 | https://github.com/torvalds/linux/blob/master/sound/core/oss/mulaw.c
|
8 | https://github.com/deftio/companders
|
9 | http://dystopiancode.blogspot.com.br/2012/02/pcm-law-and-u-law-companding-algorithms.html
|
10 |
|
11 | [![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)
|
12 |
|
13 | ## Install
|
14 | ```
|
15 | npm install alawmulaw
|
16 | ```
|
17 |
|
18 | ## A-Law
|
19 |
|
20 | Full files:
|
21 | ```javascript
|
22 |
|
23 | const alaw = require("alawmulaw").alaw;
|
24 |
|
25 | // Compressing all the samples in a file
|
26 | // Only 16-bit samples are supported
|
27 | aLawSamples = alaw.encode(pcmSamples);
|
28 |
|
29 | // Decompressing all the samples in a file
|
30 | pcmSamples = alaw.decode(aLawSamples);
|
31 | ```
|
32 |
|
33 | Sample by sample:
|
34 | ```javascript
|
35 |
|
36 | const alaw = require("alawmulaw").alaw;
|
37 |
|
38 | // Compressing
|
39 | aLawSample = alaw.encodeSample(pcmSample);
|
40 |
|
41 | // Decompressing
|
42 | pcmSample = alaw.decodeSample(aLawSample);
|
43 | ```
|
44 |
|
45 | ## mu-Law
|
46 |
|
47 | Full files:
|
48 | ```javascript
|
49 |
|
50 | const mulaw = require("alawmulaw").mulaw;
|
51 |
|
52 | // Compressing all the samples in a file
|
53 | // Only 16-bit samples are supported
|
54 | muLawSamples = mulaw.encode(pcmSamples);
|
55 |
|
56 | // Decompressing all the samples in a file
|
57 | pcmSamples = mulaw.decode(muLawSamples);
|
58 | ```
|
59 |
|
60 | Sample by sample:
|
61 | ```javascript
|
62 |
|
63 | const mulaw = require("alawmulaw").mulaw;
|
64 |
|
65 | // Compressing
|
66 | muLawSample = mulaw.encodeSample(pcmSample);
|
67 |
|
68 | // Decompressing
|
69 | pcmSample = mulaw.decodeSample(muLawSample);
|
70 | ```
|
71 |
|
72 |
|
73 | ## In the browser
|
74 |
|
75 | ```html
|
76 | <script src="dist/alawmulaw-min.js"></script>
|
77 | <script>
|
78 | // A-Law
|
79 | samples = alaw.encode(samples);
|
80 | samples = alaw.decode(samples);
|
81 | sample = alaw.encodeSample(sample);
|
82 | sample = alaw.decodeSample(sample);
|
83 |
|
84 | // mu-Law
|
85 | samples = mulaw.encode(samples);
|
86 | samples = mulaw.decode(samples);
|
87 | sample = mulaw.encode(sample);
|
88 | sample = mulaw.decode(sample);
|
89 | </script>
|
90 | ```
|
91 |
|
92 | ## LICENSE
|
93 | Copyright (c) 2018 Rafael da Silva Rocha.
|
94 |
|
95 | Permission is hereby granted, free of charge, to any person obtaining
|
96 | a copy of this software and associated documentation files (the
|
97 | "Software"), to deal in the Software without restriction, including
|
98 | without limitation the rights to use, copy, modify, merge, publish,
|
99 | distribute, sublicense, and/or sell copies of the Software, and to
|
100 | permit persons to whom the Software is furnished to do so, subject to
|
101 | the following conditions:
|
102 |
|
103 | The above copyright notice and this permission notice shall be
|
104 | included in all copies or substantial portions of the Software.
|
105 |
|
106 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
107 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
108 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
109 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
110 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
111 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
112 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|