Skip to content

Commit 25a7b0d

Browse files
committed
Initial commit
0 parents  commit 25a7b0d

36 files changed

+5685
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.DS_Store
2+
3+
# Development folders
4+
.nyc_output
5+
node_modules
6+
7+
# Development files
8+
*.log
9+
*.reapeaks
10+
11+
# GitHub do not allow big files
12+
test/large-files

.jsdocrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"source": {
3+
"include": [
4+
"index.js"
5+
]
6+
},
7+
"templates": {
8+
"default": {
9+
"includeDate": false
10+
}
11+
}
12+
}

.jshintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"esversion": 6
3+
}

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: node_js
2+
os:
3+
- linux
4+
- osx
5+
node_js:
6+
- "8"
7+
- "9"
8+
- "10"
9+
- "12"
10+
install:
11+
- npm install
12+
- npm install -g
13+
script:
14+
- npm run build
15+
after_success:
16+
- npm run coverage

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CHANGELOG

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 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.

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# wave-resampler
2+
Copyright (c) 2019 Rafael da Silva Rocha.
3+
https://github.com/rochars/wave-resampler
4+
5+
[![NPM version](https://img.shields.io/npm/v/wave-resampler.svg?style=for-the-badge)](https://www.npmjs.com/package/wave-resampler) [![Docs](https://img.shields.io/badge/API-docs-blue.svg?style=for-the-badge)](https://rochars.github.io/wave-resampler/docs) [![Tests](https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge)](https://rochars.github.io/wave-resampler/test/index.html)
6+
[![Codecov](https://img.shields.io/codecov/c/github/rochars/wave-resampler.svg?style=flat-square)](https://codecov.io/gh/rochars/wave-resampler) [![Unix Build](https://img.shields.io/travis/rochars/wave-resampler.svg?style=flat-square)](https://travis-ci.org/rochars/wave-resampler) [![Windows Build](https://img.shields.io/appveyor/ci/rochars/wave-resampler.svg?style=flat-square&logo=appveyor)](https://ci.appveyor.com/project/rochars/wave-resampler) [![Scrutinizer](https://img.shields.io/scrutinizer/g/rochars/wave-resampler.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/rochars/wave-resampler/)
7+
8+
PCM audio resampler written entirely in JavaScript.
9+
10+
## Install
11+
```
12+
npm install wave-resampler
13+
```
14+
15+
## Use
16+
17+
### Node
18+
```javascript
19+
const waveResampler = require('wave-resampler');
20+
// resample 48kHz samples to 44.1kHz
21+
let newSamples = waveResampler.resample(samples, 48000, 44100);
22+
```
23+
or
24+
```javascript
25+
import { resampler } from 'wave-resampler';
26+
let newSamples = resample(samples, 48000, 44100);
27+
```
28+
29+
### Browser
30+
Use the **wave-resampler.js** file in the *dist* folder:
31+
```html
32+
<script src="wave-resampler.js"></script>
33+
<script>
34+
var newSamples = waveResampler.resample(samples, 48000, 44100);
35+
</script>
36+
```
37+
38+
Or load it from the [jsDelivr](https://cdn.jsdelivr.net/npm/wave-resampler) CDN:
39+
```html
40+
<script src="https://cdn.jsdelivr.net/npm/wave-resampler"></script>
41+
```
42+
43+
Or load it from [unpkg](https://unpkg.com/wave-resampler):
44+
```html
45+
<script src="https://unpkg.com/wave-resampler"></script>
46+
```
47+
48+
## Advanced use
49+
50+
### Resampling methods
51+
- **point**: Nearest point interpolation, lowest quality, no LPF by default, fastest
52+
- **linear**: Linear interpolation, low quality, no LPF by default, fast
53+
- **cubic**: Cubic interpolation, use LPF by default **(default method)**
54+
- **sinc**: Windowed sinc interpolation, use LPF by default, slowest
55+
56+
To use a different interpolation method:
57+
```javascript
58+
// Will use 'sinc' method
59+
resample(48000, 44100, {method: "sinc"});
60+
61+
// Will use 'linear' method
62+
resample(48000, 44100, {method: "linear"});
63+
```
64+
65+
### LPF
66+
You can turn the LPF on and off for any resampling method:
67+
```javascript
68+
// Will use 'sinc' method with no LPF
69+
let newSamples = resample(48000, 44100, {method: "sinc", LPF: false});
70+
71+
// Will use 'linear' method with LPF
72+
let newSamples = resample(48000, 44100, {method: "linear", LPF: true});
73+
```
74+
75+
The default LPF is a IIR LPF. You may define what type of LPF will be used
76+
by changing the LPFType attribute on the *toSampleRate()* param.
77+
You can use **IIR** or **FIR**:
78+
```javascript
79+
// Will use 'linear' method with a FIR LPF
80+
let newSamples = resample(48000, 44100,
81+
{method: "linear", LPF: true, LPFType: 'FIR'});
82+
83+
// Will use 'linear' method with a IIR LPF, the default
84+
let newSamples = resample(48000, 44100,
85+
{method: "linear", LPF: true});
86+
```
87+
88+
You can change the order of the LPF for both IIR and FIR with
89+
the attribute LPFOrder:
90+
```javascript
91+
let newSamples = resample(48000, 44100,
92+
{method: "linear", LPF: true, LPFType: 'IIR', LPFOrder: 2});
93+
```
94+
95+
The default order for IIR is 16 and for FIR is 71.
96+
97+
## API
98+
```javascript
99+
/**
100+
* Change the sample rate of the samples to a new sample rate.
101+
* @param {!Array|!TypedArray} samples The original samples.
102+
* @param {number} oldSampleRate The original sample rate.
103+
* @param {number} sampleRate The target sample rate.
104+
* @param {?Object} details The extra configuration, if needed.
105+
* @return {!Float64Array} the new samples.
106+
*/
107+
export function resample(samples, oldSampleRate, sampleRate, details={}) {}
108+
```
109+
110+
### LICENSE
111+
Copyright (c) 2019 Rafael da Silva Rocha.
112+
113+
Permission is hereby granted, free of charge, to any person obtaining
114+
a copy of this software and associated documentation files (the
115+
"Software"), to deal in the Software without restriction, including
116+
without limitation the rights to use, copy, modify, merge, publish,
117+
distribute, sublicense, and/or sell copies of the Software, and to
118+
permit persons to whom the Software is furnished to do so, subject to
119+
the following conditions:
120+
121+
The above copyright notice and this permission notice shall be
122+
included in all copies or substantial portions of the Software.
123+
124+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
125+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
126+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
127+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
128+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
129+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
130+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

appveyor.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
- npm install -g
13+
14+
test_script:
15+
- node --version
16+
- npm --version
17+
- cmd: npm run build
18+
19+
build: off
20+
21+
version: "{build}"
22+
23+
matrix:
24+
fast_finish: true

dist/wave-resampler.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)