react-native-simple-note-pitch-detector 0.1.1 → 0.1.2
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/.gradle/7.5.1/checksums/checksums.lock +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.5.1/gc.properties +0 -0
- package/android/.idea/gradle.xml +13 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +2 -0
- package/android/local.properties +8 -0
- package/android/src/libs/tarsos-dsp.jar +0 -0
- package/android/src/main/java/expo/modules/simplenotepitchdetector/PitchAnalyzer.kt +57 -0
- package/android/src/main/java/expo/modules/simplenotepitchdetector/ReactNativeSimpleNotePitchDetectorModule.kt +5 -32
- package/android/src/main/java/expo/modules/simplenotepitchdetector/ReactNativeSimpleNotePitchDetectorView.kt +1 -1
- package/package.json +1 -1
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="GradleSettings">
|
|
4
|
+
<option name="linkedExternalProjectsSettings">
|
|
5
|
+
<GradleProjectSettings>
|
|
6
|
+
<option name="testRunner" value="GRADLE" />
|
|
7
|
+
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
8
|
+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
9
|
+
<option name="gradleJvm" value="jbr-17" />
|
|
10
|
+
</GradleProjectSettings>
|
|
11
|
+
</option>
|
|
12
|
+
</component>
|
|
13
|
+
</project>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
4
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
|
5
|
+
<output url="file://$PROJECT_DIR$/build/classes" />
|
|
6
|
+
</component>
|
|
7
|
+
<component name="ProjectType">
|
|
8
|
+
<option name="id" value="Android" />
|
|
9
|
+
</component>
|
|
10
|
+
</project>
|
package/android/build.gradle
CHANGED
|
@@ -86,4 +86,6 @@ repositories {
|
|
|
86
86
|
dependencies {
|
|
87
87
|
implementation project(':expo-modules-core')
|
|
88
88
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
89
|
+
implementation ("com.facebook.react:react-native:+")
|
|
90
|
+
implementation fileTree(dir: "./src/libs", include: ["*.jar"])
|
|
89
91
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## This file must *NOT* be checked into Version Control Systems,
|
|
2
|
+
# as it contains information specific to your local configuration.
|
|
3
|
+
#
|
|
4
|
+
# Location of the SDK. This is only used by Gradle.
|
|
5
|
+
# For customization when using a Version Control System, please read the
|
|
6
|
+
# header note.
|
|
7
|
+
#Wed Sep 27 12:55:37 PDT 2023
|
|
8
|
+
sdk.dir=/Users/derek.dawson/Library/Android/sdk
|
|
Binary file
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package expo.modules.simplepitchdetector
|
|
2
|
+
|
|
3
|
+
import be.tarsos.dsp.AudioDispatcher
|
|
4
|
+
import be.tarsos.dsp.AudioProcessor
|
|
5
|
+
import be.tarsos.dsp.io.android.AudioDispatcherFactory
|
|
6
|
+
import be.tarsos.dsp.pitch.PitchDetectionHandler
|
|
7
|
+
import be.tarsos.dsp.pitch.PitchProcessor
|
|
8
|
+
import be.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm
|
|
9
|
+
import com.facebook.react.bridge.WritableMap
|
|
10
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
11
|
+
import kotlin.math.log2
|
|
12
|
+
import kotlin.math.round
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PitchAnalyzer {
|
|
16
|
+
|
|
17
|
+
private val tones = arrayOf("C","C#","D","D#","E","F","F#","G","G#","A","A#","B")
|
|
18
|
+
|
|
19
|
+
private var dispatcher: AudioDispatcher? = null
|
|
20
|
+
private var processor: AudioProcessor? = null
|
|
21
|
+
|
|
22
|
+
private var runner: Thread? = null
|
|
23
|
+
|
|
24
|
+
private val handler = PitchDetectionHandler { res, e ->
|
|
25
|
+
val pitchInHz = res.pitch
|
|
26
|
+
process(pitchInHz)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private fun prepare() {
|
|
30
|
+
processor =
|
|
31
|
+
PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, 22050f, 1024, handler)
|
|
32
|
+
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0)
|
|
33
|
+
dispatcher?.addAudioProcessor(processor)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private fun process(pitchInHz: Float) {
|
|
37
|
+
val index = round(12 * (log2(pitchInHz / 440) / log2(2f)) + 69) % 12
|
|
38
|
+
|
|
39
|
+
if (!index.isNaN() && pitchInHz > 0) {
|
|
40
|
+
val tone = tones[index.toInt()]
|
|
41
|
+
val data: WritableMap = WritableNativeMap()
|
|
42
|
+
|
|
43
|
+
data.putDouble("frequency", pitchInHz.toDouble())
|
|
44
|
+
data.putString("tone", tone)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun start() {
|
|
49
|
+
prepare()
|
|
50
|
+
runner = Thread(dispatcher)
|
|
51
|
+
runner?.start()
|
|
52
|
+
}
|
|
53
|
+
fun stop() {
|
|
54
|
+
dispatcher?.stop()
|
|
55
|
+
runner?.interrupt()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -2,46 +2,19 @@ package expo.modules.simplenotepitchdetector
|
|
|
2
2
|
|
|
3
3
|
import expo.modules.kotlin.modules.Module
|
|
4
4
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
+
import expo.modules.simplepitchdetector.PitchAnalyzer
|
|
5
6
|
|
|
6
7
|
class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
private val pitchAnalyzer = PitchAnalyzer()
|
|
10
|
+
|
|
10
11
|
override fun definition() = ModuleDefinition {
|
|
11
|
-
// Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
|
|
12
|
-
// Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
|
|
13
|
-
// The module will be accessible from `requireNativeModule('ReactNativeSimpleNotePitchDetector')` in JavaScript.
|
|
14
12
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
15
13
|
|
|
16
|
-
// Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
|
|
17
|
-
Constants(
|
|
18
|
-
"PI" to Math.PI
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
// Defines event names that the module can send to JavaScript.
|
|
22
14
|
Events("onChange")
|
|
23
15
|
|
|
24
|
-
// Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
|
|
25
16
|
Function("hello") {
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Defines a JavaScript function that always returns a Promise and whose native code
|
|
30
|
-
// is by default dispatched on the different thread than the JavaScript runtime runs on.
|
|
31
|
-
AsyncFunction("setValueAsync") { value: String ->
|
|
32
|
-
// Send an event to JavaScript.
|
|
33
|
-
sendEvent("onChange", mapOf(
|
|
34
|
-
"value" to value
|
|
35
|
-
))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Enables the module to be used as a native view. Definition components that are accepted as part of
|
|
39
|
-
// the view definition: Prop, Events.
|
|
40
|
-
View(ReactNativeSimpleNotePitchDetectorView::class) {
|
|
41
|
-
// Defines a setter for the `name` prop.
|
|
42
|
-
Prop("name") { view: ReactNativeSimpleNotePitchDetectorView, prop: String ->
|
|
43
|
-
println(prop)
|
|
44
|
-
}
|
|
17
|
+
pitchAnalyzer.start()
|
|
45
18
|
}
|
|
46
19
|
}
|
|
47
20
|
}
|
|
@@ -4,4 +4,4 @@ import android.content.Context
|
|
|
4
4
|
import expo.modules.kotlin.AppContext
|
|
5
5
|
import expo.modules.kotlin.views.ExpoView
|
|
6
6
|
|
|
7
|
-
class ReactNativeSimpleNotePitchDetectorView(context: Context, appContext: AppContext) : ExpoView(context, appContext)
|
|
7
|
+
class ReactNativeSimpleNotePitchDetectorView(context: Context, appContext: AppContext) : ExpoView(context, appContext)
|