|
1 | 1 | # react-native-tiny-wavpack-decoder |
2 | 2 |
|
3 | | -Tiny WavPack Decoder for React Native |
| 3 | +A lightweight React Native Turbo Module for decoding WavPack audio files to WAV format on iOS and Android. Built with the New Architecture for optimal performance, this module supports progress updates during decoding and is designed for seamless integration into React Native apps. |
| 4 | + |
| 5 | +## Features |
| 6 | +- Decode WavPack (.wv) files to WAV format. |
| 7 | +- Cross-platform support for iOS (13.0+) and Android (API 21+). |
| 8 | +- Progress updates via event emitter for real-time feedback. |
| 9 | +- Configurable decoding options (e.g., max samples, bits per sample. |
| 10 | +- Thread-safe decoding on iOS with concurrent queue support. |
| 11 | + |
| 12 | +## Requirements |
| 13 | +- React Native 0.75 or higher with New Architecture enabled. |
| 14 | +- iOS 13.0 or later. |
| 15 | +- Android API 21 or later. |
| 16 | +- Node.js 16+ for development. |
4 | 17 |
|
5 | 18 | ## Installation |
6 | 19 |
|
7 | | -```sh |
8 | | -npm install react-native-tiny-wavpack-decoder |
9 | | -``` |
| 20 | +1. **Install the package**: |
| 21 | + ```bash |
| 22 | + npm install react-native-tiny-wavpack-decoder |
| 23 | + ``` |
| 24 | + |
| 25 | +2. **Link native dependencies**: |
| 26 | + - For iOS, install CocoaPods dependencies: |
| 27 | + ```bash |
| 28 | + cd ios && pod install |
| 29 | + ``` |
| 30 | + - For Android, the module is auto-linked via React Native. |
| 31 | + |
| 32 | +3. **Enable New Architecture** (if not already enabled): |
| 33 | + - In `ios/Podfile`, ensure: |
| 34 | + ```ruby |
| 35 | + use_react_native!( |
| 36 | + :path => '../node_modules/react-native', |
| 37 | + :new_architecture => true |
| 38 | + ) |
| 39 | + ``` |
| 40 | + - In `android/app/build.gradle`, enable Turbo Modules: |
| 41 | + ```gradle |
| 42 | + newArchEnabled=true |
| 43 | + ``` |
| 44 | + |
| 45 | +4. **Rebuild the app**: |
| 46 | + ```bash |
| 47 | + npx react-native run-ios |
| 48 | + # or |
| 49 | + npx react-native run-android |
| 50 | + ``` |
10 | 51 |
|
11 | 52 | ## Usage |
12 | 53 |
|
| 54 | +### Basic Decoding |
| 55 | +Decode a WavPack file to WAV using the `decode` method. The module requires file paths accessible by the app (e.g., in the document directory). |
13 | 56 |
|
14 | | -```js |
15 | | -import { multiply } from 'react-native-tiny-wavpack-decoder'; |
| 57 | +```typescript |
| 58 | +import TinyWavPackDecoder from 'react-native-tiny-wavpack-decoder'; |
| 59 | +import * as RNFS from '@dr.pogodin/react-native-fs'; |
16 | 60 |
|
17 | | -// ... |
| 61 | +const decodeWavPack = async () => { |
| 62 | + const inputPath = `${RNFS.DocumentDirectoryPath}/sample.wv`; // Ensure file exists |
| 63 | + const outputPath = `${RNFS.DocumentDirectoryPath}/output.wav`; |
18 | 64 |
|
19 | | -const result = multiply(3, 7); |
| 65 | + try { |
| 66 | + const result = await TinyWavPackDecoder.decode(inputPath, outputPath, { |
| 67 | + maxSamples: -1, // Decode all samples |
| 68 | + bitsPerSample: 16, // Output bit depth (8, 16, 24, or 32) |
| 69 | + }); |
| 70 | + console.log('Decode result:', result); // "Success" |
| 71 | + } catch (error) { |
| 72 | + console.error('Decode error:', error.message); |
| 73 | + } |
| 74 | +}; |
20 | 75 | ``` |
21 | 76 |
|
| 77 | +### Progress Updates |
| 78 | +Subscribe to decoding progress events (0.0 to 1.0) using `addProgressListener`. |
22 | 79 |
|
23 | | -## Contributing |
| 80 | +```typescript |
| 81 | +import { useEffect } from 'react'; |
| 82 | +import TinyWavPackDecoder from 'react-native-tiny-wavpack-decoder'; |
24 | 83 |
|
25 | | -See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
| 84 | +const App = () => { |
| 85 | + useEffect(() => { |
| 86 | + const subscription = TinyWavPackDecoder.addProgressListener((progress) => { |
| 87 | + console.log(`Progress: ${(progress * 100).toFixed(2)}%`); |
| 88 | + }); |
| 89 | + return () => { |
| 90 | + subscription.remove(); |
| 91 | + }; |
| 92 | + }, []); |
26 | 93 |
|
27 | | -## License |
| 94 | + // Trigger decodeWavPack() as shown above |
| 95 | +}; |
| 96 | +``` |
| 97 | +
|
| 98 | +### Options |
| 99 | +The `decode` method accepts an options object with the following properties: |
28 | 100 |
|
29 | | -MIT |
| 101 | +| Option | Type | Default | Description | |
| 102 | +|-----------------|--------------------------|---------|-----------------------------------------------------------------------------| |
| 103 | +| `maxSamples` | `number` | `-1` | Maximum number of samples to decode. Use `-1` for all samples. | |
| 104 | +| `bitsPerSample` | `8 | 16 | 24 | 32` | `16` | Output bit depth. Must be 8, 16, 24, or 32. | |
30 | 105 |
|
31 | | ---- |
| 106 | +### Example App |
| 107 | +The `example/` directory contains a sample app demonstrating decoding and progress updates. To run it: |
| 108 | +
|
| 109 | +```bash |
| 110 | +cd example |
| 111 | +npm install |
| 112 | +npm run ios |
| 113 | +# or |
| 114 | +npm run android |
| 115 | +``` |
| 116 | +
|
| 117 | +Place a `sample.wv` file in the app’s document directory (e.g., via `RNFS.DocumentDirectoryPath`). |
| 118 | +
|
| 119 | +## Notes |
| 120 | +- **File Access**: Ensure input and output paths are valid and accessible. Use libraries like `@dr.pogodin/react-native-fs` to manage files. |
| 121 | +- **Thread Safety**: iOS uses a concurrent dispatch queue for decoding, but rapid concurrent calls may require additional thread-safety measures (see Limitations). |
| 122 | +- **Progress Events**: Ensure listeners are set up before starting decoding. |
| 123 | +- **New Architecture**: This module requires Turbo Modules and the New Architecture. Ensure your app is configured accordingly. |
| 124 | +
|
| 125 | +## Limitations |
| 126 | +- The module uses a static `FILE*` in the C code, which may cause crashes if multiple decoding operations are triggered concurrently. A thread-safe version is planned (see [issue #TBD]). |
| 127 | +- Progress updates are tied to the decoding buffer size (4096 samples), which may result in coarse-grained updates for small files. |
| 128 | +- Android performance may vary on low-end devices due to JNI overhead. |
| 129 | +
|
| 130 | +## Contributing |
| 131 | +Contributions are welcome! Please open an issue or pull request on the [GitHub repository](https://github.com/JairajJangle/react-native-tiny-wavpack-decoder) for bugs, features, or improvements. |
| 132 | +
|
| 133 | +## License |
| 134 | +MIT License. See [LICENSE](LICENSE) for details. |
32 | 135 |
|
33 | | -Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
| 136 | +## Acknowledgments |
| 137 | +- Built with [WavPack](https://www.wavpack.com/)'s Tiny Decoder source for efficient audio decoding. |
| 138 | +- Uses React Native’s New Architecture for modern performance. |
0 commit comments