react-native-audio-api 0.4.17 → 0.4.18
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.
|
@@ -63,7 +63,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
63
63
|
size_t stopFrame = stopTime_ == -1.0
|
|
64
64
|
? std::numeric_limits<size_t>::max()
|
|
65
65
|
: std::max(
|
|
66
|
-
AudioUtils::timeToSampleFrame(stopTime_, sampleRate),
|
|
66
|
+
AudioUtils::timeToSampleFrame(stopTime_, sampleRate), lastFrame);
|
|
67
67
|
|
|
68
68
|
if (isUnscheduled() || isFinished()) {
|
|
69
69
|
startOffset = 0;
|
|
@@ -85,7 +85,10 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
85
85
|
startOffset = std::max(startFrame, firstFrame) - firstFrame > 0
|
|
86
86
|
? std::max(startFrame, firstFrame) - firstFrame
|
|
87
87
|
: 0;
|
|
88
|
-
nonSilentFramesToProcess = std::min(lastFrame, stopFrame) - startFrame;
|
|
88
|
+
nonSilentFramesToProcess = std::max(std::min(lastFrame, stopFrame), startFrame) - startFrame;
|
|
89
|
+
|
|
90
|
+
assert(startOffset < framesToProcess);
|
|
91
|
+
assert(nonSilentFramesToProcess <= framesToProcess);
|
|
89
92
|
processingBus->zero(0, startOffset);
|
|
90
93
|
return;
|
|
91
94
|
}
|
|
@@ -97,6 +100,9 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
97
100
|
if (stopFrame < lastFrame && stopFrame >= firstFrame) {
|
|
98
101
|
startOffset = 0;
|
|
99
102
|
nonSilentFramesToProcess = stopFrame - firstFrame;
|
|
103
|
+
|
|
104
|
+
assert(startOffset < framesToProcess);
|
|
105
|
+
assert(nonSilentFramesToProcess <= framesToProcess);
|
|
100
106
|
processingBus->zero(stopFrame - firstFrame, lastFrame - stopFrame);
|
|
101
107
|
return;
|
|
102
108
|
}
|
|
@@ -16,6 +16,7 @@ typedef void (^RenderAudioBlock)(AudioBufferList *outputBuffer, int numFrames);
|
|
|
16
16
|
@property (nonatomic, assign) float sampleRate;
|
|
17
17
|
@property (nonatomic, assign) bool isRunning;
|
|
18
18
|
@property (nonatomic, strong) AVAudioSourceNodeRenderBlock renderBlock;
|
|
19
|
+
@property (nonatomic, assign) bool isAudioSessionActive;
|
|
19
20
|
|
|
20
21
|
- (instancetype)initWithRenderAudioBlock:(RenderAudioBlock)renderAudio;
|
|
21
22
|
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
self.audioEngine = [[AVAudioEngine alloc] init];
|
|
10
10
|
self.audioEngine.mainMixerNode.outputVolume = 1;
|
|
11
11
|
self.isRunning = true;
|
|
12
|
+
self.isAudioSessionActive = false;
|
|
12
13
|
|
|
13
14
|
[self setupAndInitAudioSession];
|
|
14
15
|
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
self.audioEngine = [[AVAudioEngine alloc] init];
|
|
40
41
|
self.audioEngine.mainMixerNode.outputVolume = 1;
|
|
41
42
|
self.isRunning = true;
|
|
43
|
+
self.isAudioSessionActive = false;
|
|
42
44
|
|
|
43
45
|
[self setupAndInitAudioSession];
|
|
44
46
|
|
|
@@ -87,7 +89,9 @@
|
|
|
87
89
|
[self.audioSession setActive:false error:&error];
|
|
88
90
|
|
|
89
91
|
if (error != nil) {
|
|
90
|
-
@
|
|
92
|
+
NSLog(@"Error while de-activating audio session: %@", [error debugDescription]);
|
|
93
|
+
} else {
|
|
94
|
+
self.isAudioSessionActive = false;
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
|
|
@@ -119,20 +123,52 @@
|
|
|
119
123
|
self.audioSession = [AVAudioSession sharedInstance];
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
AVAudioSessionCategoryOptionAllowAirPlay
|
|
126
|
-
error:&error];
|
|
126
|
+
AVAudioSessionCategory desiredCategory = AVAudioSessionCategoryPlayback;
|
|
127
|
+
AVAudioSessionMode desiredMode = AVAudioSessionModeDefault;
|
|
128
|
+
AVAudioSessionCategoryOptions desiredOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowAirPlay;
|
|
127
129
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
+
if (self.audioSession.category != desiredCategory || self.audioSession.mode != desiredMode || self.audioSession.categoryOptions != desiredOptions) {
|
|
131
|
+
[self.audioSession setCategory:desiredCategory mode:desiredMode options:desiredOptions error:&error];
|
|
132
|
+
|
|
133
|
+
if (error != nil) {
|
|
134
|
+
NSLog(@"Error while configuring audio session: %@", [error debugDescription]);
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
NSLog(@"AVAudioSession category mode and options are valid, skipping configuration");
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
|
|
140
|
+
if (self.sampleRate) {
|
|
141
|
+
if (self.audioSession.preferredSampleRate != self.sampleRate) {
|
|
142
|
+
[self.audioSession setPreferredSampleRate:self.sampleRate error:&error];
|
|
133
143
|
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
if (error != nil) {
|
|
145
|
+
NSLog(@"Error while setting preferred sample rate buffer duration: %@", [error debugDescription]);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
NSLog(@"AVAudioSession preferred sample rate is valid, skipping configuration");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (self.audioSession.preferredIOBufferDuration != 0.02) {
|
|
153
|
+
[self.audioSession setPreferredIOBufferDuration:0.02 error:&error];
|
|
154
|
+
|
|
155
|
+
if (error != nil) {
|
|
156
|
+
NSLog(@"Error while setting preferred IO buffer duration: %@", [error debugDescription]);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
NSLog(@"AVAudioSession preferred IO buffer duration is valid, skipping configuration");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!self.isAudioSessionActive) {
|
|
163
|
+
[self.audioSession setActive:true error:&error];
|
|
164
|
+
|
|
165
|
+
if (error != nil) {
|
|
166
|
+
NSLog(@"Error while activating audio session: %@", [error debugDescription]);
|
|
167
|
+
} else {
|
|
168
|
+
self.isAudioSessionActive = true;
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
NSLog(@"AVAudioSession was active, skipping unnecessary activation");
|
|
136
172
|
}
|
|
137
173
|
}
|
|
138
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-audio-api",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
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-custom-wasm": "./scripts/setup-custom-wasm.js"
|