react-native-audio-api 0.10.0 → 0.10.1
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/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +3 -3
- package/common/cpp/test/src/AudioParamTest.cpp +1 -1
- package/common/cpp/test/src/AudioScheduledSourceTest.cpp +134 -0
- package/common/cpp/test/src/ConstantSourceTest.cpp +1 -1
- package/common/cpp/test/src/GainTest.cpp +1 -1
- package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +4 -4
- package/common/cpp/test/src/OscillatorTest.cpp +1 -1
- package/common/cpp/test/src/StereoPannerTest.cpp +1 -1
- package/common/cpp/test/src/biquad/BiquadFilterTest.h +1 -1
- package/package.json +8 -2
|
@@ -71,7 +71,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
71
71
|
auto sampleRate = context_->getSampleRate();
|
|
72
72
|
|
|
73
73
|
size_t firstFrame = context_->getCurrentSampleFrame();
|
|
74
|
-
size_t lastFrame = firstFrame + framesToProcess;
|
|
74
|
+
size_t lastFrame = firstFrame + framesToProcess - 1;
|
|
75
75
|
|
|
76
76
|
size_t startFrame =
|
|
77
77
|
std::max(dsp::timeToSampleFrame(startTime_, sampleRate), firstFrame);
|
|
@@ -100,7 +100,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
100
100
|
? std::max(startFrame, firstFrame) - firstFrame
|
|
101
101
|
: 0;
|
|
102
102
|
nonSilentFramesToProcess =
|
|
103
|
-
std::max(std::min(lastFrame, stopFrame), startFrame) - startFrame;
|
|
103
|
+
std::max(std::min(lastFrame, stopFrame) + 1, startFrame) - startFrame;
|
|
104
104
|
|
|
105
105
|
assert(startOffset <= framesToProcess);
|
|
106
106
|
assert(nonSilentFramesToProcess <= framesToProcess);
|
|
@@ -119,7 +119,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
119
119
|
|
|
120
120
|
// stop will happen in this render quantum
|
|
121
121
|
// zero remaining frames after stop frame
|
|
122
|
-
if (stopFrame
|
|
122
|
+
if (stopFrame <= lastFrame && stopFrame >= firstFrame) {
|
|
123
123
|
playbackState_ = PlaybackState::STOP_SCHEDULED;
|
|
124
124
|
startOffset = 0;
|
|
125
125
|
nonSilentFramesToProcess = stopFrame - firstFrame;
|
|
@@ -8,7 +8,7 @@ using namespace audioapi;
|
|
|
8
8
|
|
|
9
9
|
class AudioParamTest : public ::testing::Test {
|
|
10
10
|
protected:
|
|
11
|
-
std::shared_ptr<
|
|
11
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
12
12
|
std::unique_ptr<OfflineAudioContext> context;
|
|
13
13
|
static constexpr int sampleRate = 44100;
|
|
14
14
|
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#include <audioapi/core/OfflineAudioContext.h>
|
|
2
|
+
#include <audioapi/core/destinations/AudioDestinationNode.h>
|
|
3
|
+
#include <audioapi/core/sources/AudioScheduledSourceNode.h>
|
|
4
|
+
#include <audioapi/core/utils/worklets/SafeIncludes.h>
|
|
5
|
+
#include <audioapi/utils/AudioBus.h>
|
|
6
|
+
#include <gtest/gtest.h>
|
|
7
|
+
#include <test/src/MockAudioEventHandlerRegistry.h>
|
|
8
|
+
|
|
9
|
+
using namespace audioapi;
|
|
10
|
+
static constexpr int SAMPLE_RATE = 44100;
|
|
11
|
+
static constexpr int RENDER_QUANTUM = 128;
|
|
12
|
+
static constexpr double RENDER_QUANTUM_TIME =
|
|
13
|
+
static_cast<double>(RENDER_QUANTUM) / SAMPLE_RATE;
|
|
14
|
+
|
|
15
|
+
class AudioScheduledSourceTest : public ::testing::Test {
|
|
16
|
+
protected:
|
|
17
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
18
|
+
std::unique_ptr<OfflineAudioContext> context;
|
|
19
|
+
|
|
20
|
+
void SetUp() override {
|
|
21
|
+
eventRegistry = std::make_shared<MockAudioEventHandlerRegistry>();
|
|
22
|
+
context = std::make_unique<OfflineAudioContext>(
|
|
23
|
+
2, 5 * SAMPLE_RATE, SAMPLE_RATE, eventRegistry, RuntimeRegistry{});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
class TestableAudioScheduledSourceNode : public AudioScheduledSourceNode {
|
|
28
|
+
public:
|
|
29
|
+
explicit TestableAudioScheduledSourceNode(BaseAudioContext *context)
|
|
30
|
+
: AudioScheduledSourceNode(context) {
|
|
31
|
+
isInitialized_ = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void updatePlaybackInfo(
|
|
35
|
+
const std::shared_ptr<AudioBus> &processingBus,
|
|
36
|
+
int framesToProcess,
|
|
37
|
+
size_t &startOffset,
|
|
38
|
+
size_t &nonSilentFramesToProcess) {
|
|
39
|
+
AudioScheduledSourceNode::updatePlaybackInfo(
|
|
40
|
+
processingBus, framesToProcess, startOffset, nonSilentFramesToProcess);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus> &, int)
|
|
44
|
+
override {
|
|
45
|
+
return nullptr;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
PlaybackState getPlaybackState() const {
|
|
49
|
+
return playbackState_;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void playFrames(int frames) {
|
|
53
|
+
size_t startOffset = 0;
|
|
54
|
+
size_t nonSilentFramesToProcess = 0;
|
|
55
|
+
auto processingBus =
|
|
56
|
+
std::make_shared<AudioBus>(128, 2, static_cast<float>(SAMPLE_RATE));
|
|
57
|
+
updatePlaybackInfo(
|
|
58
|
+
processingBus, frames, startOffset, nonSilentFramesToProcess);
|
|
59
|
+
context_->getDestination()->renderAudio(processingBus, frames);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
TEST_F(AudioScheduledSourceTest, IsUnscheduledStateSetCorrectly) {
|
|
64
|
+
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
65
|
+
EXPECT_EQ(
|
|
66
|
+
sourceNode.getPlaybackState(),
|
|
67
|
+
AudioScheduledSourceNode::PlaybackState::UNSCHEDULED);
|
|
68
|
+
|
|
69
|
+
sourceNode.start(RENDER_QUANTUM_TIME);
|
|
70
|
+
EXPECT_NE(
|
|
71
|
+
sourceNode.getPlaybackState(),
|
|
72
|
+
AudioScheduledSourceNode::PlaybackState::UNSCHEDULED);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
TEST_F(AudioScheduledSourceTest, IsScheduledStateSetCorrectly) {
|
|
76
|
+
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
77
|
+
sourceNode.start(RENDER_QUANTUM_TIME);
|
|
78
|
+
EXPECT_EQ(
|
|
79
|
+
sourceNode.getPlaybackState(),
|
|
80
|
+
AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
81
|
+
|
|
82
|
+
sourceNode.playFrames(RENDER_QUANTUM);
|
|
83
|
+
EXPECT_EQ(
|
|
84
|
+
sourceNode.getPlaybackState(),
|
|
85
|
+
AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
86
|
+
|
|
87
|
+
sourceNode.playFrames(1);
|
|
88
|
+
EXPECT_NE(
|
|
89
|
+
sourceNode.getPlaybackState(),
|
|
90
|
+
AudioScheduledSourceNode::PlaybackState::SCHEDULED);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
TEST_F(AudioScheduledSourceTest, IsPlayingStateSetCorrectly) {
|
|
94
|
+
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
95
|
+
sourceNode.start(0);
|
|
96
|
+
sourceNode.stop(RENDER_QUANTUM_TIME);
|
|
97
|
+
|
|
98
|
+
sourceNode.playFrames(RENDER_QUANTUM);
|
|
99
|
+
EXPECT_EQ(
|
|
100
|
+
sourceNode.getPlaybackState(),
|
|
101
|
+
AudioScheduledSourceNode::PlaybackState::PLAYING);
|
|
102
|
+
|
|
103
|
+
sourceNode.playFrames(1);
|
|
104
|
+
EXPECT_NE(
|
|
105
|
+
sourceNode.getPlaybackState(),
|
|
106
|
+
AudioScheduledSourceNode::PlaybackState::PLAYING);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
TEST_F(AudioScheduledSourceTest, IsStopScheduledStateSetCorrectly) {
|
|
110
|
+
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
111
|
+
sourceNode.start(0);
|
|
112
|
+
sourceNode.stop(RENDER_QUANTUM_TIME);
|
|
113
|
+
sourceNode.playFrames(1); // start playing
|
|
114
|
+
sourceNode.playFrames(RENDER_QUANTUM);
|
|
115
|
+
EXPECT_EQ(
|
|
116
|
+
sourceNode.getPlaybackState(),
|
|
117
|
+
AudioScheduledSourceNode::PlaybackState::STOP_SCHEDULED);
|
|
118
|
+
|
|
119
|
+
sourceNode.playFrames(1);
|
|
120
|
+
EXPECT_NE(
|
|
121
|
+
sourceNode.getPlaybackState(),
|
|
122
|
+
AudioScheduledSourceNode::PlaybackState::STOP_SCHEDULED);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
TEST_F(AudioScheduledSourceTest, IsFinishedStateSetCorrectly) {
|
|
126
|
+
auto sourceNode = TestableAudioScheduledSourceNode(context.get());
|
|
127
|
+
sourceNode.start(0);
|
|
128
|
+
sourceNode.stop(RENDER_QUANTUM_TIME);
|
|
129
|
+
sourceNode.playFrames(1); // start playing
|
|
130
|
+
|
|
131
|
+
sourceNode.playFrames(RENDER_QUANTUM);
|
|
132
|
+
sourceNode.playFrames(1);
|
|
133
|
+
EXPECT_TRUE(sourceNode.isFinished());
|
|
134
|
+
}
|
|
@@ -10,7 +10,7 @@ using namespace audioapi;
|
|
|
10
10
|
|
|
11
11
|
class ConstantSourceTest : public ::testing::Test {
|
|
12
12
|
protected:
|
|
13
|
-
std::shared_ptr<
|
|
13
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
14
14
|
std::unique_ptr<OfflineAudioContext> context;
|
|
15
15
|
static constexpr int sampleRate = 44100;
|
|
16
16
|
|
|
@@ -10,7 +10,7 @@ using namespace audioapi;
|
|
|
10
10
|
|
|
11
11
|
class GainTest : public ::testing::Test {
|
|
12
12
|
protected:
|
|
13
|
-
std::shared_ptr<
|
|
13
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
14
14
|
std::unique_ptr<OfflineAudioContext> context;
|
|
15
15
|
static constexpr int sampleRate = 44100;
|
|
16
16
|
|
|
@@ -17,8 +17,8 @@ class MockAudioEventHandlerRegistry : public IAudioEventHandlerRegistry {
|
|
|
17
17
|
MOCK_METHOD(void, unregisterHandler,
|
|
18
18
|
(const std::string &eventName, uint64_t listenerId), (override));
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
(const std::string &eventName, const EventMap &body)
|
|
22
|
-
|
|
23
|
-
(const std::string &eventName, uint64_t listenerId, const EventMap &body)
|
|
20
|
+
MOCK_METHOD2(invokeHandlerWithEventBody, void
|
|
21
|
+
(const std::string &eventName, const EventMap &body));
|
|
22
|
+
MOCK_METHOD3(invokeHandlerWithEventBody, void
|
|
23
|
+
(const std::string &eventName, uint64_t listenerId, const EventMap &body));
|
|
24
24
|
};
|
|
@@ -8,7 +8,7 @@ using namespace audioapi;
|
|
|
8
8
|
|
|
9
9
|
class OscillatorTest : public ::testing::Test {
|
|
10
10
|
protected:
|
|
11
|
-
std::shared_ptr<
|
|
11
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
12
12
|
std::unique_ptr<OfflineAudioContext> context;
|
|
13
13
|
static constexpr int sampleRate = 44100;
|
|
14
14
|
|
|
@@ -10,7 +10,7 @@ using namespace audioapi;
|
|
|
10
10
|
|
|
11
11
|
class StereoPannerTest : public ::testing::Test {
|
|
12
12
|
protected:
|
|
13
|
-
std::shared_ptr<
|
|
13
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
14
14
|
std::unique_ptr<OfflineAudioContext> context;
|
|
15
15
|
static constexpr int sampleRate = 44100;
|
|
16
16
|
|
|
@@ -14,7 +14,7 @@ static constexpr float tolerance = 0.0001f;
|
|
|
14
14
|
namespace audioapi {
|
|
15
15
|
class BiquadFilterTest : public ::testing::Test {
|
|
16
16
|
protected:
|
|
17
|
-
std::shared_ptr<
|
|
17
|
+
std::shared_ptr<MockAudioEventHandlerRegistry> eventRegistry;
|
|
18
18
|
std::unique_ptr<OfflineAudioContext> context;
|
|
19
19
|
|
|
20
20
|
void SetUp() override {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-audio-api",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification",
|
|
5
5
|
"bin": {
|
|
6
6
|
"setup-rn-audio-api-web": "./scripts/setup-rn-audio-api-web.js"
|
|
@@ -84,7 +84,12 @@
|
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"react": "*",
|
|
86
86
|
"react-native": "*",
|
|
87
|
-
"react-native-worklets": "
|
|
87
|
+
"react-native-worklets": ">= 0.6.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"react-native-worklets": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
88
93
|
},
|
|
89
94
|
"devDependencies": {
|
|
90
95
|
"@babel/cli": "^7.20.0",
|
|
@@ -107,6 +112,7 @@
|
|
|
107
112
|
"@types/node": "^18.0.0",
|
|
108
113
|
"@types/react": "^19.1.1",
|
|
109
114
|
"@types/react-test-renderer": "^19.1.0",
|
|
115
|
+
"@types/semver": "7.7.1",
|
|
110
116
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
111
117
|
"commitlint": "^17.0.2",
|
|
112
118
|
"del-cli": "^5.1.0",
|