react-native-tiny-wavpack-decoder 0.1.0

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.
Files changed (62) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +148 -0
  3. package/android/build.gradle +112 -0
  4. package/android/generated/java/com/tinywavpackdecoder/NativeTinyWavPackDecoderSpec.java +47 -0
  5. package/android/generated/jni/CMakeLists.txt +36 -0
  6. package/android/generated/jni/RNTinyWavPackDecoderSpec-generated.cpp +44 -0
  7. package/android/generated/jni/RNTinyWavPackDecoderSpec.h +31 -0
  8. package/android/generated/jni/react/renderer/components/RNTinyWavPackDecoderSpec/RNTinyWavPackDecoderSpecJSI-generated.cpp +46 -0
  9. package/android/generated/jni/react/renderer/components/RNTinyWavPackDecoderSpec/RNTinyWavPackDecoderSpecJSI.h +89 -0
  10. package/android/gradle.properties +5 -0
  11. package/android/src/main/AndroidManifest.xml +3 -0
  12. package/android/src/main/AndroidManifestNew.xml +2 -0
  13. package/android/src/main/cpp/CMakeLists.txt +54 -0
  14. package/android/src/main/cpp/TinyWavPackDecoderModule.cpp +118 -0
  15. package/android/src/main/java/com/tinywavpackdecoder/TinyWavPackDecoderModule.kt +114 -0
  16. package/android/src/main/java/com/tinywavpackdecoder/TinyWavPackDecoderPackage.kt +18 -0
  17. package/ios/TinyWavPackDecoder.h +8 -0
  18. package/ios/TinyWavPackDecoder.mm +83 -0
  19. package/ios/generated/RNTinyWavPackDecoderSpec/RNTinyWavPackDecoderSpec-generated.mm +53 -0
  20. package/ios/generated/RNTinyWavPackDecoderSpec/RNTinyWavPackDecoderSpec.h +69 -0
  21. package/ios/generated/RNTinyWavPackDecoderSpecJSI-generated.cpp +46 -0
  22. package/ios/generated/RNTinyWavPackDecoderSpecJSI.h +89 -0
  23. package/lib/module/NativeTinyWavPackDecoder.ts +19 -0
  24. package/lib/module/index.js +38 -0
  25. package/lib/module/index.js.map +1 -0
  26. package/lib/module/package.json +1 -0
  27. package/lib/module/tiny-wavpack/common/TinyWavPackDecoderInterface.c +414 -0
  28. package/lib/module/tiny-wavpack/common/TinyWavPackDecoderInterface.h +52 -0
  29. package/lib/module/tiny-wavpack/common/test.c +45 -0
  30. package/lib/module/tiny-wavpack/common/wv2wav +0 -0
  31. package/lib/module/tiny-wavpack/lib/bits.c +140 -0
  32. package/lib/module/tiny-wavpack/lib/float.c +50 -0
  33. package/lib/module/tiny-wavpack/lib/license.txt +25 -0
  34. package/lib/module/tiny-wavpack/lib/metadata.c +105 -0
  35. package/lib/module/tiny-wavpack/lib/readme.txt +68 -0
  36. package/lib/module/tiny-wavpack/lib/unpack.c +785 -0
  37. package/lib/module/tiny-wavpack/lib/wavpack.h +384 -0
  38. package/lib/module/tiny-wavpack/lib/words.c +560 -0
  39. package/lib/module/tiny-wavpack/lib/wputils.c +351 -0
  40. package/lib/typescript/package.json +1 -0
  41. package/lib/typescript/src/NativeTinyWavPackDecoder.d.ts +9 -0
  42. package/lib/typescript/src/NativeTinyWavPackDecoder.d.ts.map +1 -0
  43. package/lib/typescript/src/index.d.ts +18 -0
  44. package/lib/typescript/src/index.d.ts.map +1 -0
  45. package/package.json +195 -0
  46. package/react-native-wavpack-decoder.podspec +35 -0
  47. package/react-native.config.js +12 -0
  48. package/src/NativeTinyWavPackDecoder.ts +19 -0
  49. package/src/index.tsx +57 -0
  50. package/src/tiny-wavpack/common/TinyWavPackDecoderInterface.c +414 -0
  51. package/src/tiny-wavpack/common/TinyWavPackDecoderInterface.h +52 -0
  52. package/src/tiny-wavpack/common/test.c +45 -0
  53. package/src/tiny-wavpack/common/wv2wav +0 -0
  54. package/src/tiny-wavpack/lib/bits.c +140 -0
  55. package/src/tiny-wavpack/lib/float.c +50 -0
  56. package/src/tiny-wavpack/lib/license.txt +25 -0
  57. package/src/tiny-wavpack/lib/metadata.c +105 -0
  58. package/src/tiny-wavpack/lib/readme.txt +68 -0
  59. package/src/tiny-wavpack/lib/unpack.c +785 -0
  60. package/src/tiny-wavpack/lib/wavpack.h +384 -0
  61. package/src/tiny-wavpack/lib/words.c +560 -0
  62. package/src/tiny-wavpack/lib/wputils.c +351 -0
@@ -0,0 +1,118 @@
1
+ #include <jni.h>
2
+ #include <string>
3
+ #include <android/log.h>
4
+ #include "TinyWavPackDecoderInterface.h"
5
+
6
+ #define TAG "TinyWavPackDecoder"
7
+ #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
8
+ #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
9
+
10
+ // Cache for the Java VM and class references
11
+ static JavaVM *javaVM = nullptr;
12
+ static jclass decoderClass = nullptr;
13
+ static jmethodID onProgressMethod = nullptr;
14
+
15
+ // Callback function to report progress back to Java
16
+ static void progressCallbackBridge(float progress, void *context)
17
+ {
18
+ JNIEnv *env;
19
+ // Get the JNI environment
20
+ jint result = javaVM->GetEnv((void **)&env, JNI_VERSION_1_6);
21
+
22
+ if (result == JNI_OK)
23
+ {
24
+ // Call the onProgress method in Java
25
+ env->CallStaticVoidMethod(decoderClass, onProgressMethod, progress);
26
+ }
27
+ else if (result == JNI_EDETACHED)
28
+ {
29
+ // Thread is detached, attach it
30
+ if (javaVM->AttachCurrentThread(&env, nullptr) == JNI_OK)
31
+ {
32
+ env->CallStaticVoidMethod(decoderClass, onProgressMethod, progress);
33
+ javaVM->DetachCurrentThread();
34
+ }
35
+ else
36
+ {
37
+ LOGE("Failed to attach thread for progress callback");
38
+ }
39
+ }
40
+ else
41
+ {
42
+ LOGE("Failed to get JNI environment for progress callback");
43
+ }
44
+ }
45
+
46
+ // The JNI implementation of the decode method
47
+ extern "C" JNIEXPORT jstring JNICALL
48
+ Java_com_tinywavpackdecoder_TinyWavPackDecoderModule_nativeDecodeWavPack(
49
+ JNIEnv *env,
50
+ jclass clazz,
51
+ jstring j_input_path,
52
+ jstring j_output_path,
53
+ jint j_max_samples,
54
+ jint j_bits_per_sample)
55
+ {
56
+
57
+ // Convert Java strings to C strings
58
+ const char *inputPath = env->GetStringUTFChars(j_input_path, nullptr);
59
+ const char *outputPath = env->GetStringUTFChars(j_output_path, nullptr);
60
+
61
+ // Log the parameters
62
+ LOGI("Decoding WavPack: input=%s, output=%s, maxSamples=%d, bitsPerSample=%d",
63
+ inputPath, outputPath, j_max_samples, j_bits_per_sample);
64
+
65
+ // Call the decoder
66
+ DecoderResult result = decode_wavpack_to_wav(
67
+ inputPath,
68
+ outputPath,
69
+ j_max_samples,
70
+ j_bits_per_sample,
71
+ progressCallbackBridge,
72
+ nullptr);
73
+
74
+ // Release the C strings
75
+ env->ReleaseStringUTFChars(j_input_path, inputPath);
76
+ env->ReleaseStringUTFChars(j_output_path, outputPath);
77
+
78
+ // Return the result
79
+ if (result.success)
80
+ {
81
+ return env->NewStringUTF("Success");
82
+ }
83
+ else
84
+ {
85
+ return env->NewStringUTF(result.error);
86
+ }
87
+ }
88
+
89
+ // Called when the library is loaded
90
+ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
91
+ {
92
+ javaVM = vm;
93
+ JNIEnv *env;
94
+
95
+ if (vm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK)
96
+ {
97
+ return JNI_ERR;
98
+ }
99
+
100
+ // Cache the Java class and method IDs
101
+ jclass localClass = env->FindClass("com/tinywavpackdecoder/TinyWavPackDecoderModule");
102
+ if (localClass == nullptr)
103
+ {
104
+ LOGE("Failed to find TinyWavPackDecoderModule class");
105
+ return JNI_ERR;
106
+ }
107
+
108
+ decoderClass = (jclass)env->NewGlobalRef(localClass);
109
+ onProgressMethod = env->GetStaticMethodID(decoderClass, "onProgress", "(F)V");
110
+
111
+ if (onProgressMethod == nullptr)
112
+ {
113
+ LOGE("Failed to find onProgress method");
114
+ return JNI_ERR;
115
+ }
116
+
117
+ return JNI_VERSION_1_6;
118
+ }
@@ -0,0 +1,114 @@
1
+ package com.tinywavpackdecoder
2
+
3
+ import android.util.Log
4
+ import com.facebook.react.bridge.*
5
+ import com.facebook.react.module.annotations.ReactModule
6
+ import com.facebook.react.modules.core.DeviceEventManagerModule
7
+
8
+ @ReactModule(name = TinyWavPackDecoderModule.NAME)
9
+ class TinyWavPackDecoderModule(reactContext: ReactApplicationContext) :
10
+ ReactContextBaseJavaModule(reactContext) {
11
+
12
+ companion object {
13
+ const val NAME = "TinyWavPackDecoderModule"
14
+ private const val TAG = "TinyWavPackDecoder"
15
+ private const val EVENT_PROGRESS = "onProgressUpdate"
16
+
17
+ init {
18
+ System.loadLibrary("tiny-wavpack-decoder")
19
+ }
20
+
21
+ // Called from JNI
22
+ @JvmStatic
23
+ fun onProgress(progress: Float) {
24
+ sInstance?.sendProgressEvent(progress)
25
+ }
26
+
27
+ // Keep a static reference to the module instance
28
+ private var sInstance: TinyWavPackDecoderModule? = null
29
+
30
+ // Native method declarations
31
+ @JvmStatic
32
+ external fun nativeDecodeWavPack(
33
+ inputPath: String,
34
+ outputPath: String,
35
+ maxSamples: Int,
36
+ bitsPerSample: Int
37
+ ): String
38
+ }
39
+
40
+ init {
41
+ sInstance = this
42
+ }
43
+
44
+ override fun getName(): String {
45
+ return NAME
46
+ }
47
+
48
+ @ReactMethod
49
+ fun decodeWavPack(
50
+ inputPath: String,
51
+ outputPath: String,
52
+ maxSamples: Double?,
53
+ bitsPerSample: Double?,
54
+ promise: Promise
55
+ ) {
56
+ try {
57
+ // Convert parameters to the correct types
58
+ val maxSamplesInt = maxSamples?.toInt() ?: -1
59
+ val bitsPerSampleInt = bitsPerSample?.toInt() ?: 16
60
+
61
+ Log.d(TAG, "Decoding WavPack: $inputPath -> $outputPath")
62
+
63
+ // Run in a background thread to avoid blocking the JS thread
64
+ Thread {
65
+ try {
66
+ val result = nativeDecodeWavPack(
67
+ inputPath,
68
+ outputPath,
69
+ maxSamplesInt,
70
+ bitsPerSampleInt
71
+ )
72
+
73
+ reactApplicationContext.runOnJSQueueThread {
74
+ if (result == "Success") {
75
+ promise.resolve(result)
76
+ } else {
77
+ promise.reject("DECODE_ERROR", result)
78
+ }
79
+ }
80
+ } catch (e: Exception) {
81
+ Log.e(TAG, "Error decoding WavPack", e)
82
+ reactApplicationContext.runOnJSQueueThread {
83
+ promise.reject("DECODE_ERROR", e.message, e)
84
+ }
85
+ }
86
+ }.start()
87
+ } catch (e: Exception) {
88
+ Log.e(TAG, "Error starting decode thread", e)
89
+ promise.reject("DECODE_ERROR", e.message, e)
90
+ }
91
+ }
92
+
93
+ // Send progress events to JavaScript
94
+ private fun sendProgressEvent(progress: Float) {
95
+ reactApplicationContext.runOnJSQueueThread {
96
+ val params = Arguments.createMap().apply {
97
+ putDouble("progress", progress.toDouble())
98
+ }
99
+ reactApplicationContext
100
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
101
+ .emit(EVENT_PROGRESS, params)
102
+ }
103
+ }
104
+
105
+ @ReactMethod
106
+ fun addListener(eventType: String) {
107
+ // Required for RN built-in Event Emitter Support
108
+ }
109
+
110
+ @ReactMethod
111
+ fun removeListeners(count: Int) {
112
+ // Required for RN built-in Event Emitter Support
113
+ }
114
+ }
@@ -0,0 +1,18 @@
1
+ package com.tinywavpackdecoder
2
+
3
+ import android.view.View
4
+ import com.facebook.react.ReactPackage
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.uimanager.ReactShadowNode
8
+ import com.facebook.react.uimanager.ViewManager
9
+
10
+ class TinyWavPackDecoderPackage : ReactPackage {
11
+ override fun createViewManagers(
12
+ reactContext: ReactApplicationContext
13
+ ): List<ViewManager<View, ReactShadowNode<*>>> = emptyList()
14
+
15
+ override fun createNativeModules(
16
+ reactContext: ReactApplicationContext
17
+ ): List<NativeModule> = listOf(TinyWavPackDecoderModule(reactContext))
18
+ }
@@ -0,0 +1,8 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <ReactCommon/RCTTurboModule.h>
3
+ #import <jsi/jsi.h>
4
+ #import <RNTinyWavPackDecoderSpec.h>
5
+ #import <React/RCTEventEmitter.h>
6
+
7
+ @interface TinyWavPackDecoder : RCTEventEmitter <NativeTinyWavPackDecoderSpec>
8
+ @end
@@ -0,0 +1,83 @@
1
+ #import "TinyWavPackDecoder.h"
2
+ #import "../src/tiny-wavpack/common/TinyWavPackDecoderInterface.h"
3
+ #import <React/RCTLog.h>
4
+ #import <ReactCommon/CallInvoker.h>
5
+ #import <jsi/jsi.h>
6
+
7
+ using namespace facebook::jsi;
8
+ using namespace facebook::react;
9
+
10
+ @implementation TinyWavPackDecoder
11
+
12
+ RCT_EXPORT_MODULE(TinyWavPackDecoderModule);
13
+
14
+ - (instancetype)init {
15
+ self = [super init];
16
+ if (self) {
17
+ RCTLogInfo(@"TinyWavPackDecoderModule initialized");
18
+ }
19
+ return self;
20
+ }
21
+
22
+ - (dispatch_queue_t)methodQueue {
23
+ static dispatch_queue_t queue = dispatch_queue_create("com.wavpackdecoder.decode", DISPATCH_QUEUE_CONCURRENT);
24
+ return queue;
25
+ }
26
+
27
+ - (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params {
28
+ return std::make_shared<NativeTinyWavPackDecoderSpecJSI>(params);
29
+ }
30
+
31
+ - (void)decodeWavPack:(NSString *)inputPath
32
+ outputPath:(NSString *)outputPath
33
+ maxSamples:(NSNumber *)maxSamples
34
+ bitsPerSample:(NSNumber *)bitsPerSample
35
+ resolve:(RCTPromiseResolveBlock)resolve
36
+ reject:(RCTPromiseRejectBlock)reject {
37
+ int maxSamplesInt = maxSamples != nil ? [maxSamples intValue] : -1;
38
+ int bitsPerSampleInt = bitsPerSample != nil ? [bitsPerSample intValue] : 0; // Default to 16-bit
39
+ const char *inputPathC = [inputPath UTF8String];
40
+ const char *outputPathC = [outputPath UTF8String];
41
+
42
+ DecoderResult result = decode_wavpack_to_wav(
43
+ inputPathC,
44
+ outputPathC,
45
+ maxSamplesInt,
46
+ bitsPerSampleInt,
47
+ progressCallbackBridge,
48
+ (__bridge void*)self
49
+ );
50
+
51
+ // Dispatch promise resolution/rejection to the main queue
52
+ dispatch_async(dispatch_get_main_queue(), ^{
53
+ if (result.success) {
54
+ resolve(@"Success");
55
+ } else {
56
+ NSString *errorMessage = [NSString stringWithUTF8String:result.error];
57
+ reject(@"decode_error", errorMessage, nil);
58
+ }
59
+ });
60
+ }
61
+
62
+ - (NSArray<NSString *> *)supportedEvents {
63
+ return @[@"onProgressUpdate"];
64
+ }
65
+
66
+ static void progressCallbackBridge(float progress, void* context) {
67
+ TinyWavPackDecoder* decoder = (__bridge TinyWavPackDecoder*)context;
68
+ if (decoder.bridge) {
69
+ [decoder sendEventWithName:@"onProgressUpdate" body:@{@"progress": @(progress)}];
70
+ } else {
71
+ RCTLogWarn(@"Cannot emit TinyWavPackDecoder progress event: bridge is nil");
72
+ }
73
+ }
74
+
75
+ - (void)startObserving {
76
+ RCTLogInfo(@"Starting event observation for TinyWavPackDecoder");
77
+ }
78
+
79
+ - (void)stopObserving {
80
+ RCTLogInfo(@"Stopping event observation for TinyWavPackDecoder");
81
+ }
82
+
83
+ @end
@@ -0,0 +1,53 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleObjCpp
8
+ *
9
+ * We create an umbrella header (and corresponding implementation) here since
10
+ * Cxx compilation in BUCK has a limitation: source-code producing genrule()s
11
+ * must have a single output. More files => more genrule()s => slower builds.
12
+ */
13
+
14
+ #import "RNTinyWavPackDecoderSpec.h"
15
+
16
+
17
+ @implementation NativeTinyWavPackDecoderSpecBase
18
+
19
+
20
+ - (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
21
+ {
22
+ _eventEmitterCallback = std::move(eventEmitterCallbackWrapper->_eventEmitterCallback);
23
+ }
24
+ @end
25
+
26
+
27
+ namespace facebook::react {
28
+
29
+ static facebook::jsi::Value __hostFunction_NativeTinyWavPackDecoderSpecJSI_decodeWavPack(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
30
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "decodeWavPack", @selector(decodeWavPack:outputPath:maxSamples:bitsPerSample:resolve:reject:), args, count);
31
+ }
32
+
33
+ static facebook::jsi::Value __hostFunction_NativeTinyWavPackDecoderSpecJSI_addListener(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
34
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "addListener", @selector(addListener:), args, count);
35
+ }
36
+
37
+ static facebook::jsi::Value __hostFunction_NativeTinyWavPackDecoderSpecJSI_removeListeners(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
38
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "removeListeners", @selector(removeListeners:), args, count);
39
+ }
40
+
41
+ NativeTinyWavPackDecoderSpecJSI::NativeTinyWavPackDecoderSpecJSI(const ObjCTurboModule::InitParams &params)
42
+ : ObjCTurboModule(params) {
43
+
44
+ methodMap_["decodeWavPack"] = MethodMetadata {4, __hostFunction_NativeTinyWavPackDecoderSpecJSI_decodeWavPack};
45
+
46
+
47
+ methodMap_["addListener"] = MethodMetadata {1, __hostFunction_NativeTinyWavPackDecoderSpecJSI_addListener};
48
+
49
+
50
+ methodMap_["removeListeners"] = MethodMetadata {1, __hostFunction_NativeTinyWavPackDecoderSpecJSI_removeListeners};
51
+
52
+ }
53
+ } // namespace facebook::react
@@ -0,0 +1,69 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleObjCpp
8
+ *
9
+ * We create an umbrella header (and corresponding implementation) here since
10
+ * Cxx compilation in BUCK has a limitation: source-code producing genrule()s
11
+ * must have a single output. More files => more genrule()s => slower builds.
12
+ */
13
+
14
+ #ifndef __cplusplus
15
+ #error This file must be compiled as Obj-C++. If you are importing it, you must change your file extension to .mm.
16
+ #endif
17
+
18
+ // Avoid multiple includes of RNTinyWavPackDecoderSpec symbols
19
+ #ifndef RNTinyWavPackDecoderSpec_H
20
+ #define RNTinyWavPackDecoderSpec_H
21
+
22
+ #import <Foundation/Foundation.h>
23
+ #import <RCTRequired/RCTRequired.h>
24
+ #import <RCTTypeSafety/RCTConvertHelpers.h>
25
+ #import <RCTTypeSafety/RCTTypedModuleConstants.h>
26
+ #import <React/RCTBridgeModule.h>
27
+ #import <React/RCTCxxConvert.h>
28
+ #import <React/RCTManagedPointer.h>
29
+ #import <ReactCommon/RCTTurboModule.h>
30
+ #import <optional>
31
+ #import <vector>
32
+
33
+
34
+ NS_ASSUME_NONNULL_BEGIN
35
+
36
+ @protocol NativeTinyWavPackDecoderSpec <RCTBridgeModule, RCTTurboModule>
37
+
38
+ - (void)decodeWavPack:(NSString *)inputPath
39
+ outputPath:(NSString *)outputPath
40
+ maxSamples:(NSNumber *)maxSamples
41
+ bitsPerSample:(NSNumber *)bitsPerSample
42
+ resolve:(RCTPromiseResolveBlock)resolve
43
+ reject:(RCTPromiseRejectBlock)reject;
44
+ - (void)addListener:(NSString *)eventType;
45
+ - (void)removeListeners:(double)count;
46
+
47
+ @end
48
+
49
+ @interface NativeTinyWavPackDecoderSpecBase : NSObject {
50
+ @protected
51
+ facebook::react::EventEmitterCallback _eventEmitterCallback;
52
+ }
53
+ - (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper;
54
+
55
+
56
+ @end
57
+
58
+ namespace facebook::react {
59
+ /**
60
+ * ObjC++ class for module 'NativeTinyWavPackDecoder'
61
+ */
62
+ class JSI_EXPORT NativeTinyWavPackDecoderSpecJSI : public ObjCTurboModule {
63
+ public:
64
+ NativeTinyWavPackDecoderSpecJSI(const ObjCTurboModule::InitParams &params);
65
+ };
66
+ } // namespace facebook::react
67
+
68
+ NS_ASSUME_NONNULL_END
69
+ #endif // RNTinyWavPackDecoderSpec_H
@@ -0,0 +1,46 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleCpp.js
8
+ */
9
+
10
+ #include "RNTinyWavPackDecoderSpecJSI.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ static jsi::Value __hostFunction_NativeTinyWavPackDecoderCxxSpecJSI_decodeWavPack(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
+ return static_cast<NativeTinyWavPackDecoderCxxSpecJSI *>(&turboModule)->decodeWavPack(
16
+ rt,
17
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
18
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt),
19
+ count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asNumber()),
20
+ count <= 3 || args[3].isUndefined() ? std::nullopt : std::make_optional(args[3].asNumber())
21
+ );
22
+ }
23
+ static jsi::Value __hostFunction_NativeTinyWavPackDecoderCxxSpecJSI_addListener(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
24
+ static_cast<NativeTinyWavPackDecoderCxxSpecJSI *>(&turboModule)->addListener(
25
+ rt,
26
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
27
+ );
28
+ return jsi::Value::undefined();
29
+ }
30
+ static jsi::Value __hostFunction_NativeTinyWavPackDecoderCxxSpecJSI_removeListeners(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
31
+ static_cast<NativeTinyWavPackDecoderCxxSpecJSI *>(&turboModule)->removeListeners(
32
+ rt,
33
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber()
34
+ );
35
+ return jsi::Value::undefined();
36
+ }
37
+
38
+ NativeTinyWavPackDecoderCxxSpecJSI::NativeTinyWavPackDecoderCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
39
+ : TurboModule("TinyWavPackDecoderModule", jsInvoker) {
40
+ methodMap_["decodeWavPack"] = MethodMetadata {4, __hostFunction_NativeTinyWavPackDecoderCxxSpecJSI_decodeWavPack};
41
+ methodMap_["addListener"] = MethodMetadata {1, __hostFunction_NativeTinyWavPackDecoderCxxSpecJSI_addListener};
42
+ methodMap_["removeListeners"] = MethodMetadata {1, __hostFunction_NativeTinyWavPackDecoderCxxSpecJSI_removeListeners};
43
+ }
44
+
45
+
46
+ } // namespace facebook::react
@@ -0,0 +1,89 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+ class JSI_EXPORT NativeTinyWavPackDecoderCxxSpecJSI : public TurboModule {
19
+ protected:
20
+ NativeTinyWavPackDecoderCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
21
+
22
+ public:
23
+ virtual jsi::Value decodeWavPack(jsi::Runtime &rt, jsi::String inputPath, jsi::String outputPath, std::optional<double> maxSamples, std::optional<double> bitsPerSample) = 0;
24
+ virtual void addListener(jsi::Runtime &rt, jsi::String eventType) = 0;
25
+ virtual void removeListeners(jsi::Runtime &rt, double count) = 0;
26
+
27
+ };
28
+
29
+ template <typename T>
30
+ class JSI_EXPORT NativeTinyWavPackDecoderCxxSpec : public TurboModule {
31
+ public:
32
+ jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
33
+ return delegate_.create(rt, propName);
34
+ }
35
+
36
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
37
+ return delegate_.getPropertyNames(runtime);
38
+ }
39
+
40
+ static constexpr std::string_view kModuleName = "TinyWavPackDecoderModule";
41
+
42
+ protected:
43
+ NativeTinyWavPackDecoderCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
44
+ : TurboModule(std::string{NativeTinyWavPackDecoderCxxSpec::kModuleName}, jsInvoker),
45
+ delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
46
+
47
+
48
+ private:
49
+ class Delegate : public NativeTinyWavPackDecoderCxxSpecJSI {
50
+ public:
51
+ Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
52
+ NativeTinyWavPackDecoderCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
53
+
54
+ }
55
+
56
+ jsi::Value decodeWavPack(jsi::Runtime &rt, jsi::String inputPath, jsi::String outputPath, std::optional<double> maxSamples, std::optional<double> bitsPerSample) override {
57
+ static_assert(
58
+ bridging::getParameterCount(&T::decodeWavPack) == 5,
59
+ "Expected decodeWavPack(...) to have 5 parameters");
60
+
61
+ return bridging::callFromJs<jsi::Value>(
62
+ rt, &T::decodeWavPack, jsInvoker_, instance_, std::move(inputPath), std::move(outputPath), std::move(maxSamples), std::move(bitsPerSample));
63
+ }
64
+ void addListener(jsi::Runtime &rt, jsi::String eventType) override {
65
+ static_assert(
66
+ bridging::getParameterCount(&T::addListener) == 2,
67
+ "Expected addListener(...) to have 2 parameters");
68
+
69
+ return bridging::callFromJs<void>(
70
+ rt, &T::addListener, jsInvoker_, instance_, std::move(eventType));
71
+ }
72
+ void removeListeners(jsi::Runtime &rt, double count) override {
73
+ static_assert(
74
+ bridging::getParameterCount(&T::removeListeners) == 2,
75
+ "Expected removeListeners(...) to have 2 parameters");
76
+
77
+ return bridging::callFromJs<void>(
78
+ rt, &T::removeListeners, jsInvoker_, instance_, std::move(count));
79
+ }
80
+
81
+ private:
82
+ friend class NativeTinyWavPackDecoderCxxSpec;
83
+ T *instance_;
84
+ };
85
+
86
+ Delegate delegate_;
87
+ };
88
+
89
+ } // namespace facebook::react
@@ -0,0 +1,19 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ decodeWavPack(
6
+ inputPath: string,
7
+ outputPath: string,
8
+ maxSamples?: number,
9
+ bitsPerSample?: number
10
+ ): Promise<string>;
11
+
12
+ // Add these to satisfy NativeEventEmitter
13
+ addListener: (eventType: string) => void;
14
+ removeListeners: (count: number) => void;
15
+ }
16
+
17
+ export default TurboModuleRegistry.getEnforcing<Spec>(
18
+ 'TinyWavPackDecoderModule'
19
+ );
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ import NativeTinyWavPackDecoder from './NativeTinyWavPackDecoder';
4
+ import { NativeModules, NativeEventEmitter } from 'react-native';
5
+ const {
6
+ TinyWavPackDecoderModule
7
+ } = NativeModules;
8
+ const emitter = new NativeEventEmitter(TinyWavPackDecoderModule);
9
+ const TinyWavPackDecoder = {
10
+ decode: async (inputPath, outputPath, options = {}) => {
11
+ const {
12
+ maxSamples = -1,
13
+ bitsPerSample = 16
14
+ } = options;
15
+ if (![8, 16, 24, 32].includes(bitsPerSample)) {
16
+ throw new Error('bitsPerSample must be 8, 16, 24, or 32');
17
+ }
18
+ return NativeTinyWavPackDecoder.decodeWavPack(inputPath, outputPath, maxSamples, bitsPerSample);
19
+ },
20
+ /**
21
+ * Subscribe to native progress updates
22
+ */
23
+ addProgressListener: callback => {
24
+ return emitter.addListener('onProgressUpdate', event => {
25
+ if (typeof event?.progress === 'number') {
26
+ callback(event.progress);
27
+ }
28
+ });
29
+ },
30
+ /**
31
+ * Remove all native listeners for progress updates
32
+ */
33
+ removeAllListeners: () => {
34
+ emitter.removeAllListeners('onProgressUpdate');
35
+ }
36
+ };
37
+ export default TinyWavPackDecoder;
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeTinyWavPackDecoder","NativeModules","NativeEventEmitter","TinyWavPackDecoderModule","emitter","TinyWavPackDecoder","decode","inputPath","outputPath","options","maxSamples","bitsPerSample","includes","Error","decodeWavPack","addProgressListener","callback","addListener","event","progress","removeAllListeners"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,wBAAwB,MAAM,4BAA4B;AACjE,SACEC,aAAa,EACbC,kBAAkB,QAEb,cAAc;AAOrB,MAAM;EAAEC;AAAyB,CAAC,GAAGF,aAAa;AAClD,MAAMG,OAAO,GAAG,IAAIF,kBAAkB,CAACC,wBAAwB,CAAC;AAEhE,MAAME,kBAAkB,GAAG;EACzBC,MAAM,EAAE,MAAAA,CACNC,SAAiB,EACjBC,UAAkB,EAClBC,OAAkC,GAAG,CAAC,CAAC,KACnB;IACpB,MAAM;MAAEC,UAAU,GAAG,CAAC,CAAC;MAAEC,aAAa,GAAG;IAAG,CAAC,GAAGF,OAAO;IAEvD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAACG,QAAQ,CAACD,aAAa,CAAC,EAAE;MAC5C,MAAM,IAAIE,KAAK,CAAC,wCAAwC,CAAC;IAC3D;IAEA,OAAOb,wBAAwB,CAACc,aAAa,CAC3CP,SAAS,EACTC,UAAU,EACVE,UAAU,EACVC,aACF,CAAC;EACH,CAAC;EAED;AACF;AACA;EACEI,mBAAmB,EACjBC,QAAoC,IACZ;IACxB,OAAOZ,OAAO,CAACa,WAAW,CAAC,kBAAkB,EAAGC,KAAK,IAAK;MACxD,IAAI,OAAOA,KAAK,EAAEC,QAAQ,KAAK,QAAQ,EAAE;QACvCH,QAAQ,CAACE,KAAK,CAACC,QAAQ,CAAC;MAC1B;IACF,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;EACEC,kBAAkB,EAAEA,CAAA,KAAY;IAC9BhB,OAAO,CAACgB,kBAAkB,CAAC,kBAAkB,CAAC;EAChD;AACF,CAAC;AAED,eAAef,kBAAkB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}