react-native-simple-note-pitch-detector 0.2.2 → 0.2.4
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.
|
@@ -6,6 +6,7 @@ import be.tarsos.dsp.io.android.AudioDispatcherFactory
|
|
|
6
6
|
import be.tarsos.dsp.pitch.PitchDetectionHandler
|
|
7
7
|
import be.tarsos.dsp.pitch.PitchProcessor
|
|
8
8
|
import be.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm
|
|
9
|
+
import kotlin.math.floor
|
|
9
10
|
import kotlin.math.log2
|
|
10
11
|
import kotlin.math.round
|
|
11
12
|
|
|
@@ -35,7 +36,7 @@ class PitchAnalyzer {
|
|
|
35
36
|
|
|
36
37
|
private fun process(pitchInHz: Float) {
|
|
37
38
|
val freq = round(12 * (log2(pitchInHz / 440) / log2(2f)) + 69)
|
|
38
|
-
val octave = freq / 12
|
|
39
|
+
val octave = (floor(freq / 12) - 1).toInt()
|
|
39
40
|
val index = freq % 12
|
|
40
41
|
|
|
41
42
|
if (!index.isNaN() && pitchInHz > 0) {
|
|
@@ -15,6 +15,10 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
|
15
15
|
|
|
16
16
|
Events("onChangePitch")
|
|
17
17
|
|
|
18
|
+
Function("isRecording") {
|
|
19
|
+
pitchAnalyzer.isRecording()
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
Function("start") {
|
|
19
23
|
pitchAnalyzer.addOnChangePitchListener { note: String, frequency: Double ->
|
|
20
24
|
this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
|
|
@@ -29,9 +33,5 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
|
29
33
|
Function("stop") {
|
|
30
34
|
pitchAnalyzer.stop()
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
Function("isRecording") {
|
|
34
|
-
pitchAnalyzer.isRecording()
|
|
35
|
-
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -7,6 +7,7 @@ public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
|
7
7
|
lazy var pitchEngine: PitchEngine = { [weak self] in
|
|
8
8
|
let config = Config(estimationStrategy: .yin)
|
|
9
9
|
let pitchEngine = PitchEngine(config: config, delegate: self)
|
|
10
|
+
pitchEngine.levelThreshold = -30
|
|
10
11
|
return pitchEngine
|
|
11
12
|
}()
|
|
12
13
|
|
package/package.json
CHANGED