react-native-simple-note-pitch-detector 0.6.0 → 0.7.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/android/src/main/java/expo/modules/simplenotepitchdetector/PitchAnalyzer.kt +47 -10
- package/android/src/main/java/expo/modules/simplenotepitchdetector/ReactNativeSimpleNotePitchDetectorModule.kt +15 -1
- package/build/ReactNativeSimpleNotePitchDetector.types.d.ts +0 -3
- package/build/ReactNativeSimpleNotePitchDetector.types.d.ts.map +1 -1
- package/build/ReactNativeSimpleNotePitchDetector.types.js.map +1 -1
- package/build/index.d.ts +14 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +9 -4
- package/build/index.js.map +1 -1
- package/ios/ReactNativeSimpleNotePitchDetectorModule.swift +11 -2
- package/package.json +7 -5
- package/src/ReactNativeSimpleNotePitchDetector.types.ts +0 -4
- package/src/index.ts +21 -15
- package/android/.gradle/9.0-milestone-1/checksums/checksums.lock +0 -0
- package/android/.gradle/9.0-milestone-1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/9.0-milestone-1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/9.0-milestone-1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/config.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/AndroidProjectSystem.xml +0 -6
- package/android/.idea/caches/deviceStreaming.xml +0 -1318
- package/android/.idea/gradle.xml +0 -12
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/vcs.xml +0 -6
- package/android/local.properties +0 -8
- package/build/ReactNativeSimpleNotePitchDetector.web.d.ts +0 -4
- package/build/ReactNativeSimpleNotePitchDetector.web.d.ts.map +0 -1
- package/build/ReactNativeSimpleNotePitchDetector.web.js +0 -7
- package/build/ReactNativeSimpleNotePitchDetector.web.js.map +0 -1
- package/build/ReactNativeSimpleNotePitchDetectorView.d.ts +0 -4
- package/build/ReactNativeSimpleNotePitchDetectorView.d.ts.map +0 -1
- package/build/ReactNativeSimpleNotePitchDetectorView.js +0 -7
- package/build/ReactNativeSimpleNotePitchDetectorView.js.map +0 -1
- package/src/ReactNativeSimpleNotePitchDetector.web.tsx +0 -13
- package/src/ReactNativeSimpleNotePitchDetectorView.tsx +0 -11
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package expo.modules.simplepitchdetector
|
|
2
2
|
|
|
3
|
+
import android.util.Log
|
|
3
4
|
import be.tarsos.dsp.AudioDispatcher
|
|
4
5
|
import be.tarsos.dsp.AudioProcessor
|
|
5
6
|
import be.tarsos.dsp.io.android.AudioDispatcherFactory
|
|
@@ -11,6 +12,8 @@ import kotlin.math.round
|
|
|
11
12
|
import kotlin.math.pow
|
|
12
13
|
import kotlin.math.abs
|
|
13
14
|
|
|
15
|
+
private const val TAG = "PitchAnalyzer"
|
|
16
|
+
|
|
14
17
|
data class PitchData(
|
|
15
18
|
val note: String,
|
|
16
19
|
val octave: Int,
|
|
@@ -24,6 +27,7 @@ class PitchAnalyzer {
|
|
|
24
27
|
private val notes = arrayOf("C","C#","D","D#","E","F","F#","G","G#","A","A#","B")
|
|
25
28
|
|
|
26
29
|
private lateinit var onPitchDetected: (PitchData) -> Unit
|
|
30
|
+
private var onStatus: ((String, String) -> Unit)? = null
|
|
27
31
|
private var isRecording = false
|
|
28
32
|
private var levelThreshold = -30f
|
|
29
33
|
// Configurable buffer size - can be changed from JS
|
|
@@ -31,8 +35,8 @@ class PitchAnalyzer {
|
|
|
31
35
|
// Smaller buffer = better high frequency detection, less latency
|
|
32
36
|
private var bufferSize = 2048
|
|
33
37
|
// Configurable algorithm - can be changed from JS
|
|
34
|
-
private var algorithm = PitchEstimationAlgorithm.
|
|
35
|
-
private var algorithmName = "
|
|
38
|
+
private var algorithm = PitchEstimationAlgorithm.MPM
|
|
39
|
+
private var algorithmName = "mpm"
|
|
36
40
|
|
|
37
41
|
private var dispatcher: AudioDispatcher? = null
|
|
38
42
|
private var processor: AudioProcessor? = null
|
|
@@ -43,15 +47,26 @@ class PitchAnalyzer {
|
|
|
43
47
|
val decibel = e.getdBSPL().toFloat()
|
|
44
48
|
// Only process if above the level threshold
|
|
45
49
|
if (decibel > levelThreshold) {
|
|
50
|
+
// Note: Not logging every pitch detection to JS to avoid flooding
|
|
51
|
+
// Use adb logcat for verbose pitch logs
|
|
52
|
+
Log.v(TAG, "Pitch detected: ${pitchInHz}Hz at ${decibel}dB")
|
|
46
53
|
process(pitchInHz, decibel)
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
private fun prepare() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
try {
|
|
59
|
+
logStatus("debug", "prepare() called with bufferSize=$bufferSize, algorithm=$algorithmName")
|
|
60
|
+
processor = PitchProcessor(algorithm, 22050f, bufferSize, handler)
|
|
61
|
+
logStatus("debug", "PitchProcessor created successfully")
|
|
62
|
+
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, bufferSize, 0)
|
|
63
|
+
logStatus("debug", "AudioDispatcher created successfully: $dispatcher")
|
|
64
|
+
dispatcher?.addAudioProcessor(processor)
|
|
65
|
+
logStatus("debug", "AudioProcessor added to dispatcher")
|
|
66
|
+
} catch (e: Exception) {
|
|
67
|
+
logStatus("error", "Error in prepare(): ${e.message}")
|
|
68
|
+
throw e
|
|
69
|
+
}
|
|
55
70
|
}
|
|
56
71
|
|
|
57
72
|
private fun process(pitchInHz: Float, decibel: Float) {
|
|
@@ -89,6 +104,20 @@ class PitchAnalyzer {
|
|
|
89
104
|
this.onPitchDetected = listener
|
|
90
105
|
}
|
|
91
106
|
|
|
107
|
+
fun setOnStatusListener(listener: (String, String) -> Unit) {
|
|
108
|
+
this.onStatus = listener
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private fun logStatus(level: String, message: String) {
|
|
112
|
+
when (level) {
|
|
113
|
+
"debug" -> Log.d(TAG, message)
|
|
114
|
+
"error" -> Log.e(TAG, message)
|
|
115
|
+
"verbose" -> Log.v(TAG, message)
|
|
116
|
+
else -> Log.d(TAG, message)
|
|
117
|
+
}
|
|
118
|
+
onStatus?.invoke(level, message)
|
|
119
|
+
}
|
|
120
|
+
|
|
92
121
|
fun setLevelThreshold(threshold: Float) {
|
|
93
122
|
this.levelThreshold = threshold
|
|
94
123
|
}
|
|
@@ -119,10 +148,18 @@ class PitchAnalyzer {
|
|
|
119
148
|
}
|
|
120
149
|
|
|
121
150
|
fun start() {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
151
|
+
try {
|
|
152
|
+
logStatus("debug", "start() called")
|
|
153
|
+
prepare()
|
|
154
|
+
runner = Thread(dispatcher)
|
|
155
|
+
logStatus("debug", "Thread created, starting...")
|
|
156
|
+
runner?.start()
|
|
157
|
+
isRecording = true
|
|
158
|
+
logStatus("debug", "Recording started successfully")
|
|
159
|
+
} catch (e: Exception) {
|
|
160
|
+
logStatus("error", "Error in start(): ${e.message}")
|
|
161
|
+
isRecording = false
|
|
162
|
+
}
|
|
126
163
|
}
|
|
127
164
|
|
|
128
165
|
fun stop() {
|
|
@@ -10,11 +10,21 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
|
10
10
|
|
|
11
11
|
private val pitchAnalyzer = PitchAnalyzer()
|
|
12
12
|
|
|
13
|
+
private fun sendStatus(level: String, message: String) {
|
|
14
|
+
this.sendEvent(
|
|
15
|
+
"onStatus",
|
|
16
|
+
bundleOf(
|
|
17
|
+
"level" to level,
|
|
18
|
+
"message" to message
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
override fun definition() = ModuleDefinition {
|
|
14
24
|
|
|
15
25
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
16
26
|
|
|
17
|
-
Events("onChangeNote")
|
|
27
|
+
Events("onChangeNote", "onStatus")
|
|
18
28
|
|
|
19
29
|
Function("isRecording") {
|
|
20
30
|
pitchAnalyzer.isRecording()
|
|
@@ -33,6 +43,10 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
|
33
43
|
)
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
pitchAnalyzer.setOnStatusListener { level: String, message: String ->
|
|
47
|
+
this@ReactNativeSimpleNotePitchDetectorModule.sendStatus(level, message)
|
|
48
|
+
}
|
|
49
|
+
|
|
36
50
|
pitchAnalyzer.start()
|
|
37
51
|
}
|
|
38
52
|
|
|
@@ -8,7 +8,4 @@ export type ChangeEventPayload = {
|
|
|
8
8
|
/** Offset from perfect pitch as percentage (-50 to +50, negative = flat, positive = sharp) */
|
|
9
9
|
offset: number;
|
|
10
10
|
};
|
|
11
|
-
export type ReactNativeSimpleNotePitchDetectorViewProps = {
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
11
|
//# sourceMappingURL=ReactNativeSimpleNotePitchDetector.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.d.ts","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC
|
|
1
|
+
{"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.d.ts","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.js","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ChangeEventPayload = {\n /** Note name without octave (e.g., \"C#\", \"D\", \"Eb\") */\n note: string;\n /** Octave number (e.g., 4 for middle C) */\n octave: number;\n /** Raw frequency in Hz */\n frequency: number;\n /** Offset from perfect pitch as percentage (-50 to +50, negative = flat, positive = sharp) */\n offset: number;\n};\n
|
|
1
|
+
{"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.js","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ChangeEventPayload = {\n /** Note name without octave (e.g., \"C#\", \"D\", \"Eb\") */\n note: string;\n /** Octave number (e.g., 4 for middle C) */\n octave: number;\n /** Raw frequency in Hz */\n frequency: number;\n /** Offset from perfect pitch as percentage (-50 to +50, negative = flat, positive = sharp) */\n offset: number;\n};\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChangeEventPayload
|
|
1
|
+
import { EventSubscription } from "expo-modules-core";
|
|
2
|
+
import { ChangeEventPayload } from "./ReactNativeSimpleNotePitchDetector.types";
|
|
3
3
|
export declare function start(): any;
|
|
4
4
|
export declare function stop(): any;
|
|
5
5
|
export declare function isRecording(): any;
|
|
@@ -66,6 +66,16 @@ export declare function setAlgorithm(algorithm: string): any;
|
|
|
66
66
|
* @returns Current algorithm name
|
|
67
67
|
*/
|
|
68
68
|
export declare function getAlgorithm(): string;
|
|
69
|
-
export declare function onChangeNote(listener: (event: ChangeEventPayload) => void):
|
|
70
|
-
export
|
|
69
|
+
export declare function onChangeNote(listener: (event: ChangeEventPayload) => void): EventSubscription;
|
|
70
|
+
export interface StatusEventPayload {
|
|
71
|
+
level: "debug" | "error" | "verbose";
|
|
72
|
+
message: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Listen for status/debug messages from the native module.
|
|
76
|
+
* Useful for debugging audio initialization issues.
|
|
77
|
+
* @param listener - Callback that receives status events with level and message
|
|
78
|
+
*/
|
|
79
|
+
export declare function onStatus(listener: (event: StatusEventPayload) => void): EventSubscription;
|
|
80
|
+
export { ChangeEventPayload };
|
|
71
81
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,wBAAgB,KAAK,QAEpB;AAED,wBAAgB,IAAI,QAEnB;AAED,wBAAgB,WAAW,QAE1B;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,OAElD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,OAEzC;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,OAE7C;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC5C,iBAAiB,CAEnB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC5C,iBAAiB,CAEnB;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NativeModulesProxy, EventEmitter, } from "expo-modules-core";
|
|
2
1
|
import ReactNativeSimpleNotePitchDetectorModule from "./ReactNativeSimpleNotePitchDetectorModule";
|
|
3
2
|
export function start() {
|
|
4
3
|
return ReactNativeSimpleNotePitchDetectorModule.start();
|
|
@@ -82,9 +81,15 @@ export function setAlgorithm(algorithm) {
|
|
|
82
81
|
export function getAlgorithm() {
|
|
83
82
|
return ReactNativeSimpleNotePitchDetectorModule.getAlgorithm();
|
|
84
83
|
}
|
|
85
|
-
const emitter = new EventEmitter(ReactNativeSimpleNotePitchDetectorModule ??
|
|
86
|
-
NativeModulesProxy.ReactNativeSimpleNotePitchDetector);
|
|
87
84
|
export function onChangeNote(listener) {
|
|
88
|
-
return
|
|
85
|
+
return ReactNativeSimpleNotePitchDetectorModule.addListener("onChangeNote", listener);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Listen for status/debug messages from the native module.
|
|
89
|
+
* Useful for debugging audio initialization issues.
|
|
90
|
+
* @param listener - Callback that receives status events with level and message
|
|
91
|
+
*/
|
|
92
|
+
export function onStatus(listener) {
|
|
93
|
+
return ReactNativeSimpleNotePitchDetectorModule.addListener("onStatus", listener);
|
|
89
94
|
}
|
|
90
95
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,wCAAwC,MAAM,4CAA4C,CAAC;AAGlG,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;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,OAAO,wCAAwC,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,wCAAwC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,wCAAwC,CAAC,aAAa,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,OAAO,wCAAwC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,wCAAwC,CAAC,YAAY,EAAE,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,QAA6C;IAE7C,OAAO,wCAAwC,CAAC,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AACxF,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,QAA6C;IAE7C,OAAO,wCAAwC,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACpF,CAAC","sourcesContent":["import {\n EventSubscription,\n} from \"expo-modules-core\";\n\nimport ReactNativeSimpleNotePitchDetectorModule from \"./ReactNativeSimpleNotePitchDetectorModule\";\nimport { ChangeEventPayload } 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\n/**\n * Set the minimum audio level threshold for pitch detection.\n * Values are in dB (e.g., -30 means sounds quieter than -30dB are ignored).\n * Lower values = more sensitive (picks up quieter sounds).\n * Default is -30.\n * @param threshold - Level threshold in dB (e.g., -30, -35, -40)\n */\nexport function setLevelThreshold(threshold: number) {\n return ReactNativeSimpleNotePitchDetectorModule.setLevelThreshold(threshold);\n}\n\n/**\n * Set the buffer size for pitch detection.\n * Must be called before start() or will restart the engine if already running.\n *\n * Buffer size affects the trade-off between frequency range and responsiveness:\n * - Smaller buffer (2048-4096): Better for high frequencies, faster response, but less accurate for low notes\n * - Larger buffer (8192-16384): Better for low frequencies, more accurate, but slightly more latency\n *\n * iOS defaults to 8192, Android defaults to 2048.\n *\n * Recommended values:\n * - 4096: Good balance for most use cases\n * - 8192: Better for bass instruments or full piano range (iOS default)\n * - 2048: Better for high-pitched instruments, faster response (Android default)\n *\n * @param size - Buffer size (must be power of 2: 1024, 2048, 4096, 8192, 16384)\n */\nexport function setBufferSize(size: number) {\n return ReactNativeSimpleNotePitchDetectorModule.setBufferSize(size);\n}\n\n/**\n * Get the current buffer size.\n * @returns Current buffer size\n */\nexport function getBufferSize(): number {\n return ReactNativeSimpleNotePitchDetectorModule.getBufferSize();\n}\n\n/**\n * Set the pitch estimation algorithm.\n * Must be called before start() or will restart the engine if already running.\n *\n * Available algorithms differ by platform:\n *\n * **iOS (Beethoven library):**\n * - \"yin\" (default) - YIN algorithm, good for monophonic instruments\n * - \"hps\" - Harmonic Product Spectrum\n * - \"barycentric\" - Barycentric interpolation\n * - \"quadradic\" - Quadratic interpolation\n * - \"jains\" - Jain's method\n * - \"quinnsFirst\" - Quinn's first estimator\n * - \"quinnsSecond\" - Quinn's second estimator\n * - \"maxValue\" - Maximum value method\n *\n * **Android (TarsosDSP library):**\n * - \"fft_yin\" (default) - FFT-based YIN, faster than pure YIN\n * - \"yin\" - Pure YIN algorithm\n * - \"mpm\" - McLeod Pitch Method, good for speech and music\n * - \"fft_pitch\" - FFT bin with most energy\n * - \"dynamic_wavelet\" - Dynamic wavelet algorithm\n * - \"amdf\" - Average Magnitude Difference Function\n *\n * @param algorithm - Algorithm name (case-insensitive)\n */\nexport function setAlgorithm(algorithm: string) {\n return ReactNativeSimpleNotePitchDetectorModule.setAlgorithm(algorithm);\n}\n\n/**\n * Get the current algorithm name.\n * @returns Current algorithm name\n */\nexport function getAlgorithm(): string {\n return ReactNativeSimpleNotePitchDetectorModule.getAlgorithm();\n}\n\nexport function onChangeNote(\n listener: (event: ChangeEventPayload) => void\n): EventSubscription {\n return ReactNativeSimpleNotePitchDetectorModule.addListener(\"onChangeNote\", listener);\n}\n\nexport interface StatusEventPayload {\n level: \"debug\" | \"error\" | \"verbose\";\n message: string;\n}\n\n/**\n * Listen for status/debug messages from the native module.\n * Useful for debugging audio initialization issues.\n * @param listener - Callback that receives status events with level and message\n */\nexport function onStatus(\n listener: (event: StatusEventPayload) => void\n): EventSubscription {\n return ReactNativeSimpleNotePitchDetectorModule.addListener(\"onStatus\", listener);\n}\n\nexport { ChangeEventPayload };\n"]}
|
|
@@ -12,14 +12,23 @@ public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
|
12
12
|
private var estimationStrategy: EstimationStrategy = .yin
|
|
13
13
|
private var _pitchEngine: PitchEngine?
|
|
14
14
|
|
|
15
|
+
private func sendStatus(_ level: String, _ message: String) {
|
|
16
|
+
self.sendEvent("onStatus", [
|
|
17
|
+
"level": level,
|
|
18
|
+
"message": message
|
|
19
|
+
])
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
public func definition() -> ModuleDefinition {
|
|
16
23
|
|
|
17
24
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
18
25
|
|
|
19
|
-
Events("onChangeNote")
|
|
26
|
+
Events("onChangeNote", "onStatus")
|
|
20
27
|
|
|
21
28
|
Function("start") {
|
|
29
|
+
self.sendStatus("debug", "start() called with bufferSize=\(self.bufferSize), algorithm=\(self.estimationStrategy)")
|
|
22
30
|
self.pitchEngine.start()
|
|
31
|
+
self.sendStatus("debug", "Recording started successfully")
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
Function("stop") {
|
|
@@ -150,7 +159,7 @@ extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
|
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
public func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error) {
|
|
153
|
-
|
|
162
|
+
self.sendStatus("error", "PitchEngine error: \(error.localizedDescription)")
|
|
154
163
|
}
|
|
155
164
|
|
|
156
165
|
public func pitchEngineWentBelowLevelThreshold(_ pitchEngine: PitchEngine) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-simple-note-pitch-detector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
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",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
14
|
"expo-module": "expo-module",
|
|
15
15
|
"open:ios": "open -a \"Xcode\" example/ios",
|
|
16
|
-
"open:android": "open -a \"Android Studio\" example/android"
|
|
16
|
+
"open:android": "open -a \"Android Studio\" example/android",
|
|
17
|
+
"android": "expo run:android",
|
|
18
|
+
"ios": "expo run:ios"
|
|
17
19
|
},
|
|
18
20
|
"keywords": [
|
|
19
21
|
"react-native",
|
|
@@ -30,13 +32,13 @@
|
|
|
30
32
|
"homepage": "https://github.com/derekhdawson/react-native-simple-note-pitch-detector#readme",
|
|
31
33
|
"dependencies": {},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@types/react": "
|
|
35
|
+
"@types/react": "~19.1.10",
|
|
34
36
|
"expo-module-scripts": "^3.0.11",
|
|
35
|
-
"expo-modules-core": "
|
|
37
|
+
"expo-modules-core": "~3.0.29"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"expo": "*",
|
|
39
41
|
"react": "*",
|
|
40
42
|
"react-native": "*"
|
|
41
43
|
}
|
|
42
|
-
}
|
|
44
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
EventEmitter,
|
|
4
|
-
Subscription,
|
|
2
|
+
EventSubscription,
|
|
5
3
|
} from "expo-modules-core";
|
|
6
4
|
|
|
7
5
|
import ReactNativeSimpleNotePitchDetectorModule from "./ReactNativeSimpleNotePitchDetectorModule";
|
|
8
|
-
import {
|
|
9
|
-
ChangeEventPayload,
|
|
10
|
-
ReactNativeSimpleNotePitchDetectorViewProps,
|
|
11
|
-
} from "./ReactNativeSimpleNotePitchDetector.types";
|
|
6
|
+
import { ChangeEventPayload } from "./ReactNativeSimpleNotePitchDetector.types";
|
|
12
7
|
|
|
13
8
|
export function start() {
|
|
14
9
|
return ReactNativeSimpleNotePitchDetectorModule.start();
|
|
@@ -100,15 +95,26 @@ export function getAlgorithm(): string {
|
|
|
100
95
|
return ReactNativeSimpleNotePitchDetectorModule.getAlgorithm();
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
const emitter = new EventEmitter(
|
|
104
|
-
ReactNativeSimpleNotePitchDetectorModule ??
|
|
105
|
-
NativeModulesProxy.ReactNativeSimpleNotePitchDetector
|
|
106
|
-
);
|
|
107
|
-
|
|
108
98
|
export function onChangeNote(
|
|
109
99
|
listener: (event: ChangeEventPayload) => void
|
|
110
|
-
):
|
|
111
|
-
return
|
|
100
|
+
): EventSubscription {
|
|
101
|
+
return ReactNativeSimpleNotePitchDetectorModule.addListener("onChangeNote", listener);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface StatusEventPayload {
|
|
105
|
+
level: "debug" | "error" | "verbose";
|
|
106
|
+
message: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Listen for status/debug messages from the native module.
|
|
111
|
+
* Useful for debugging audio initialization issues.
|
|
112
|
+
* @param listener - Callback that receives status events with level and message
|
|
113
|
+
*/
|
|
114
|
+
export function onStatus(
|
|
115
|
+
listener: (event: StatusEventPayload) => void
|
|
116
|
+
): EventSubscription {
|
|
117
|
+
return ReactNativeSimpleNotePitchDetectorModule.addListener("onStatus", listener);
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
export {
|
|
120
|
+
export { ChangeEventPayload };
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|