You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A compilation of pitch detection algorithms for Javascript. Supports both the browser and node.
4
6
5
7
## Provided pitch-finding algorithms
6
-
-**YIN** - The best balance of accuracy and speed, in my experience. Occasionally provides values that are wildly incorrect.
8
+
9
+
-**YIN** - The best balance of accuracy and speed, in my experience. Occasionally provides values that are wildly incorrect.
7
10
-**AMDF** - Slow and only accurate to around +/- 2%, but finds a frequency more consistenly than others.
8
11
-**Dynamic Wavelet** - Very fast, but struggles to identify lower frequencies.
9
-
-**YIN w/ FFT***(coming soon)*
10
-
-**Goertzel***(coming soon)*
11
-
-**Mcleod***(coming soon)*
12
+
-**YIN w/ FFT**_(coming soon)_
13
+
-**Goertzel**_(coming soon)_
14
+
-**Mcleod**_(coming soon)_
12
15
13
16
## Installation
17
+
14
18
`npm install --save pitchfinder`
15
19
16
20
## Usage
17
21
18
22
### Finding the pitch of a wav file in node
23
+
19
24
All pitchfinding algorithms provided operate on `Float32Array`s. To find the pitch of a `wav` file, we can use the `wav-decoder` library to extract the data into such an array.
25
+
20
26
```javascript
21
27
constfs=require("fs");
22
28
constWavDecoder=require("wav-decoder");
@@ -32,17 +38,21 @@ const pitch = detectPitch(float32Array); // null if pitch cannot be identified
32
38
```
33
39
34
40
### Finding the pitch of a WebAudio AudioBuffer in the browser
35
-
This assumes you are using an npm-compatible build system, like Webpack or Browserify, and that your target browser supports WebAudio. Ample documentation on WebAudio is available online, especially on Mozilla's MDN.
41
+
42
+
This assumes you are using an npm-compatible build system, like Webpack or Browserify, and that your target browser supports WebAudio. Ample documentation on WebAudio is available online, especially on Mozilla's MDN.
43
+
36
44
```javascript
37
-
constPitchfinder=require("pitchfinder");
38
-
constdetectPitch=Pitchfinder.AMDF();
45
+
import*asPitchfinderfrom"pitchfinder";
39
46
40
47
constmyAudioBuffer=getAudioBuffer(); // assume this returns a WebAudio AudioBuffer object
41
48
constfloat32Array=myAudioBuffer.getChannelData(0); // get a single channel of sound
49
+
50
+
constdetectPitch=Pitchfinder.AMDF();
42
51
constpitch=detectPitch(float32Array); // null if pitch cannot be identified
43
52
```
44
53
45
54
### Finding a series of pitches
55
+
46
56
Set a tempo and a quantization interval, and an array of pitches at each interval will be returned.
quantization:4, // samples per beat, defaults to 4 (i.e. 16th notes)
75
+
}
76
+
);
63
77
```
64
78
65
-
66
79
## Configuration
67
80
68
81
### All detectors
82
+
69
83
-`sampleRate` - defaults to 44100
70
84
71
85
### YIN
86
+
72
87
-`threshold` - used by the algorithm
73
88
-`probabilityThreshold` - don't return a pitch if probability estimate is below this number.
74
89
75
90
### AMDF
91
+
76
92
-`minFrequency` - Lowest frequency detectable
77
93
-`maxFrequency` - Highest frequency detectable
78
94
-`sensitivity`
79
95
-`ratio`
80
96
81
97
### Dynamic Wavelet
82
-
*no special config*
98
+
99
+
_no special config_
83
100
84
101
## Note
85
102
86
103
If you'd like a version that uses compiled C++ code and runs much faster, check out [this repo](https://github.com/cristovao-trevisan/node-pitchfinder). However, it will not work in the browser.
87
104
88
105
## Todo
106
+
89
107
- Integrate with `teoria` or another music theory tool to add more intelligent parsing.
90
-
- Note-onsite algorithms.
108
+
- Note-onset algorithms.
91
109
- Enable requiring of single detectors.
92
110
93
111
## Thanks
94
-
Several of these algorithms were ported from Jonas Six's excellent TarsosDSP library (written in Java). If you're looking for a far deeper set of tools than this, check out his work [on his website](https://0110.be/tags/TarsosDSP) or [on Github](https://github.com/JorenSix/TarsosDSP).
112
+
113
+
Several of these algorithms were ported from Jonas Six's excellent TarsosDSP library (written in Java). If you're looking for a far deeper set of tools than this, check out his work [on his website](https://0110.be/tags/TarsosDSP) or [on Github](https://github.com/JorenSix/TarsosDSP).
95
114
96
115
Thanks to Aubio for his [YIN code](https://github.com/aubio/aubio/blob/master/src/pitch/pitchyin.c)
0 commit comments