react-native-simple-note-pitch-detector 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,25 +1,45 @@
|
|
|
1
1
|
import ExpoModulesCore
|
|
2
|
+
import Beethoven
|
|
3
|
+
import Pitchy
|
|
2
4
|
|
|
3
5
|
public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
6
|
+
|
|
7
|
+
lazy var pitchEngine: PitchEngine = { [weak self] in
|
|
8
|
+
let config = Config(estimationStrategy: .yin)
|
|
9
|
+
let pitchEngine = PitchEngine(config: config, delegate: self)
|
|
10
|
+
return pitchEngine
|
|
11
|
+
}()
|
|
4
12
|
|
|
5
13
|
public func definition() -> ModuleDefinition {
|
|
6
14
|
|
|
7
15
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
8
16
|
|
|
9
|
-
Events("
|
|
17
|
+
Events("onChangePitch")
|
|
10
18
|
|
|
11
|
-
Function("
|
|
12
|
-
|
|
19
|
+
Function("start") {
|
|
20
|
+
pitchEngine.start()
|
|
13
21
|
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
|
|
26
|
+
public func pitchEngine(_ pitchEngine: PitchEngine, didReceivePitch pitch: Pitch) {
|
|
27
|
+
|
|
28
|
+
let offsetPercentage = pitch.closestOffset.percentage
|
|
29
|
+
let absOffsetPercentage = abs(offsetPercentage)
|
|
30
|
+
|
|
31
|
+
guard absOffsetPercentage > 1.0 else {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
self.sendEvent("onChangePitch", ["note" : pitch.note.string, "frequency" : pitch.frequency, "wave" : pitch.wave.wavelength])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error) {
|
|
39
|
+
|
|
40
|
+
}
|
|
23
41
|
|
|
42
|
+
public func pitchEngineWentBelowLevelThreshold(_ pitchEngine: PitchEngine) {
|
|
43
|
+
|
|
24
44
|
}
|
|
25
45
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-simple-note-pitch-detector",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "a simple react native library to detect the pitch of the input recording",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"scripts": {
|