react-native-audio-api 0.10.0-nightly-c815c40-20251026 → 0.11.0-alpha.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 (213) hide show
  1. package/RNAudioAPI.podspec +5 -9
  2. package/android/build.gradle +3 -33
  3. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +0 -5
  4. package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +0 -1
  5. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +94 -28
  6. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +28 -14
  7. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +2 -4
  8. package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
  9. package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +33 -0
  10. package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +0 -6
  11. package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +34 -0
  12. package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +133 -0
  13. package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +3 -0
  14. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +154 -0
  15. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +41 -0
  16. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +431 -0
  17. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +112 -0
  18. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +47 -0
  19. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +28 -0
  20. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +237 -0
  21. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +46 -0
  22. package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +31 -0
  23. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +3 -29
  24. package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +9 -21
  25. package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +18 -0
  26. package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
  27. package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
  28. package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
  29. package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
  30. package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
  31. package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
  32. package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
  33. package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
  34. package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
  35. package/android/src/main/jniLibs/x86/libavformat.so +0 -0
  36. package/android/src/main/jniLibs/x86/libavutil.so +0 -0
  37. package/android/src/main/jniLibs/x86/libswresample.so +0 -0
  38. package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
  39. package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
  40. package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
  41. package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
  42. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +2 -30
  43. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
  44. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +80 -18
  45. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +15 -6
  46. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  47. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +32 -69
  48. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +1 -37
  49. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +102 -49
  50. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +46 -28
  51. package/common/cpp/audioapi/core/utils/Constants.h +1 -2
  52. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +10 -0
  53. package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
  54. package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
  55. package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
  56. package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
  57. package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
  58. package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
  59. package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
  60. package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
  61. package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
  62. package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
  63. package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
  64. package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
  65. package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
  66. package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
  67. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
  68. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
  69. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +2 -2
  70. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
  71. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
  72. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +1 -1
  73. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +1 -1
  74. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +2 -2
  75. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
  76. package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
  77. package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
  78. package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
  79. package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
  80. package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
  81. package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
  82. package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
  83. package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
  84. package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
  85. package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
  86. package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
  87. package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
  88. package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
  89. package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
  90. package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
  91. package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
  92. package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +44 -0
  93. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +1 -0
  94. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
  95. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +1 -0
  96. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
  97. package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +44 -0
  98. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +1 -0
  99. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
  100. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +1 -0
  101. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
  102. package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +44 -0
  103. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +1 -0
  104. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
  105. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +1 -0
  106. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
  107. package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +44 -0
  108. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +1 -0
  109. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
  110. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +1 -0
  111. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
  112. package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
  113. package/common/cpp/audioapi/external/x86/libogg.a +0 -0
  114. package/common/cpp/audioapi/external/x86/libopus.a +0 -0
  115. package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
  116. package/common/cpp/audioapi/external/x86/libssl.a +0 -0
  117. package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
  118. package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
  119. package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
  120. package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
  121. package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
  122. package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
  123. package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
  124. package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
  125. package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
  126. package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
  127. package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
  128. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +3 -2
  129. package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +32 -0
  130. package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +111 -0
  131. package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +391 -0
  132. package/common/cpp/test/CMakeLists.txt +0 -3
  133. package/ios/audioapi/ios/AudioAPIModule.h +1 -2
  134. package/ios/audioapi/ios/AudioAPIModule.mm +0 -2
  135. package/ios/audioapi/ios/core/IOSAudioFileOptions.h +35 -0
  136. package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +135 -0
  137. package/ios/audioapi/ios/core/IOSAudioFileWriter.h +38 -0
  138. package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +187 -0
  139. package/ios/audioapi/ios/core/IOSAudioRecorder.h +18 -10
  140. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +70 -28
  141. package/ios/audioapi/ios/core/NativeAudioRecorder.h +2 -6
  142. package/ios/audioapi/ios/core/NativeAudioRecorder.m +5 -73
  143. package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
  144. package/ios/audioapi/ios/system/AudioSessionManager.mm +0 -9
  145. package/ios/audioapi/ios/system/LockScreenManager.h +1 -0
  146. package/ios/audioapi/ios/system/LockScreenManager.mm +19 -6
  147. package/lib/commonjs/api.js +76 -134
  148. package/lib/commonjs/api.js.map +1 -1
  149. package/lib/commonjs/core/AudioContext.js +1 -1
  150. package/lib/commonjs/core/AudioContext.js.map +1 -1
  151. package/lib/commonjs/core/AudioRecorder.js +157 -12
  152. package/lib/commonjs/core/AudioRecorder.js.map +1 -1
  153. package/lib/commonjs/core/BaseAudioContext.js +25 -16
  154. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  155. package/lib/commonjs/core/OfflineAudioContext.js +1 -1
  156. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  157. package/lib/commonjs/types.js +50 -0
  158. package/lib/commonjs/types.js.map +1 -1
  159. package/lib/commonjs/utils/bitEnums.js +33 -0
  160. package/lib/commonjs/utils/bitEnums.js.map +1 -0
  161. package/lib/commonjs/utils/index.js +21 -19
  162. package/lib/commonjs/utils/index.js.map +1 -1
  163. package/lib/module/api.js +15 -15
  164. package/lib/module/api.js.map +1 -1
  165. package/lib/module/core/AudioContext.js +2 -2
  166. package/lib/module/core/AudioContext.js.map +1 -1
  167. package/lib/module/core/AudioRecorder.js +157 -12
  168. package/lib/module/core/AudioRecorder.js.map +1 -1
  169. package/lib/module/core/BaseAudioContext.js +26 -17
  170. package/lib/module/core/BaseAudioContext.js.map +1 -1
  171. package/lib/module/core/OfflineAudioContext.js +2 -2
  172. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  173. package/lib/module/types.js +46 -0
  174. package/lib/module/types.js.map +1 -1
  175. package/lib/module/utils/bitEnums.js +27 -0
  176. package/lib/module/utils/bitEnums.js.map +1 -0
  177. package/lib/module/utils/index.js +2 -15
  178. package/lib/module/utils/index.js.map +1 -1
  179. package/lib/typescript/api.d.ts +17 -18
  180. package/lib/typescript/api.d.ts.map +1 -1
  181. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  182. package/lib/typescript/core/AudioRecorder.d.ts +58 -6
  183. package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
  184. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  185. package/lib/typescript/events/types.d.ts +16 -0
  186. package/lib/typescript/events/types.d.ts.map +1 -1
  187. package/lib/typescript/interfaces.d.ts +39 -3
  188. package/lib/typescript/interfaces.d.ts.map +1 -1
  189. package/lib/typescript/types.d.ts +75 -4
  190. package/lib/typescript/types.d.ts.map +1 -1
  191. package/lib/typescript/utils/bitEnums.d.ts +4 -0
  192. package/lib/typescript/utils/bitEnums.d.ts.map +1 -0
  193. package/lib/typescript/utils/index.d.ts +2 -5
  194. package/lib/typescript/utils/index.d.ts.map +1 -1
  195. package/package.json +4 -7
  196. package/src/api.ts +18 -44
  197. package/src/core/AudioContext.ts +2 -3
  198. package/src/core/AudioRecorder.ts +190 -20
  199. package/src/core/BaseAudioContext.ts +60 -44
  200. package/src/core/OfflineAudioContext.ts +2 -2
  201. package/src/events/types.ts +18 -0
  202. package/src/interfaces.ts +47 -4
  203. package/src/types.ts +86 -4
  204. package/src/utils/bitEnums.ts +51 -0
  205. package/src/utils/index.ts +2 -22
  206. package/common/cpp/audioapi/libs/ffmpeg/relinking.md +0 -24
  207. package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +0 -389
  208. package/common/cpp/test/src/biquad/BiquadFilterChromium.h +0 -64
  209. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +0 -284
  210. package/common/cpp/test/src/biquad/BiquadFilterTest.h +0 -40
  211. package/scripts/download-prebuilt-binaries.sh +0 -52
  212. package/scripts/rnaa_utils.rb +0 -8
  213. package/scripts/validate-worklets-version.js +0 -28
package/src/types.ts CHANGED
@@ -12,7 +12,7 @@ export type BiquadFilterType =
12
12
  | 'notch'
13
13
  | 'allpass';
14
14
 
15
- export type ContextState = 'running' | 'closed' | `suspended`;
15
+ export type ContextState = 'running' | 'closed' | 'suspended';
16
16
 
17
17
  export type AudioWorkletRuntime = 'AudioRuntime' | 'UIRuntime';
18
18
 
@@ -38,9 +38,69 @@ export interface OfflineAudioContextOptions {
38
38
  sampleRate: number;
39
39
  }
40
40
 
41
- export interface AudioRecorderOptions {
42
- sampleRate: number;
43
- bufferLengthInSamples: number;
41
+ export enum FileDirectory {
42
+ Document = 1,
43
+ Cache = 2,
44
+ }
45
+
46
+ export enum IOSFormat {
47
+ Wav = 1,
48
+ Caf = 2,
49
+ M4A = 3,
50
+ Flac = 4,
51
+ }
52
+
53
+ export enum IOSAudioQuality {
54
+ Min = 1,
55
+ Low = 2,
56
+ Medium = 3,
57
+ High = 4,
58
+ Max = 5,
59
+ }
60
+
61
+ export enum AndroidFormat {
62
+ Wav = 1,
63
+ Caf = 2,
64
+ M4A = 3,
65
+ Flac = 4,
66
+ }
67
+
68
+ export enum FlacCompressionLevel {
69
+ L0 = 1,
70
+ L1 = 2,
71
+ L2 = 3,
72
+ L3 = 4,
73
+ L4 = 5,
74
+ L5 = 6,
75
+ L6 = 7,
76
+ L7 = 8,
77
+ L8 = 9,
78
+ }
79
+
80
+ export enum BitDepth {
81
+ Bit16 = 1,
82
+ Bit24 = 2,
83
+ Bit32 = 3,
84
+ }
85
+
86
+ export interface AudioRecorderFileOptionsIOS {
87
+ format?: IOSFormat;
88
+ quality?: IOSAudioQuality;
89
+ flacCompressionLevel?: FlacCompressionLevel;
90
+ }
91
+
92
+ export interface AudioRecorderFileOptionsAndroid {
93
+ format?: AndroidFormat;
94
+ }
95
+
96
+ export interface AudioRecorderFileOptions {
97
+ directory?: FileDirectory;
98
+ sampleRate?: number;
99
+ channels?: number;
100
+ bitRate?: number;
101
+ bitDepth?: BitDepth;
102
+ ios?: AudioRecorderFileOptionsIOS;
103
+ android?: AudioRecorderFileOptionsAndroid;
44
104
  }
45
105
 
46
106
  export type WindowType = 'blackman' | 'hann';
@@ -50,3 +110,25 @@ export interface AudioBufferBaseSourceNodeOptions {
50
110
  }
51
111
 
52
112
  export type ProcessorMode = 'processInPlace' | 'processThrough';
113
+
114
+ export interface AudioRecorderCallbackOptions {
115
+ /**
116
+ * The desired sample rate (in Hz) for audio buffers delivered to the
117
+ * recording callback. Common values include 44100 or 48000 Hz. The actual
118
+ * sample rate may differ depending on hardware and system capabilities.
119
+ */
120
+ sampleRate: number;
121
+
122
+ /**
123
+ * The preferred size of each audio buffer, expressed as the number of samples
124
+ * per channel. Smaller buffers reduce latency but increase CPU load, while
125
+ * larger buffers improve efficiency at the cost of higher latency.
126
+ */
127
+ bufferLength: number;
128
+
129
+ /**
130
+ * The desired number of audio channels per buffer. Typically 1 for mono or 2
131
+ * for stereo recordings.
132
+ */
133
+ channelCount: number;
134
+ }
@@ -0,0 +1,51 @@
1
+ function setBitValue(
2
+ output: number,
3
+ value: number,
4
+ shift: number,
5
+ bitWidth = 4
6
+ ): number {
7
+ const fieldMask = (1 << bitWidth) - 1;
8
+
9
+ if ((value & ~fieldMask) !== 0) {
10
+ throw new Error(
11
+ `Value ${value} exceeds the maximum for a field with width ${bitWidth} bits.`
12
+ );
13
+ }
14
+
15
+ return (output & ~(fieldMask << shift)) | ((value & fieldMask) << shift);
16
+ }
17
+
18
+ function getBitValue(input: number, shift: number, bitWidth = 4): number {
19
+ const fieldMask = (1 << bitWidth) - 1;
20
+ return (input >> shift) & fieldMask;
21
+ }
22
+
23
+ export function setEnumValue<T extends Record<string, number>>(
24
+ output: number,
25
+ value: T[keyof T],
26
+ shift: number,
27
+ bitWidth = 4
28
+ ): number {
29
+ return setBitValue(output, value, shift, bitWidth);
30
+ }
31
+
32
+ export function getEnumValue<T extends Record<string, number>>(
33
+ input: number,
34
+ _enum: T,
35
+ shift: number,
36
+ bitWidth = 4
37
+ ): T[keyof T] {
38
+ return getBitValue(input, shift, bitWidth) as T[keyof T];
39
+ }
40
+
41
+ export function encodeFlags<T extends Record<string, number>>(
42
+ ...flags: Array<T[keyof T]>
43
+ ): number {
44
+ let output = 0;
45
+
46
+ for (let i = 0; i < flags.length; i++) {
47
+ output |= setEnumValue(output, flags[i], i * 4);
48
+ }
49
+
50
+ return output;
51
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ShareableWorkletCallback } from '../interfaces';
2
+ export * from './bitEnums';
2
3
 
3
4
  interface SimplifiedWorkletModule {
4
5
  makeShareableCloneRecursive: (
@@ -13,33 +14,12 @@ export function clamp(value: number, min: number, max: number): number {
13
14
  return Math.min(Math.max(value, min), max);
14
15
  }
15
16
 
16
- let isWorkletsAvailable = false;
17
- export let isWorkletsVersionSupported = false;
18
- export let workletsVersion = 'unknown';
19
- export const supportedWorkletsVersions = ['0.6.0', '0.6.1'];
17
+ export let isWorkletsAvailable = false;
20
18
  export let workletsModule: SimplifiedWorkletModule;
21
19
 
22
- export function assertWorkletsEnabled() {
23
- if (!isWorkletsAvailable) {
24
- throw new Error(
25
- '[react-native-audio-api]: Worklets are not available. Please install react-native-worklets to use this feature.'
26
- );
27
- } else if (!isWorkletsVersionSupported) {
28
- throw new Error(
29
- `[react-native-audio-api]: Worklets version ${workletsVersion} is not supported.
30
- Please install react-native-worklets of one of the following versions: [${supportedWorkletsVersions.join(', ')}] to use this feature.`
31
- );
32
- }
33
- }
34
-
35
20
  try {
36
21
  workletsModule = require('react-native-worklets');
37
- const workletsModuleJson = require('react-native-worklets/package.json');
38
- isWorkletsVersionSupported = supportedWorkletsVersions.includes(
39
- workletsModuleJson.version
40
- );
41
22
  isWorkletsAvailable = true;
42
- workletsVersion = workletsModuleJson.version;
43
23
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
24
  } catch (error) {
45
25
  isWorkletsAvailable = false;
@@ -1,24 +0,0 @@
1
- ## If you would like to relink ffmpeg to your implementation there are two options:
2
-
3
- ### Option A)
4
-
5
- you can modify script in scripts/download-prebuilt-binaries.sh
6
-
7
- - ios dynamic frameworks are in `ffmpeg_ios.zip` directory
8
- - android shared libraries are in `jniLibs.zip`
9
-
10
- just replace way of downloading them that links to your binaries
11
-
12
- ### Option B)
13
-
14
- directly modify libraries in source code
15
-
16
- - ios dynamic frameworks are placed in `common/cpp/audioapi/external`
17
- - android shared libraries are placed in `android/src/main/jniLibs`
18
-
19
- ---
20
- `USED_LIBRARIES`:
21
- - libavcodec
22
- - libavformat
23
- - libavutil
24
- - libswresample
@@ -1,389 +0,0 @@
1
- /*
2
- * Copyright (C) 2010 Google Inc. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions
6
- * are met:
7
- *
8
- * 1. Redistributions of source code must retain the above copyright
9
- * notice, this list of conditions and the following disclaimer.
10
- * 2. Redistributions in binary form must reproduce the above copyright
11
- * notice, this list of conditions and the following disclaimer in the
12
- * documentation and/or other materials provided with the distribution.
13
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14
- * its contributors may be used to endorse or promote products derived
15
- * from this software without specific prior written permission.
16
- *
17
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- */
28
-
29
- #include <assert.h>
30
- #include <audioapi/core/utils/Constants.h>
31
- #include <test/src/biquad/BiquadFilterChromium.h>
32
- #include <algorithm>
33
- #include <cmath>
34
- #include <complex>
35
- #include <span>
36
- #include <vector>
37
-
38
- namespace audioapi {
39
-
40
- // Compute 10^x = exp(x*log(10))
41
- static double pow10(double x) {
42
- return std::exp(x * 2.30258509299404568402);
43
- }
44
-
45
- void getFrequencyResponse(
46
- const BiquadCoefficients &coeffs,
47
- std::span<const float> frequency,
48
- std::span<float> mag_response,
49
- std::span<float> phase_response,
50
- float nyquistFrequency) {
51
- assert(!frequency.empty());
52
- assert(!mag_response.empty());
53
- assert(!phase_response.empty());
54
-
55
- std::vector<float> normalizedFreq(frequency.size());
56
- for (size_t i = 0; i < frequency.size(); ++i) {
57
- normalizedFreq[i] = frequency[i] / nyquistFrequency;
58
- }
59
-
60
- // Evaluate the Z-transform of the filter at given normalized
61
- // frequency from 0 to 1. (1 corresponds to the Nyquist
62
- // frequency.)
63
- //
64
- // The z-transform of the filter is
65
- //
66
- // H(z) = (b0 + b1*z^(-1) + b2*z^(-2))/(1 + a1*z^(-1) + a2*z^(-2))
67
- //
68
- // Evaluate as
69
- //
70
- // b0 + (b1 + b2*z1)*z1
71
- // --------------------
72
- // 1 + (a1 + a2*z1)*z1
73
- //
74
- // with z1 = 1/z and z = exp(j*pi*frequency). Hence z1 = exp(-j*pi*frequency)
75
-
76
- double b0 = coeffs.b0;
77
- double b1 = coeffs.b1;
78
- double b2 = coeffs.b2;
79
- double a1 = coeffs.a1;
80
- double a2 = coeffs.a2;
81
-
82
- for (size_t k = 0; k < normalizedFreq.size(); ++k) {
83
- if (normalizedFreq[k] < 0.0 || normalizedFreq[k] > 1.0) {
84
- // Out-of-bounds frequencies should return NaN.
85
- mag_response[k] = std::nanf("");
86
- phase_response[k] = std::nanf("");
87
- } else {
88
- double omega = -PI * normalizedFreq[k];
89
- std::complex<double> z =
90
- std::complex<double>(std::cos(omega), std::sin(omega));
91
- std::complex<double> numerator = b0 + (b1 + b2 * z) * z;
92
- std::complex<double> denominator =
93
- std::complex<double>(1, 0) + (a1 + a2 * z) * z;
94
- std::complex<double> response = numerator / denominator;
95
- mag_response[k] = static_cast<float>(abs(response));
96
- phase_response[k] =
97
- static_cast<float>(std::atan2(imag(response), real(response)));
98
- }
99
- }
100
- }
101
-
102
- BiquadCoefficients normalizeCoefficients(
103
- double b0,
104
- double b1,
105
- double b2,
106
- double a0,
107
- double a1,
108
- double a2) {
109
- return BiquadCoefficients{b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0};
110
- }
111
-
112
- BiquadCoefficients calculateLowpassCoefficients(
113
- double cutoff,
114
- double resonance) {
115
- // Limit cutoff to 0 to 1.
116
- cutoff = std::clamp(cutoff, 0.0, 1.0);
117
-
118
- if (cutoff == 1) {
119
- // When cutoff is 1, the z-transform is 1.
120
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
121
- } else if (cutoff > 0) {
122
- // Compute biquad coefficients for lowpass filter
123
-
124
- resonance = pow10(resonance / 20);
125
-
126
- double theta = kPiDouble * cutoff;
127
- double alpha = std::sin(theta) / (2 * resonance);
128
- double cosw = std::cos(theta);
129
- double beta = (1 - cosw) / 2;
130
-
131
- double b0 = beta;
132
- double b1 = 2 * beta;
133
- double b2 = beta;
134
-
135
- double a0 = 1 + alpha;
136
- double a1 = -2 * cosw;
137
- double a2 = 1 - alpha;
138
-
139
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
140
- } else {
141
- // When cutoff is zero, nothing gets through the filter, so set
142
- // coefficients up correctly.
143
- return normalizeCoefficients(0, 0, 0, 1, 0, 0);
144
- }
145
- }
146
-
147
- BiquadCoefficients calculateHighpassCoefficients(
148
- double cutoff,
149
- double resonance) {
150
- // Limit cutoff to 0 to 1.
151
- cutoff = std::clamp(cutoff, 0.0, 1.0);
152
-
153
- if (cutoff == 1) {
154
- // The z-transform is 0.
155
- return normalizeCoefficients(0, 0, 0, 1, 0, 0);
156
- } else if (cutoff > 0) {
157
- // Compute biquad coefficients for highpass filter
158
-
159
- resonance = pow10(resonance / 20);
160
- double theta = kPiDouble * cutoff;
161
- double alpha = std::sin(theta) / (2 * resonance);
162
- double cosw = std::cos(theta);
163
- double beta = (1 + cosw) / 2;
164
-
165
- double b0 = beta;
166
- double b1 = -2 * beta;
167
- double b2 = beta;
168
-
169
- double a0 = 1 + alpha;
170
- double a1 = -2 * cosw;
171
- double a2 = 1 - alpha;
172
-
173
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
174
- } else {
175
- // When cutoff is zero, we need to be careful because the above
176
- // gives a quadratic divided by the same quadratic, with poles
177
- // and zeros on the unit circle in the same place. When cutoff
178
- // is zero, the z-transform is 1.
179
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
180
- }
181
- }
182
-
183
- BiquadCoefficients calculateLowshelfCoefficients(
184
- double frequency,
185
- double db_gain) {
186
- // Clip frequencies to between 0 and 1, inclusive.
187
- frequency = std::clamp(frequency, 0.0, 1.0);
188
-
189
- double a = pow10(db_gain / 40);
190
-
191
- if (frequency == 1) {
192
- // The z-transform is a constant gain.
193
- return normalizeCoefficients(a * a, 0, 0, 1, 0, 0);
194
- } else if (frequency > 0) {
195
- double w0 = kPiDouble * frequency;
196
- double s = 1; // filter slope (1 is max value)
197
- double alpha = 0.5 * std::sin(w0) * sqrt((a + 1 / a) * (1 / s - 1) + 2);
198
- double k = std::cos(w0);
199
- double k2 = 2 * sqrt(a) * alpha;
200
- double a_plus_one = a + 1;
201
- double a_minus_one = a - 1;
202
-
203
- double b0 = a * (a_plus_one - a_minus_one * k + k2);
204
- double b1 = 2 * a * (a_minus_one - a_plus_one * k);
205
- double b2 = a * (a_plus_one - a_minus_one * k - k2);
206
- double a0 = a_plus_one + a_minus_one * k + k2;
207
- double a1 = -2 * (a_minus_one + a_plus_one * k);
208
- double a2 = a_plus_one + a_minus_one * k - k2;
209
-
210
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
211
- } else {
212
- // When frequency is 0, the z-transform is 1.
213
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
214
- }
215
- }
216
-
217
- BiquadCoefficients calculateHighshelfCoefficients(
218
- double frequency,
219
- double db_gain) {
220
- // Clip frequencies to between 0 and 1, inclusive.
221
- frequency = std::clamp(frequency, 0.0, 1.0);
222
-
223
- double a = pow10(db_gain / 40);
224
-
225
- if (frequency == 1) {
226
- // The z-transform is 1.
227
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
228
- } else if (frequency > 0) {
229
- double w0 = kPiDouble * frequency;
230
- double s = 1; // filter slope (1 is max value)
231
- double alpha = 0.5 * std::sin(w0) * sqrt((a + 1 / a) * (1 / s - 1) + 2);
232
- double k = std::cos(w0);
233
- double k2 = 2 * sqrt(a) * alpha;
234
- double a_plus_one = a + 1;
235
- double a_minus_one = a - 1;
236
-
237
- double b0 = a * (a_plus_one + a_minus_one * k + k2);
238
- double b1 = -2 * a * (a_minus_one + a_plus_one * k);
239
- double b2 = a * (a_plus_one + a_minus_one * k - k2);
240
- double a0 = a_plus_one - a_minus_one * k + k2;
241
- double a1 = 2 * (a_minus_one - a_plus_one * k);
242
- double a2 = a_plus_one - a_minus_one * k - k2;
243
-
244
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
245
- } else {
246
- // When frequency = 0, the filter is just a gain, A^2.
247
- return normalizeCoefficients(a * a, 0, 0, 1, 0, 0);
248
- }
249
- }
250
-
251
- BiquadCoefficients
252
- calculatePeakingCoefficients(double frequency, double q, double db_gain) {
253
- // Clip frequencies to between 0 and 1, inclusive.
254
- frequency = std::clamp(frequency, 0.0, 1.0);
255
-
256
- // Don't let Q go negative, which causes an unstable filter.
257
- q = std::max(0.0, q);
258
-
259
- double a = pow10(db_gain / 40);
260
-
261
- if (frequency > 0 && frequency < 1) {
262
- if (q > 0) {
263
- double w0 = kPiDouble * frequency;
264
- double alpha = std::sin(w0) / (2 * q);
265
- double k = std::cos(w0);
266
-
267
- double b0 = 1 + alpha * a;
268
- double b1 = -2 * k;
269
- double b2 = 1 - alpha * a;
270
- double a0 = 1 + alpha / a;
271
- double a1 = -2 * k;
272
- double a2 = 1 - alpha / a;
273
-
274
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
275
- } else {
276
- // When Q = 0, the above formulas have problems. If we look at
277
- // the z-transform, we can see that the limit as Q->0 is A^2, so
278
- // set the filter that way.
279
- return normalizeCoefficients(a * a, 0, 0, 1, 0, 0);
280
- }
281
- } else {
282
- // When frequency is 0 or 1, the z-transform is 1.
283
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
284
- }
285
- }
286
-
287
- BiquadCoefficients calculateAllpassCoefficients(double frequency, double q) {
288
- // Clip frequencies to between 0 and 1, inclusive.
289
- frequency = std::clamp(frequency, 0.0, 1.0);
290
-
291
- // Don't let Q go negative, which causes an unstable filter.
292
- q = std::max(0.0, q);
293
-
294
- if (frequency > 0 && frequency < 1) {
295
- if (q > 0) {
296
- double w0 = kPiDouble * frequency;
297
- double alpha = std::sin(w0) / (2 * q);
298
- double k = std::cos(w0);
299
-
300
- double b0 = 1 - alpha;
301
- double b1 = -2 * k;
302
- double b2 = 1 + alpha;
303
- double a0 = 1 + alpha;
304
- double a1 = -2 * k;
305
- double a2 = 1 - alpha;
306
-
307
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
308
- } else {
309
- // When Q = 0, the above formulas have problems. If we look at
310
- // the z-transform, we can see that the limit as Q->0 is -1, so
311
- // set the filter that way.
312
- return normalizeCoefficients(-1, 0, 0, 1, 0, 0);
313
- }
314
- } else {
315
- // When frequency is 0 or 1, the z-transform is 1.
316
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
317
- }
318
- }
319
-
320
- BiquadCoefficients calculateNotchCoefficients(double frequency, double q) {
321
- // Clip frequencies to between 0 and 1, inclusive.
322
- frequency = std::clamp(frequency, 0.0, 1.0);
323
-
324
- // Don't let Q go negative, which causes an unstable filter.
325
- q = std::max(0.0, q);
326
-
327
- if (frequency > 0 && frequency < 1) {
328
- if (q > 0) {
329
- double w0 = kPiDouble * frequency;
330
- double alpha = std::sin(w0) / (2 * q);
331
- double k = std::cos(w0);
332
-
333
- double b0 = 1;
334
- double b1 = -2 * k;
335
- double b2 = 1;
336
- double a0 = 1 + alpha;
337
- double a1 = -2 * k;
338
- double a2 = 1 - alpha;
339
-
340
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
341
- } else {
342
- // When Q = 0, the above formulas have problems. If we look at
343
- // the z-transform, we can see that the limit as Q->0 is 0, so
344
- // set the filter that way.
345
- return normalizeCoefficients(0, 0, 0, 1, 0, 0);
346
- }
347
- } else {
348
- // When frequency is 0 or 1, the z-transform is 1.
349
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
350
- }
351
- }
352
-
353
- BiquadCoefficients calculateBandpassCoefficients(double frequency, double q) {
354
- // No negative frequencies allowed.
355
- frequency = std::max(0.0, frequency);
356
-
357
- // Don't let Q go negative, which causes an unstable filter.
358
- q = std::max(0.0, q);
359
-
360
- if (frequency > 0 && frequency < 1) {
361
- double w0 = kPiDouble * frequency;
362
- if (q > 0) {
363
- double alpha = std::sin(w0) / (2 * q);
364
- double k = std::cos(w0);
365
-
366
- double b0 = alpha;
367
- double b1 = 0;
368
- double b2 = -alpha;
369
- double a0 = 1 + alpha;
370
- double a1 = -2 * k;
371
- double a2 = 1 - alpha;
372
-
373
- return normalizeCoefficients(b0, b1, b2, a0, a1, a2);
374
- } else {
375
- // When Q = 0, the above formulas have problems. If we look at
376
- // the z-transform, we can see that the limit as Q->0 is 1, so
377
- // set the filter that way.
378
- return normalizeCoefficients(1, 0, 0, 1, 0, 0);
379
- }
380
- } else {
381
- // When the cutoff is zero, the z-transform approaches 0, if Q
382
- // > 0. When both Q and cutoff are zero, the z-transform is
383
- // pretty much undefined. What should we do in this case?
384
- // For now, just make the filter 0. When the cutoff is 1, the
385
- // z-transform also approaches 0.
386
- return normalizeCoefficients(0, 0, 0, 1, 0, 0);
387
- }
388
- }
389
- } // namespace audioapi
@@ -1,64 +0,0 @@
1
- /*
2
- * Copyright (C) 2010 Google Inc. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions
6
- * are met:
7
- *
8
- * 1. Redistributions of source code must retain the above copyright
9
- * notice, this list of conditions and the following disclaimer.
10
- * 2. Redistributions in binary form must reproduce the above copyright
11
- * notice, this list of conditions and the following disclaimer in the
12
- * documentation and/or other materials provided with the distribution.
13
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14
- * its contributors may be used to endorse or promote products derived
15
- * from this software without specific prior written permission.
16
- *
17
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- */
28
-
29
- #pragma once
30
-
31
- #include <numbers>
32
- #include <span>
33
-
34
- namespace audioapi {
35
-
36
- constexpr double kPiDouble = std::numbers::pi_v<double>;
37
-
38
- struct BiquadCoefficients {
39
- double b0;
40
- double b1;
41
- double b2;
42
- double a1;
43
- double a2;
44
- };
45
-
46
- void getFrequencyResponse(
47
- const BiquadCoefficients &coeffs,
48
- std::span<const float> frequency,
49
- std::span<float> mag_response,
50
- std::span<float> phase_response,
51
- float nyquistFrequency);
52
-
53
- BiquadCoefficients normalizeCoefficients(double b0, double b1, double b2, double a0, double a1, double a2);
54
-
55
- BiquadCoefficients calculateLowpassCoefficients(double cutoff, double Q);
56
- BiquadCoefficients calculateHighpassCoefficients(double cutoff, double Q);
57
- BiquadCoefficients calculateBandpassCoefficients(double frequency, double Q);
58
- BiquadCoefficients calculateNotchCoefficients(double frequency, double Q);
59
- BiquadCoefficients calculateAllpassCoefficients(double frequency, double Q);
60
- BiquadCoefficients calculatePeakingCoefficients(double frequency, double Q, double db_gain);
61
- BiquadCoefficients calculateLowshelfCoefficients(double frequency, double db_gain);
62
- BiquadCoefficients calculateHighshelfCoefficients(double frequency, double db_gain);
63
-
64
- } // namespace audioapi