@techoptio/react-native-live-pitch-detection 1.2.0 → 1.2.1
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.
|
@@ -37,7 +37,26 @@
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
AVAudioSession *session = [AVAudioSession sharedInstance];
|
|
41
|
+
NSError *error = nil;
|
|
42
|
+
|
|
43
|
+
[session setCategory:AVAudioSessionCategoryPlayAndRecord
|
|
44
|
+
mode:AVAudioSessionModeMeasurement
|
|
45
|
+
options:AVAudioSessionCategoryOptionDefaultToSpeaker
|
|
46
|
+
error:&error];
|
|
47
|
+
|
|
48
|
+
if (error) {
|
|
49
|
+
reject(@"E_SET_CATEGORY_FAILED", @"Failed to set audio session category", error);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
error = nil;
|
|
54
|
+
[session setActive:YES error:&error];
|
|
55
|
+
|
|
56
|
+
if (error) {
|
|
57
|
+
reject(@"E_SET_ACTIVE_FAILED", @"Failed to activate audio session", error);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
41
60
|
|
|
42
61
|
if (!_audioEngine) {
|
|
43
62
|
_audioEngine = [[AVAudioEngine alloc] init];
|
|
@@ -45,21 +64,21 @@
|
|
|
45
64
|
AVAudioInputNode *inputNode = [_audioEngine inputNode];
|
|
46
65
|
|
|
47
66
|
AVAudioFormat *format = [inputNode inputFormatForBus:0];
|
|
67
|
+
if (format.sampleRate <= 0 || format.channelCount == 0) {
|
|
68
|
+
format = [inputNode outputFormatForBus:0];
|
|
69
|
+
}
|
|
70
|
+
if (format.sampleRate <= 0 || format.channelCount == 0) {
|
|
71
|
+
reject(@"E_INVALID_AUDIO_FORMAT", @"Invalid audio format for microphone input", nil);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
48
74
|
_sampleRate = format.sampleRate;
|
|
49
75
|
|
|
50
|
-
|
|
51
|
-
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
[session setCategory:AVAudioSessionCategoryPlayAndRecord
|
|
57
|
-
mode:AVAudioSessionModeMeasurement
|
|
58
|
-
options:AVAudioSessionCategoryOptionDefaultToSpeaker
|
|
59
|
-
error:&error];
|
|
60
|
-
|
|
61
|
-
if (error) {
|
|
62
|
-
reject(@"E_SET_CATEGORY_FAILED", @"Failed to set audio session category", error);
|
|
76
|
+
@try {
|
|
77
|
+
[inputNode installTapOnBus:0 bufferSize:_bufferSize format:format block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
|
|
78
|
+
[self detectPitch:buffer];
|
|
79
|
+
}];
|
|
80
|
+
} @catch (NSException *exception) {
|
|
81
|
+
reject(@"E_INSTALL_TAP_FAILED", exception.reason ?: @"Failed to install audio tap", nil);
|
|
63
82
|
return;
|
|
64
83
|
}
|
|
65
84
|
}
|
|
@@ -124,4 +143,3 @@
|
|
|
124
143
|
}
|
|
125
144
|
|
|
126
145
|
@end
|
|
127
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@techoptio/react-native-live-pitch-detection",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Live pitch detection (frequency, note and octave) from device microphone for React Native.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|