react-native-simple-note-pitch-detector 0.2.8 → 0.3.0
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.
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Subscription } from "expo-modules-core";
|
|
2
|
-
import ReactNativeSimpleNotePitchDetectorView from "./ReactNativeSimpleNotePitchDetectorView";
|
|
3
2
|
import { ChangeEventPayload, ReactNativeSimpleNotePitchDetectorViewProps } from "./ReactNativeSimpleNotePitchDetector.types";
|
|
4
3
|
export declare function start(): any;
|
|
5
4
|
export declare function stop(): any;
|
|
6
5
|
export declare function isRecording(): any;
|
|
7
6
|
export declare function onChangePitch(listener: (event: ChangeEventPayload) => void): Subscription;
|
|
8
|
-
export {
|
|
7
|
+
export { ReactNativeSimpleNotePitchDetectorViewProps, ChangeEventPayload };
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,kBAAkB,EAClB,2CAA2C,EAC5C,MAAM,4CAA4C,CAAC;AAEpD,wBAAgB,KAAK,QAEpB;AAED,wBAAgB,IAAI,QAEnB;AAED,wBAAgB,WAAW,QAE1B;AAOD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC5C,YAAY,CAEd;AAED,OAAO,EAAE,2CAA2C,EAAE,kBAAkB,EAAE,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NativeModulesProxy, EventEmitter, } from "expo-modules-core";
|
|
2
2
|
import ReactNativeSimpleNotePitchDetectorModule from "./ReactNativeSimpleNotePitchDetectorModule";
|
|
3
|
-
import ReactNativeSimpleNotePitchDetectorView from "./ReactNativeSimpleNotePitchDetectorView";
|
|
4
3
|
export function start() {
|
|
5
4
|
return ReactNativeSimpleNotePitchDetectorModule.start();
|
|
6
5
|
}
|
|
@@ -15,5 +14,4 @@ const emitter = new EventEmitter(ReactNativeSimpleNotePitchDetectorModule ??
|
|
|
15
14
|
export function onChangePitch(listener) {
|
|
16
15
|
return emitter.addListener("onChangePitch", listener);
|
|
17
16
|
}
|
|
18
|
-
export { ReactNativeSimpleNotePitchDetectorView, };
|
|
19
17
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,GAEb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,wCAAwC,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,GAEb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,wCAAwC,MAAM,4CAA4C,CAAC;AAMlG,MAAM,UAAU,KAAK;IACnB,OAAO,wCAAwC,CAAC,KAAK,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,wCAAwC,CAAC,IAAI,EAAE,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,wCAAwC,CAAC,WAAW,EAAE,CAAC;AAChE,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,YAAY,CAC9B,wCAAwC;IACtC,kBAAkB,CAAC,kCAAkC,CACxD,CAAC;AAEF,MAAM,UAAU,aAAa,CAC3B,QAA6C;IAE7C,OAAO,OAAO,CAAC,WAAW,CAAqB,eAAe,EAAE,QAAQ,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import {\n NativeModulesProxy,\n EventEmitter,\n Subscription,\n} from \"expo-modules-core\";\n\nimport ReactNativeSimpleNotePitchDetectorModule from \"./ReactNativeSimpleNotePitchDetectorModule\";\nimport {\n ChangeEventPayload,\n ReactNativeSimpleNotePitchDetectorViewProps,\n} from \"./ReactNativeSimpleNotePitchDetector.types\";\n\nexport function start() {\n return ReactNativeSimpleNotePitchDetectorModule.start();\n}\n\nexport function stop() {\n return ReactNativeSimpleNotePitchDetectorModule.stop();\n}\n\nexport function isRecording() {\n return ReactNativeSimpleNotePitchDetectorModule.isRecording();\n}\n\nconst emitter = new EventEmitter(\n ReactNativeSimpleNotePitchDetectorModule ??\n NativeModulesProxy.ReactNativeSimpleNotePitchDetector\n);\n\nexport function onChangePitch(\n listener: (event: ChangeEventPayload) => void\n): Subscription {\n return emitter.addListener<ChangeEventPayload>(\"onChangePitch\", listener);\n}\n\nexport { ReactNativeSimpleNotePitchDetectorViewProps, ChangeEventPayload };\n"]}
|
|
@@ -4,6 +4,10 @@ import Pitchy
|
|
|
4
4
|
|
|
5
5
|
public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
6
6
|
|
|
7
|
+
var bufferSize = 3
|
|
8
|
+
var notes = Array(repeating: "", count: 3)
|
|
9
|
+
var counter = 0
|
|
10
|
+
|
|
7
11
|
lazy var pitchEngine: PitchEngine = { [weak self] in
|
|
8
12
|
let config = Config(estimationStrategy: .yin)
|
|
9
13
|
let pitchEngine = PitchEngine(config: config, delegate: self)
|
|
@@ -11,6 +15,23 @@ public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
|
11
15
|
return pitchEngine
|
|
12
16
|
}()
|
|
13
17
|
|
|
18
|
+
func mostFrequent(array: [String]) -> String? {
|
|
19
|
+
var counts = [String: Int]()
|
|
20
|
+
|
|
21
|
+
// Count the values with using forEach
|
|
22
|
+
array.forEach { counts[$0] = (counts[$0] ?? 0) + 1 }
|
|
23
|
+
|
|
24
|
+
// Find the most frequent value and its count with max(by:)
|
|
25
|
+
if let (value, count) = counts.max(by: {$0.1 < $1.1}) {
|
|
26
|
+
if (count <= 1) {
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return nil
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
var isRecording = false
|
|
15
36
|
|
|
16
37
|
public func definition() -> ModuleDefinition {
|
|
@@ -45,8 +66,24 @@ extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
|
|
|
45
66
|
guard absOffsetPercentage > 1.0 else {
|
|
46
67
|
return
|
|
47
68
|
}
|
|
69
|
+
|
|
70
|
+
if (counter == bufferSize) {
|
|
71
|
+
var result = mostFrequent(array: notes)
|
|
72
|
+
if (result != nil) {
|
|
73
|
+
self.sendEvent("onChangePitch", ["note" : result, "soundPressure" : ""])
|
|
74
|
+
}
|
|
75
|
+
counter = 0
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
do {
|
|
79
|
+
let note = try Note(frequency: pitch.wave.frequency)
|
|
80
|
+
notes[counter] = note.string
|
|
81
|
+
counter += 1
|
|
82
|
+
} catch {
|
|
83
|
+
|
|
84
|
+
}
|
|
48
85
|
|
|
49
|
-
self.sendEvent("onChangePitch", ["note" : pitch.note.string, "soundPressure" : pitchEngine.signalLevel])
|
|
86
|
+
// self.sendEvent("onChangePitch", ["note" : pitch.note.string, "soundPressure" : pitchEngine.signalLevel])
|
|
50
87
|
}
|
|
51
88
|
|
|
52
89
|
public func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
} from "expo-modules-core";
|
|
6
6
|
|
|
7
7
|
import ReactNativeSimpleNotePitchDetectorModule from "./ReactNativeSimpleNotePitchDetectorModule";
|
|
8
|
-
import ReactNativeSimpleNotePitchDetectorView from "./ReactNativeSimpleNotePitchDetectorView";
|
|
9
8
|
import {
|
|
10
9
|
ChangeEventPayload,
|
|
11
10
|
ReactNativeSimpleNotePitchDetectorViewProps,
|
|
@@ -34,8 +33,4 @@ export function onChangePitch(
|
|
|
34
33
|
return emitter.addListener<ChangeEventPayload>("onChangePitch", listener);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
export {
|
|
38
|
-
ReactNativeSimpleNotePitchDetectorView,
|
|
39
|
-
ReactNativeSimpleNotePitchDetectorViewProps,
|
|
40
|
-
ChangeEventPayload,
|
|
41
|
-
};
|
|
36
|
+
export { ReactNativeSimpleNotePitchDetectorViewProps, ChangeEventPayload };
|