react-native-audio-api 0.4.10-rc.1 → 0.4.10

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.
@@ -9,7 +9,7 @@
9
9
  namespace audioapi {
10
10
 
11
11
  AudioPlayer::AudioPlayer(
12
- const std::function<void(AudioBus *, int)> &renderAudio)
12
+ const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio)
13
13
  : renderAudio_(renderAudio) {
14
14
  AudioStreamBuilder builder;
15
15
 
@@ -29,7 +29,7 @@ AudioPlayer::AudioPlayer(
29
29
  }
30
30
 
31
31
  AudioPlayer::AudioPlayer(
32
- const std::function<void(AudioBus *, int)> &renderAudio,
32
+ const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio,
33
33
  float sampleRate)
34
34
  : renderAudio_(renderAudio) {
35
35
  AudioStreamBuilder builder;
@@ -86,7 +86,7 @@ DataCallbackResult AudioPlayer::onAudioReady(
86
86
  while (processedFrames < numFrames) {
87
87
  int framesToProcess =
88
88
  std::min(numFrames - processedFrames, RENDER_QUANTUM_SIZE);
89
- renderAudio_(mBus_.get(), framesToProcess);
89
+ renderAudio_(mBus_, framesToProcess);
90
90
 
91
91
  // TODO: optimize this with SIMD?
92
92
  for (int i = 0; i < framesToProcess; i++) {
@@ -13,9 +13,10 @@ class AudioBus;
13
13
 
14
14
  class AudioPlayer : public AudioStreamDataCallback {
15
15
  public:
16
- explicit AudioPlayer(const std::function<void(AudioBus *, int)> &renderAudio);
16
+ explicit AudioPlayer(
17
+ const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio);
17
18
  AudioPlayer(
18
- const std::function<void(AudioBus *, int)> &renderAudio,
19
+ const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio,
19
20
  float sampleRate);
20
21
 
21
22
  [[nodiscard]] float getSampleRate() const;
@@ -28,7 +29,7 @@ class AudioPlayer : public AudioStreamDataCallback {
28
29
  int32_t numFrames) override;
29
30
 
30
31
  private:
31
- std::function<void(AudioBus *, int)> renderAudio_;
32
+ std::function<void(std::shared_ptr<AudioBus>, int)> renderAudio_;
32
33
  std::shared_ptr<AudioStream> mStream_;
33
34
  std::shared_ptr<AudioBus> mBus_;
34
35
  bool isInitialized_ = false;
@@ -48,12 +48,13 @@ void AudioContext::close() {
48
48
  audioPlayer_->stop();
49
49
  }
50
50
 
51
- std::function<void(AudioBus *, int)> AudioContext::renderAudio() {
51
+ std::function<void(std::shared_ptr<AudioBus>, int)>
52
+ AudioContext::renderAudio() {
52
53
  if (!isRunning() || !destination_) {
53
- return [](AudioBus *, int) {};
54
+ return [](const std::shared_ptr<AudioBus> &, int) {};
54
55
  }
55
56
 
56
- return [this](AudioBus *data, int frames) {
57
+ return [this](const std::shared_ptr<AudioBus> &data, int frames) {
57
58
  destination_->renderAudio(data, frames);
58
59
  };
59
60
  }
@@ -27,7 +27,7 @@ class AudioContext : public BaseAudioContext {
27
27
  std::shared_ptr<IOSAudioPlayer> audioPlayer_;
28
28
  #endif
29
29
 
30
- std::function<void(AudioBus *, int)> renderAudio();
30
+ std::function<void(std::shared_ptr<AudioBus>, int)> renderAudio();
31
31
  };
32
32
 
33
33
  } // namespace audioapi
@@ -23,7 +23,7 @@ double AudioDestinationNode::getCurrentTime() const {
23
23
  }
24
24
 
25
25
  void AudioDestinationNode::renderAudio(
26
- AudioBus *destinationBus,
26
+ const std::shared_ptr<AudioBus> &destinationBus,
27
27
  int numFrames) {
28
28
  if (numFrames < 0 || !destinationBus || !isInitialized_) {
29
29
  return;
@@ -33,10 +33,10 @@ void AudioDestinationNode::renderAudio(
33
33
 
34
34
  destinationBus->zero();
35
35
 
36
- AudioBus *processedBus = processAudio(destinationBus, numFrames);
36
+ auto processedBus = processAudio(destinationBus, numFrames);
37
37
 
38
38
  if (processedBus && processedBus != destinationBus) {
39
- destinationBus->copy(processedBus);
39
+ destinationBus->copy(processedBus.get());
40
40
  }
41
41
 
42
42
  destinationBus->normalize();
@@ -16,11 +16,11 @@ class AudioDestinationNode : public AudioNode {
16
16
  public:
17
17
  explicit AudioDestinationNode(BaseAudioContext *context);
18
18
 
19
- void renderAudio(AudioBus *audioData, int numFrames);
20
-
21
19
  std::size_t getCurrentSampleFrame() const;
22
20
  double getCurrentTime() const;
23
21
 
22
+ void renderAudio(const std::shared_ptr<AudioBus>& audioData, int numFrames);
23
+
24
24
  protected:
25
25
  // DestinationNode is triggered by AudioContext using renderAudio
26
26
  // processNode function is not necessary and is never called.
@@ -97,17 +97,19 @@ std::string AudioNode::toString(ChannelInterpretation interpretation) {
97
97
  }
98
98
  }
99
99
 
100
- AudioBus *AudioNode::processAudio(AudioBus *outputBus, int framesToProcess) {
100
+ std::shared_ptr<AudioBus> AudioNode::processAudio(
101
+ std::shared_ptr<AudioBus> outputBus,
102
+ int framesToProcess) {
101
103
  if (!isInitialized_) {
102
104
  return outputBus;
103
105
  }
104
106
 
105
107
  if (isAlreadyProcessed()) {
106
- return audioBus_.get();
108
+ return audioBus_;
107
109
  }
108
110
 
109
111
  // Process inputs and return the bus with the most channels.
110
- AudioBus *processingBus = processInputs(outputBus, framesToProcess);
112
+ auto processingBus = processInputs(outputBus, framesToProcess);
111
113
 
112
114
  // Apply channel count mode.
113
115
  processingBus = applyChannelCountMode(processingBus);
@@ -117,7 +119,7 @@ AudioBus *AudioNode::processAudio(AudioBus *outputBus, int framesToProcess) {
117
119
 
118
120
  assert(processingBus != nullptr);
119
121
  // Finally, process the node itself.
120
- processNode(processingBus, framesToProcess);
122
+ processNode(processingBus.get(), framesToProcess);
121
123
 
122
124
  return processingBus;
123
125
  }
@@ -138,8 +140,10 @@ bool AudioNode::isAlreadyProcessed() {
138
140
  return false;
139
141
  }
140
142
 
141
- AudioBus *AudioNode::processInputs(AudioBus *outputBus, int framesToProcess) {
142
- AudioBus *processingBus = audioBus_.get();
143
+ std::shared_ptr<AudioBus> AudioNode::processInputs(
144
+ const std::shared_ptr<AudioBus> &outputBus,
145
+ int framesToProcess) {
146
+ auto processingBus = audioBus_;
143
147
  processingBus->zero();
144
148
 
145
149
  int maxNumberOfChannels = 0;
@@ -162,28 +166,29 @@ AudioBus *AudioNode::processInputs(AudioBus *outputBus, int framesToProcess) {
162
166
  return processingBus;
163
167
  }
164
168
 
165
- AudioBus *AudioNode::applyChannelCountMode(AudioBus *processingBus) {
169
+ std::shared_ptr<AudioBus> AudioNode::applyChannelCountMode(
170
+ std::shared_ptr<AudioBus> processingBus) {
166
171
  // If the channelCountMode is EXPLICIT, the node should output the number of
167
172
  // channels specified by the channelCount.
168
173
  if (channelCountMode_ == ChannelCountMode::EXPLICIT) {
169
- return audioBus_.get();
174
+ return audioBus_;
170
175
  }
171
176
 
172
177
  // If the channelCountMode is CLAMPED_MAX, the node should output the maximum
173
178
  // number of channels clamped to channelCount.
174
179
  if (channelCountMode_ == ChannelCountMode::CLAMPED_MAX &&
175
180
  processingBus->getNumberOfChannels() >= channelCount_) {
176
- return audioBus_.get();
181
+ return audioBus_;
177
182
  }
178
183
 
179
184
  return processingBus;
180
185
  }
181
186
 
182
- void AudioNode::mixInputsBuses(AudioBus *processingBus) {
187
+ void AudioNode::mixInputsBuses(const std::shared_ptr<AudioBus> &processingBus) {
183
188
  assert(processingBus != nullptr);
184
189
 
185
- for (auto inputBus : inputBuses_) {
186
- processingBus->sum(inputBus, channelInterpretation_);
190
+ for (const auto &inputBus : inputBuses_) {
191
+ processingBus->sum(inputBus.get(), channelInterpretation_);
187
192
  }
188
193
 
189
194
  inputBuses_.clear();
@@ -57,18 +57,18 @@ class AudioNode : public std::enable_shared_from_this<AudioNode> {
57
57
  std::size_t lastRenderedFrame_{SIZE_MAX};
58
58
 
59
59
  private:
60
- std::vector<AudioBus*> inputBuses_;
60
+ std::vector<std::shared_ptr<AudioBus>> inputBuses_ = {};
61
61
 
62
62
  static std::string toString(ChannelCountMode mode);
63
63
  static std::string toString(ChannelInterpretation interpretation);
64
64
 
65
- AudioBus *processAudio(AudioBus *outputBus, int framesToProcess);
65
+ std::shared_ptr<AudioBus> processAudio(std::shared_ptr<AudioBus> outputBus, int framesToProcess);
66
66
  virtual void processNode(AudioBus *processingBus, int framesToProcess) = 0;
67
67
 
68
68
  bool isAlreadyProcessed();
69
- AudioBus *processInputs(AudioBus *outputBus, int framesToProcess);
70
- AudioBus *applyChannelCountMode(AudioBus *processingBus);
71
- void mixInputsBuses(AudioBus *processingBus);
69
+ std::shared_ptr<AudioBus> processInputs(const std::shared_ptr<AudioBus>& outputBus, int framesToProcess);
70
+ std::shared_ptr<AudioBus> applyChannelCountMode(std::shared_ptr<AudioBus> processingBus);
71
+ void mixInputsBuses(const std::shared_ptr<AudioBus>& processingBus);
72
72
 
73
73
  void connectNode(const std::shared_ptr<AudioNode> &node);
74
74
  void disconnectNode(const std::shared_ptr<AudioNode> &node);
@@ -15,15 +15,15 @@ class AudioBus;
15
15
 
16
16
  class IOSAudioPlayer {
17
17
  protected:
18
- AudioBus *audioBus_;
18
+ std::shared_ptr<AudioBus> audioBus_;
19
19
  AudioPlayer *audioPlayer_;
20
- std::function<void(AudioBus *, int)> renderAudio_;
20
+ std::function<void(std::shared_ptr<AudioBus>, int)> renderAudio_;
21
21
 
22
22
  public:
23
23
  explicit IOSAudioPlayer(
24
- const std::function<void(AudioBus *, int)> &renderAudio);
24
+ const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio);
25
25
  IOSAudioPlayer(
26
- const std::function<void(AudioBus *, int)> &renderAudio,
26
+ const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio,
27
27
  float sampleRate);
28
28
  ~IOSAudioPlayer();
29
29
 
@@ -7,11 +7,9 @@
7
7
 
8
8
  namespace audioapi {
9
9
 
10
- IOSAudioPlayer::IOSAudioPlayer(const std::function<void(AudioBus *, int)> &renderAudio)
10
+ IOSAudioPlayer::IOSAudioPlayer(const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio)
11
11
  : renderAudio_(renderAudio), audioBus_(0)
12
12
  {
13
- audioBus_ = new AudioBus(RENDER_QUANTUM_SIZE, CHANNEL_COUNT, getSampleRate());
14
-
15
13
  RenderAudioBlock renderAudioBlock = ^(AudioBufferList *outputData, int numFrames) {
16
14
  int processedFrames = 0;
17
15
 
@@ -34,10 +32,10 @@ IOSAudioPlayer::IOSAudioPlayer(const std::function<void(AudioBus *, int)> &rende
34
32
  };
35
33
 
36
34
  audioPlayer_ = [[AudioPlayer alloc] initWithRenderAudioBlock:renderAudioBlock];
37
- audioBus_ = new AudioBus(RENDER_QUANTUM_SIZE, CHANNEL_COUNT, [audioPlayer_ getSampleRate]);
35
+ audioBus_ = std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE, CHANNEL_COUNT, getSampleRate());
38
36
  }
39
37
 
40
- IOSAudioPlayer::IOSAudioPlayer(const std::function<void(AudioBus *, int)> &renderAudio, float sampleRate)
38
+ IOSAudioPlayer::IOSAudioPlayer(const std::function<void(std::shared_ptr<AudioBus>, int)> &renderAudio, float sampleRate)
41
39
  : renderAudio_(renderAudio), audioBus_(0)
42
40
  {
43
41
  RenderAudioBlock renderAudioBlock = ^(AudioBufferList *outputData, int numFrames) {
@@ -62,7 +60,7 @@ IOSAudioPlayer::IOSAudioPlayer(const std::function<void(AudioBus *, int)> &rende
62
60
  };
63
61
 
64
62
  audioPlayer_ = [[AudioPlayer alloc] initWithRenderAudioBlock:renderAudioBlock sampleRate:sampleRate];
65
- audioBus_ = new AudioBus(RENDER_QUANTUM_SIZE, CHANNEL_COUNT, [audioPlayer_ getSampleRate]);
63
+ audioBus_ = std::make_shared<AudioBus>(RENDER_QUANTUM_SIZE, CHANNEL_COUNT, getSampleRate());
66
64
  }
67
65
 
68
66
  IOSAudioPlayer::~IOSAudioPlayer()
@@ -71,7 +69,6 @@ IOSAudioPlayer::~IOSAudioPlayer()
71
69
  [audioPlayer_ cleanup];
72
70
 
73
71
  if (audioBus_) {
74
- delete audioBus_;
75
72
  audioBus_ = 0;
76
73
  }
77
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-audio-api",
3
- "version": "0.4.10-rc.1",
3
+ "version": "0.4.10",
4
4
  "description": "react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",