alawmulaw
61 |Copyright (c) 2018-2019 Rafael da Silva Rocha.
62 | https://github.com/rochars/alawmulaw
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
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.