react-native-audio-api 0.9.0 → 0.10.0-nightly-971a6b4-20251010

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 (60) hide show
  1. package/android/src/main/cpp/audioapi/android/core/{AudioDecoder.cpp → utils/AudioDecoder.cpp} +79 -75
  2. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +124 -43
  3. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +1 -101
  4. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +0 -3
  5. package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.cpp +133 -0
  6. package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.h +28 -0
  7. package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +58 -0
  8. package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.h +26 -0
  9. package/common/cpp/audioapi/core/AudioContext.cpp +0 -2
  10. package/common/cpp/audioapi/core/BaseAudioContext.cpp +0 -35
  11. package/common/cpp/audioapi/core/BaseAudioContext.h +4 -12
  12. package/common/cpp/audioapi/core/OfflineAudioContext.cpp +0 -2
  13. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +0 -4
  14. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +0 -1
  15. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +0 -2
  16. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +0 -4
  17. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +0 -1
  18. package/common/cpp/audioapi/core/types/AudioFormat.h +16 -0
  19. package/common/cpp/audioapi/core/utils/AudioDecoder.h +36 -91
  20. package/common/cpp/audioapi/core/utils/AudioStretcher.cpp +75 -0
  21. package/common/cpp/audioapi/core/utils/AudioStretcher.h +30 -0
  22. package/common/cpp/audioapi/core/utils/Constants.h +4 -0
  23. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +5 -1
  24. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +241 -282
  25. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h +57 -19
  26. package/common/cpp/test/CMakeLists.txt +1 -1
  27. package/ios/audioapi/ios/core/utils/AudioDecoder.mm +160 -0
  28. package/lib/commonjs/api.js +21 -1
  29. package/lib/commonjs/api.js.map +1 -1
  30. package/lib/commonjs/core/AudioDecoder.js +48 -0
  31. package/lib/commonjs/core/AudioDecoder.js.map +1 -0
  32. package/lib/commonjs/core/AudioStretcher.js +31 -0
  33. package/lib/commonjs/core/AudioStretcher.js.map +1 -0
  34. package/lib/commonjs/core/BaseAudioContext.js +11 -18
  35. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  36. package/lib/module/api.js +3 -1
  37. package/lib/module/api.js.map +1 -1
  38. package/lib/module/core/AudioDecoder.js +42 -0
  39. package/lib/module/core/AudioDecoder.js.map +1 -0
  40. package/lib/module/core/AudioStretcher.js +26 -0
  41. package/lib/module/core/AudioStretcher.js.map +1 -0
  42. package/lib/module/core/BaseAudioContext.js +11 -18
  43. package/lib/module/core/BaseAudioContext.js.map +1 -1
  44. package/lib/typescript/api.d.ts +5 -1
  45. package/lib/typescript/api.d.ts.map +1 -1
  46. package/lib/typescript/core/AudioDecoder.d.ts +4 -0
  47. package/lib/typescript/core/AudioDecoder.d.ts.map +1 -0
  48. package/lib/typescript/core/AudioStretcher.d.ts +3 -0
  49. package/lib/typescript/core/AudioStretcher.d.ts.map +1 -0
  50. package/lib/typescript/core/BaseAudioContext.d.ts +3 -6
  51. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  52. package/lib/typescript/interfaces.d.ts +10 -3
  53. package/lib/typescript/interfaces.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/api.ts +10 -0
  56. package/src/core/AudioDecoder.ts +78 -0
  57. package/src/core/AudioStretcher.ts +43 -0
  58. package/src/core/BaseAudioContext.ts +26 -29
  59. package/src/interfaces.ts +26 -6
  60. package/ios/audioapi/ios/core/AudioDecoder.mm +0 -156
@@ -1,156 +0,0 @@
1
- #define MINIAUDIO_IMPLEMENTATION
2
- #import <audioapi/libs/miniaudio/miniaudio.h>
3
-
4
- #include <audioapi/libs/miniaudio/decoders/libopus/miniaudio_libopus.h>
5
- #include <audioapi/libs/miniaudio/decoders/libvorbis/miniaudio_libvorbis.h>
6
-
7
- #include <audioapi/core/utils/AudioDecoder.h>
8
- #include <audioapi/dsp/VectorMath.h>
9
- #include <audioapi/libs/audio-stretch/stretch.h>
10
- #include <audioapi/libs/base64/base64.h>
11
- #include <audioapi/libs/ffmpeg/FFmpegDecoding.h>
12
- #include <audioapi/utils/AudioArray.h>
13
- #include <audioapi/utils/AudioBus.h>
14
-
15
- namespace audioapi {
16
-
17
- // Decoding audio in fixed-size chunks because total frame count can't be
18
- // determined in advance. Note: ma_decoder_get_length_in_pcm_frames() always
19
- // returns 0 for Vorbis decoders.
20
- std::vector<int16_t> AudioDecoder::readAllPcmFrames(ma_decoder &decoder, int numChannels, ma_uint64 &outFramesRead)
21
- {
22
- std::vector<int16_t> buffer;
23
- std::vector<int16_t> temp(CHUNK_SIZE * numChannels);
24
- outFramesRead = 0;
25
-
26
- while (true) {
27
- ma_uint64 tempFramesDecoded = 0;
28
- ma_decoder_read_pcm_frames(&decoder, temp.data(), CHUNK_SIZE, &tempFramesDecoded);
29
- if (tempFramesDecoded == 0) {
30
- break;
31
- }
32
-
33
- buffer.insert(buffer.end(), temp.data(), temp.data() + tempFramesDecoded * numChannels);
34
- outFramesRead += tempFramesDecoded;
35
- }
36
-
37
- return buffer;
38
- }
39
-
40
- std::shared_ptr<AudioBus>
41
- AudioDecoder::makeAudioBusFromInt16Buffer(const std::vector<int16_t> &buffer, int numChannels, float sampleRate)
42
- {
43
- auto outputFrames = buffer.size() / numChannels;
44
- auto audioBus = std::make_shared<AudioBus>(outputFrames, numChannels, sampleRate);
45
-
46
- for (int ch = 0; ch < numChannels; ++ch) {
47
- auto channelData = audioBus->getChannel(ch)->getData();
48
- for (int i = 0; i < outputFrames; ++i) {
49
- channelData[i] = int16ToFloat(buffer[i * numChannels + ch]);
50
- }
51
- }
52
- return audioBus;
53
- }
54
-
55
- std::shared_ptr<AudioBus> AudioDecoder::decodeWithFilePath(const std::string &path) const
56
- {
57
- std::vector<int16_t> buffer;
58
- if (AudioDecoder::pathHasExtension(path, {".mp4", ".m4a", ".aac"})) {
59
- buffer = ffmpegdecoding::decodeWithFilePath(path, numChannels_, static_cast<int>(sampleRate_));
60
- if (buffer.empty()) {
61
- NSLog(@"Failed to decode with FFmpeg: %s", path.c_str());
62
- return nullptr;
63
- }
64
- return makeAudioBusFromInt16Buffer(buffer, numChannels_, sampleRate_);
65
- }
66
- ma_decoding_backend_vtable *customBackends[] = {ma_decoding_backend_libvorbis, ma_decoding_backend_libopus};
67
-
68
- ma_decoder decoder;
69
- ma_decoder_config config = ma_decoder_config_init(ma_format_s16, numChannels_, static_cast<int>(sampleRate_));
70
- config.ppCustomBackendVTables = customBackends;
71
- config.customBackendCount = sizeof(customBackends) / sizeof(customBackends[0]);
72
-
73
- if (ma_decoder_init_file(path.c_str(), &config, &decoder) != MA_SUCCESS) {
74
- NSLog(@"Failed to initialize decoder for file: %s", path.c_str());
75
- ma_decoder_uninit(&decoder);
76
- return nullptr;
77
- }
78
-
79
- ma_uint64 framesRead = 0;
80
- buffer = readAllPcmFrames(decoder, numChannels_, framesRead);
81
- if (framesRead == 0) {
82
- NSLog(@"Failed to decode");
83
- ma_decoder_uninit(&decoder);
84
- return nullptr;
85
- }
86
-
87
- ma_decoder_uninit(&decoder);
88
- return makeAudioBusFromInt16Buffer(buffer, numChannels_, sampleRate_);
89
- }
90
-
91
- std::shared_ptr<AudioBus> AudioDecoder::decodeWithMemoryBlock(const void *data, size_t size) const
92
- {
93
- std::vector<int16_t> buffer;
94
- const AudioFormat format = AudioDecoder::detectAudioFormat(data, size);
95
- if (format == AudioFormat::MP4 || format == AudioFormat::M4A || format == AudioFormat::AAC) {
96
- buffer = ffmpegdecoding::decodeWithMemoryBlock(data, size, numChannels_, static_cast<int>(sampleRate_));
97
- if (buffer.empty()) {
98
- NSLog(@"Failed to decode with FFmpeg");
99
- return nullptr;
100
- }
101
- return makeAudioBusFromInt16Buffer(buffer, numChannels_, sampleRate_);
102
- }
103
- ma_decoding_backend_vtable *customBackends[] = {ma_decoding_backend_libvorbis, ma_decoding_backend_libopus};
104
-
105
- ma_decoder decoder;
106
- ma_decoder_config config = ma_decoder_config_init(ma_format_s16, numChannels_, static_cast<int>(sampleRate_));
107
- config.ppCustomBackendVTables = customBackends;
108
- config.customBackendCount = sizeof(customBackends) / sizeof(customBackends[0]);
109
-
110
- if (ma_decoder_init_memory(data, size, &config, &decoder) != MA_SUCCESS) {
111
- NSLog(@"Failed to initialize decoder for memory block");
112
- ma_decoder_uninit(&decoder);
113
- return nullptr;
114
- }
115
-
116
- ma_uint64 framesRead = 0;
117
- buffer = readAllPcmFrames(decoder, numChannels_, framesRead);
118
- if (framesRead == 0) {
119
- NSLog(@"Failed to decode");
120
- ma_decoder_uninit(&decoder);
121
- return nullptr;
122
- }
123
-
124
- ma_decoder_uninit(&decoder);
125
- return makeAudioBusFromInt16Buffer(buffer, numChannels_, sampleRate_);
126
- }
127
-
128
- std::shared_ptr<AudioBus> AudioDecoder::decodeWithPCMInBase64(const std::string &data, float playbackSpeed) const
129
- {
130
- auto decodedData = base64_decode(data, false);
131
-
132
- const auto uint8Data = reinterpret_cast<uint8_t *>(decodedData.data());
133
- size_t framesDecoded = decodedData.size() / 2;
134
-
135
- std::vector<int16_t> buffer(framesDecoded);
136
- for (size_t i = 0; i < framesDecoded; ++i) {
137
- buffer[i] = static_cast<int16_t>((uint8Data[i * 2 + 1] << 8) | uint8Data[i * 2]);
138
- }
139
-
140
- changePlaybackSpeedIfNeeded(buffer, framesDecoded, 1, playbackSpeed);
141
- auto outputFrames = buffer.size();
142
-
143
- auto audioBus = std::make_shared<AudioBus>(outputFrames, numChannels_, sampleRate_);
144
- auto leftChannelData = audioBus->getChannel(0)->getData();
145
- auto rightChannelData = audioBus->getChannel(1)->getData();
146
-
147
- for (size_t i = 0; i < outputFrames; ++i) {
148
- auto sample = int16ToFloat(buffer[i]);
149
- leftChannelData[i] = sample;
150
- rightChannelData[i] = sample;
151
- }
152
-
153
- return audioBus;
154
- }
155
-
156
- } // namespace audioapi