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.
- package/android/src/main/cpp/audioapi/android/core/{AudioDecoder.cpp → utils/AudioDecoder.cpp} +79 -75
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +124 -43
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +1 -101
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +0 -3
- package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.cpp +133 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.h +28 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +58 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.h +26 -0
- package/common/cpp/audioapi/core/AudioContext.cpp +0 -2
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +0 -35
- package/common/cpp/audioapi/core/BaseAudioContext.h +4 -12
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +0 -2
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +0 -4
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +0 -1
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +0 -2
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +0 -4
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +0 -1
- package/common/cpp/audioapi/core/types/AudioFormat.h +16 -0
- package/common/cpp/audioapi/core/utils/AudioDecoder.h +36 -91
- package/common/cpp/audioapi/core/utils/AudioStretcher.cpp +75 -0
- package/common/cpp/audioapi/core/utils/AudioStretcher.h +30 -0
- package/common/cpp/audioapi/core/utils/Constants.h +4 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +5 -1
- package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +241 -282
- package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h +57 -19
- package/common/cpp/test/CMakeLists.txt +1 -1
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +160 -0
- package/lib/commonjs/api.js +21 -1
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioDecoder.js +48 -0
- package/lib/commonjs/core/AudioDecoder.js.map +1 -0
- package/lib/commonjs/core/AudioStretcher.js +31 -0
- package/lib/commonjs/core/AudioStretcher.js.map +1 -0
- package/lib/commonjs/core/BaseAudioContext.js +11 -18
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/module/api.js +3 -1
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioDecoder.js +42 -0
- package/lib/module/core/AudioDecoder.js.map +1 -0
- package/lib/module/core/AudioStretcher.js +26 -0
- package/lib/module/core/AudioStretcher.js.map +1 -0
- package/lib/module/core/BaseAudioContext.js +11 -18
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/typescript/api.d.ts +5 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioDecoder.d.ts +4 -0
- package/lib/typescript/core/AudioDecoder.d.ts.map +1 -0
- package/lib/typescript/core/AudioStretcher.d.ts +3 -0
- package/lib/typescript/core/AudioStretcher.d.ts.map +1 -0
- package/lib/typescript/core/BaseAudioContext.d.ts +3 -6
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +10 -3
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api.ts +10 -0
- package/src/core/AudioDecoder.ts +78 -0
- package/src/core/AudioStretcher.ts +43 -0
- package/src/core/BaseAudioContext.ts +26 -29
- package/src/interfaces.ts +26 -6
- package/ios/audioapi/ios/core/AudioDecoder.mm +0 -156
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#include <audioapi/core/sources/AudioBuffer.h>
|
|
2
|
+
#include <audioapi/core/utils/AudioStretcher.h>
|
|
3
|
+
#include <audioapi/core/utils/Constants.h>
|
|
4
|
+
#include <audioapi/libs/audio-stretch/stretch.h>
|
|
5
|
+
#include <audioapi/utils/AudioArray.h>
|
|
6
|
+
#include <audioapi/utils/AudioBus.h>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
|
|
9
|
+
namespace audioapi {
|
|
10
|
+
|
|
11
|
+
std::vector<int16_t> AudioStretcher::castToInt16Buffer(AudioBuffer &buffer) {
|
|
12
|
+
const size_t numChannels = buffer.getNumberOfChannels();
|
|
13
|
+
const size_t numFrames = buffer.getLength();
|
|
14
|
+
|
|
15
|
+
std::vector<int16_t> int16Buffer(numFrames * numChannels);
|
|
16
|
+
|
|
17
|
+
for (size_t ch = 0; ch < numChannels; ++ch) {
|
|
18
|
+
const float *channelData = buffer.getChannelData(ch);
|
|
19
|
+
for (size_t i = 0; i < numFrames; ++i) {
|
|
20
|
+
int16Buffer[i * numChannels + ch] = floatToInt16(channelData[i]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return int16Buffer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
std::shared_ptr<AudioBuffer> AudioStretcher::changePlaybackSpeed(
|
|
28
|
+
AudioBuffer buffer,
|
|
29
|
+
float playbackSpeed) {
|
|
30
|
+
const float sampleRate = buffer.getSampleRate();
|
|
31
|
+
const size_t outputChannels = buffer.getNumberOfChannels();
|
|
32
|
+
const size_t numFrames = buffer.getLength();
|
|
33
|
+
|
|
34
|
+
if (playbackSpeed == 1.0f) {
|
|
35
|
+
return std::make_shared<AudioBuffer>(buffer);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
std::vector<int16_t> int16Buffer = castToInt16Buffer(buffer);
|
|
39
|
+
|
|
40
|
+
auto stretcher = stretch_init(
|
|
41
|
+
static_cast<int>(sampleRate / UPPER_FREQUENCY_LIMIT_DETECTION),
|
|
42
|
+
static_cast<int>(sampleRate / LOWER_FREQUENCY_LIMIT_DETECTION),
|
|
43
|
+
outputChannels,
|
|
44
|
+
0x1);
|
|
45
|
+
|
|
46
|
+
int maxOutputFrames = stretch_output_capacity(
|
|
47
|
+
stretcher, static_cast<int>(numFrames), 1 / playbackSpeed);
|
|
48
|
+
std::vector<int16_t> stretchedBuffer(maxOutputFrames * outputChannels);
|
|
49
|
+
|
|
50
|
+
int outputFrames = stretch_samples(
|
|
51
|
+
stretcher,
|
|
52
|
+
int16Buffer.data(),
|
|
53
|
+
static_cast<int>(numFrames),
|
|
54
|
+
stretchedBuffer.data(),
|
|
55
|
+
1 / playbackSpeed);
|
|
56
|
+
|
|
57
|
+
outputFrames +=
|
|
58
|
+
stretch_flush(stretcher, stretchedBuffer.data() + (outputFrames));
|
|
59
|
+
stretchedBuffer.resize(outputFrames * outputChannels);
|
|
60
|
+
stretch_deinit(stretcher);
|
|
61
|
+
|
|
62
|
+
auto audioBus =
|
|
63
|
+
std::make_shared<AudioBus>(outputFrames, outputChannels, sampleRate);
|
|
64
|
+
|
|
65
|
+
for (int ch = 0; ch < outputChannels; ++ch) {
|
|
66
|
+
auto channelData = audioBus->getChannel(ch)->getData();
|
|
67
|
+
for (int i = 0; i < outputFrames; ++i) {
|
|
68
|
+
channelData[i] = int16ToFloat(stretchedBuffer[i * outputChannels + ch]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return std::make_shared<AudioBuffer>(audioBus);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
namespace audioapi {
|
|
7
|
+
|
|
8
|
+
class AudioBus;
|
|
9
|
+
class AudioBuffer;
|
|
10
|
+
|
|
11
|
+
class AudioStretcher {
|
|
12
|
+
public:
|
|
13
|
+
AudioStretcher() = delete;
|
|
14
|
+
|
|
15
|
+
[[nodiscard]] static std::shared_ptr<AudioBuffer> changePlaybackSpeed(
|
|
16
|
+
AudioBuffer buffer,
|
|
17
|
+
float playbackSpeed);
|
|
18
|
+
|
|
19
|
+
private:
|
|
20
|
+
static std::vector<int16_t> castToInt16Buffer(AudioBuffer &buffer);
|
|
21
|
+
|
|
22
|
+
[[nodiscard]] static inline int16_t floatToInt16(float sample) {
|
|
23
|
+
return static_cast<int16_t>(sample * INT16_MAX);
|
|
24
|
+
}
|
|
25
|
+
[[nodiscard]] static inline float int16ToFloat(int16_t sample) {
|
|
26
|
+
return static_cast<float>(sample) / INT16_MAX;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
} // namespace audioapi
|
|
@@ -10,6 +10,10 @@ namespace audioapi {
|
|
|
10
10
|
static constexpr int RENDER_QUANTUM_SIZE = 128;
|
|
11
11
|
static constexpr size_t MAX_FFT_SIZE = 32768;
|
|
12
12
|
|
|
13
|
+
// stretcher
|
|
14
|
+
static constexpr float UPPER_FREQUENCY_LIMIT_DETECTION = 333.0f;
|
|
15
|
+
static constexpr float LOWER_FREQUENCY_LIMIT_DETECTION = 55.0f;
|
|
16
|
+
|
|
13
17
|
// general
|
|
14
18
|
static constexpr float MOST_POSITIVE_SINGLE_FLOAT = static_cast<float>(std::numeric_limits<float>::max());
|
|
15
19
|
static constexpr float MOST_NEGATIVE_SINGLE_FLOAT = static_cast<float>(std::numeric_limits<float>::lowest());
|
|
@@ -156,8 +156,12 @@ void AudioEventHandlerRegistry::invokeHandlerWithEventBody(
|
|
|
156
156
|
|
|
157
157
|
// In case of debugging this, please increment the hours spent counter
|
|
158
158
|
|
|
159
|
-
// Hours spent on this:
|
|
159
|
+
// Hours spent on this: 8
|
|
160
160
|
try {
|
|
161
|
+
if (!handlerIt->second || !handlerIt->second->isFunction(*runtime_)) {
|
|
162
|
+
// If the handler is not valid, we can skip it
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
161
165
|
jsi::Object eventObject(*runtime_);
|
|
162
166
|
// handle special logic for microphone, because we pass audio buffer which
|
|
163
167
|
// has significant size
|