react-native-simple-note-pitch-detector 0.1.8 → 0.1.9

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.
@@ -14,19 +14,18 @@ import kotlin.math.round
14
14
 
15
15
  class PitchAnalyzer {
16
16
 
17
- var onChangePitch: (String, Double) -> Unit
17
+ private val notes = arrayOf("C","C#","D","D#","E","F","F#","G","G#","A","A#","B")
18
18
 
19
- constructor(callback: (String, Double) -> Unit) {
20
- this.onChangePitch = callback
21
- }
22
-
23
- private val tones = arrayOf("C","C#","D","D#","E","F","F#","G","G#","A","A#","B")
19
+ private var onChangePitch: (String, Double) -> Unit
24
20
 
25
21
  private var dispatcher: AudioDispatcher? = null
26
22
  private var processor: AudioProcessor? = null
27
-
28
23
  private var runner: Thread? = null
29
24
 
25
+ constructor(callback: (String, Double) -> Unit) {
26
+ this.onChangePitch = callback
27
+ }
28
+
30
29
  private val handler = PitchDetectionHandler { res, e ->
31
30
  val pitchInHz = res.pitch
32
31
  process(pitchInHz)
@@ -40,13 +39,14 @@ class PitchAnalyzer {
40
39
  }
41
40
 
42
41
  private fun process(pitchInHz: Float) {
43
- val index = round(12 * (log2(pitchInHz / 440) / log2(2f)) + 69) % 12
42
+ val octave = round(12 * (log2(pitchInHz / 440) / log2(2f)) + 69)
43
+ val index = octave % 12
44
44
 
45
45
  if (!index.isNaN() && pitchInHz > 0) {
46
- val tone = tones[index.toInt()]
46
+ val note = notes[index.toInt()]
47
47
  val frequency = pitchInHz.toDouble()
48
48
 
49
- this.onChangePitch(tone, frequency)
49
+ this.onChangePitch("$note$octave", frequency)
50
50
  }
51
51
  }
52
52
 
@@ -1,8 +1,5 @@
1
1
  package expo.modules.simplenotepitchdetector
2
2
 
3
- import android.Manifest
4
- import android.content.pm.PackageManager
5
- import androidx.core.app.ActivityCompat
6
3
  import expo.modules.kotlin.modules.Module
7
4
  import expo.modules.kotlin.modules.ModuleDefinition
8
5
  import expo.modules.simplepitchdetector.PitchAnalyzer
@@ -25,21 +22,6 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
25
22
  }
26
23
 
27
24
  pitchAnalyzer.start()
28
-
29
- // val context = appContext.reactContext!!
30
- // var activity = appContext.currentActivity!!
31
- // var permissionsGranted = ActivityCompat.checkSelfPermission(context, permissions[0]) == PackageManager.PERMISSION_GRANTED
32
- // if (!permissionsGranted) {
33
- // ActivityCompat.requestPermissions(activity, permissions, 200)
34
- // } else {
35
- // val pitchAnalyzer = PitchAnalyzer {
36
- // this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
37
- // "onChange",
38
- // bundleOf("tone" to it)
39
- // )
40
- // }
41
- // pitchAnalyzer.start()
42
- // }
43
25
  }
44
26
  }
45
27
  }
@@ -32,7 +32,7 @@ extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
32
32
  return
33
33
  }
34
34
 
35
- self.sendEvent("onChangePitch", ["note" : pitch.note.string, "frequency" : pitch.frequency, "wave" : pitch.wave.wavelength])
35
+ self.sendEvent("onChangePitch", ["note" : pitch.note.string, "frequency" : pitch.frequency])
36
36
  }
37
37
 
38
38
  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.1.8",
3
+ "version": "0.1.9",
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",