react-native-simple-note-pitch-detector 0.2.4 → 0.2.6

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.
@@ -24,7 +24,9 @@ class PitchAnalyzer {
24
24
 
25
25
  private val handler = PitchDetectionHandler { res, e ->
26
26
  val pitchInHz = res.pitch
27
- process(pitchInHz)
27
+ val soundPressure = e.getdBSPL()
28
+
29
+ process(pitchInHz, soundPressure)
28
30
  }
29
31
 
30
32
  private fun prepare() {
@@ -34,7 +36,7 @@ class PitchAnalyzer {
34
36
  dispatcher?.addAudioProcessor(processor)
35
37
  }
36
38
 
37
- private fun process(pitchInHz: Float) {
39
+ private fun process(pitchInHz: Float, soundPressure: Double) {
38
40
  val freq = round(12 * (log2(pitchInHz / 440) / log2(2f)) + 69)
39
41
  val octave = (floor(freq / 12) - 1).toInt()
40
42
  val index = freq % 12
@@ -42,7 +44,7 @@ class PitchAnalyzer {
42
44
  if (!index.isNaN() && pitchInHz > 0) {
43
45
  val note = notes[index.toInt()]
44
46
 
45
- this.onChangePitch("$note$octave", pitchInHz.toDouble())
47
+ this.onChangePitch("$note$octave", soundPressure)
46
48
  }
47
49
  }
48
50
 
@@ -20,10 +20,10 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
20
20
  }
21
21
 
22
22
  Function("start") {
23
- pitchAnalyzer.addOnChangePitchListener { note: String, frequency: Double ->
23
+ pitchAnalyzer.addOnChangePitchListener { note: String, soundPressure: Double ->
24
24
  this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
25
25
  "onChangePitch",
26
- bundleOf("note" to note, "frequency" to frequency)
26
+ bundleOf("note" to note, "soundPressure" to soundPressure)
27
27
  )
28
28
  }
29
29
 
@@ -1,6 +1,6 @@
1
1
  export type ChangeEventPayload = {
2
2
  note: string;
3
- frequency: number;
3
+ soundPressure: number;
4
4
  };
5
5
  export type ReactNativeSimpleNotePitchDetectorViewProps = {
6
6
  name: string;
@@ -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,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
1
+ {"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.d.ts","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.js","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ChangeEventPayload = {\n note: string;\n frequency: number;\n};\n\nexport type ReactNativeSimpleNotePitchDetectorViewProps = {\n name: string;\n};\n"]}
1
+ {"version":3,"file":"ReactNativeSimpleNotePitchDetector.types.js","sourceRoot":"","sources":["../src/ReactNativeSimpleNotePitchDetector.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ChangeEventPayload = {\n note: string;\n soundPressure: number;\n};\n\nexport type ReactNativeSimpleNotePitchDetectorViewProps = {\n name: string;\n};\n"]}
@@ -46,7 +46,7 @@ extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
46
46
  return
47
47
  }
48
48
 
49
- self.sendEvent("onChangePitch", ["note" : pitch.note.string, "frequency" : pitch.frequency])
49
+ self.sendEvent("onChangePitch", ["note" : pitch.note.string, "soundPressure" : pitchEngine.signalLevel])
50
50
  }
51
51
 
52
52
  public func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-simple-note-pitch-detector",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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",
@@ -1,6 +1,6 @@
1
1
  export type ChangeEventPayload = {
2
2
  note: string;
3
- frequency: number;
3
+ soundPressure: number;
4
4
  };
5
5
 
6
6
  export type ReactNativeSimpleNotePitchDetectorViewProps = {