react-native-simple-note-pitch-detector 0.7.3 → 0.7.5
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,6 +1,7 @@
|
|
|
1
1
|
import ExpoModulesCore
|
|
2
2
|
import Beethoven
|
|
3
3
|
import Pitchy
|
|
4
|
+
import AVFoundation
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
@@ -19,6 +20,23 @@ public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
|
19
20
|
])
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
private func configureAudioSession() {
|
|
24
|
+
let session = AVAudioSession.sharedInstance()
|
|
25
|
+
do {
|
|
26
|
+
try session.setCategory(
|
|
27
|
+
.playAndRecord,
|
|
28
|
+
options: [.defaultToSpeaker, .allowBluetooth]
|
|
29
|
+
)
|
|
30
|
+
try session.setActive(true, options: .notifyOthersOnDeactivation)
|
|
31
|
+
self.sendStatus(
|
|
32
|
+
"debug",
|
|
33
|
+
"AVAudioSession configured: category=playAndRecord, sampleRate=\(session.sampleRate), inputChannels=\(session.inputNumberOfChannels), inputAvailable=\(session.isInputAvailable)"
|
|
34
|
+
)
|
|
35
|
+
} catch {
|
|
36
|
+
self.sendStatus("error", "Failed to configure AVAudioSession: \(error.localizedDescription)")
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
public func definition() -> ModuleDefinition {
|
|
23
41
|
|
|
24
42
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
@@ -27,6 +45,7 @@ public class ReactNativeSimpleNotePitchDetectorModule: Module {
|
|
|
27
45
|
|
|
28
46
|
Function("start") {
|
|
29
47
|
self.sendStatus("debug", "start() called with bufferSize=\(self.bufferSize), algorithm=\(self.estimationStrategy)")
|
|
48
|
+
self.configureAudioSession()
|
|
30
49
|
self.pitchEngine.start()
|
|
31
50
|
self.sendStatus("debug", "Recording started successfully")
|
|
32
51
|
}
|
|
@@ -162,7 +181,12 @@ extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
|
|
|
162
181
|
self.sendStatus("error", "PitchEngine error: \(error.localizedDescription)")
|
|
163
182
|
}
|
|
164
183
|
|
|
184
|
+
private var belowThresholdLogged = false
|
|
165
185
|
public func pitchEngineWentBelowLevelThreshold(_ pitchEngine: PitchEngine) {
|
|
166
|
-
//
|
|
186
|
+
// Log once per session to avoid spamming
|
|
187
|
+
if !belowThresholdLogged {
|
|
188
|
+
self.sendStatus("debug", "Audio level below threshold (audio is reaching Beethoven but too quiet)")
|
|
189
|
+
belowThresholdLogged = true
|
|
190
|
+
}
|
|
167
191
|
}
|
|
168
192
|
}
|
package/package.json
CHANGED