UNPKG

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