Skip to content

Commit a88616d

Browse files
author
Maciej Makowski
committed
ci: yarn format
1 parent 72442d8 commit a88616d

File tree

13 files changed

+229
-183
lines changed

13 files changed

+229
-183
lines changed

packages/react-native-audio-api/common/cpp/HostObjects/BaseAudioContextHostObject.cpp

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ std::vector<jsi::PropNameID> BaseAudioContextHostObject::getPropertyNames(
3030
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "createBuffer"));
3131
propertyNames.push_back(
3232
jsi::PropNameID::forUtf8(runtime, "createPeriodicWave"));
33-
propertyNames.push_back(jsi::PropNameID::forUtf8(runtime, "decodeAudioDataSource"));
33+
propertyNames.push_back(
34+
jsi::PropNameID::forUtf8(runtime, "decodeAudioDataSource"));
3435
return propertyNames;
3536
}
3637

@@ -165,61 +166,60 @@ jsi::Value BaseAudioContextHostObject::get(
165166
}
166167

167168
if (propName == "createPeriodicWave") {
168-
return jsi::Function::createFromHostFunction(
169-
runtime,
170-
propNameId,
171-
3,
172-
[this](
173-
jsi::Runtime &runtime,
174-
const jsi::Value &thisValue,
175-
const jsi::Value *arguments,
176-
size_t count) -> jsi::Value {
177-
auto real = arguments[0].getObject(runtime).getArray(runtime);
178-
auto imag = arguments[1].getObject(runtime).getArray(runtime);
179-
auto disableNormalization = arguments[2].getBool();
180-
auto length =
181-
static_cast<int>(real.getProperty(runtime, "length").asNumber());
182-
183-
auto *realData = new float[length];
184-
auto *imagData = new float[length];
185-
186-
for (size_t i = 0; i < real.length(runtime); i++) {
187-
realData[i] = static_cast<float>(
188-
real.getValueAtIndex(runtime, i).getNumber());
189-
}
190-
for (size_t i = 0; i < imag.length(runtime); i++) {
191-
realData[i] = static_cast<float>(
192-
imag.getValueAtIndex(runtime, i).getNumber());
193-
}
194-
195-
auto periodicWave = wrapper_->createPeriodicWave(
196-
realData, imagData, disableNormalization, length);
197-
auto periodicWaveHostObject =
198-
PeriodicWaveHostObject::createFromWrapper(periodicWave);
199-
return jsi::Object::createFromHostObject(
200-
runtime, periodicWaveHostObject);
201-
});
169+
return jsi::Function::createFromHostFunction(
170+
runtime,
171+
propNameId,
172+
3,
173+
[this](
174+
jsi::Runtime &runtime,
175+
const jsi::Value &thisValue,
176+
const jsi::Value *arguments,
177+
size_t count) -> jsi::Value {
178+
auto real = arguments[0].getObject(runtime).getArray(runtime);
179+
auto imag = arguments[1].getObject(runtime).getArray(runtime);
180+
auto disableNormalization = arguments[2].getBool();
181+
auto length =
182+
static_cast<int>(real.getProperty(runtime, "length").asNumber());
183+
184+
auto *realData = new float[length];
185+
auto *imagData = new float[length];
186+
187+
for (size_t i = 0; i < real.length(runtime); i++) {
188+
realData[i] = static_cast<float>(
189+
real.getValueAtIndex(runtime, i).getNumber());
190+
}
191+
for (size_t i = 0; i < imag.length(runtime); i++) {
192+
realData[i] = static_cast<float>(
193+
imag.getValueAtIndex(runtime, i).getNumber());
194+
}
195+
196+
auto periodicWave = wrapper_->createPeriodicWave(
197+
realData, imagData, disableNormalization, length);
198+
auto periodicWaveHostObject =
199+
PeriodicWaveHostObject::createFromWrapper(periodicWave);
200+
return jsi::Object::createFromHostObject(
201+
runtime, periodicWaveHostObject);
202+
});
202203
}
203204

204-
205-
if (propName == "decodeAudioDataSource") {
206-
return jsi::Function::createFromHostFunction(
207-
runtime,
208-
propNameId,
209-
1,
210-
[this](
211-
jsi::Runtime &runtime,
212-
const jsi::Value &thisValue,
213-
const jsi::Value *arguments,
214-
size_t count) -> jsi::Value {
215-
std::string source = arguments[0].getString(runtime).utf8(runtime);
216-
auto buffer = wrapper_->decodeAudioDataSource(source);
217-
auto audioBufferHostObject =
218-
AudioBufferHostObject::createFromWrapper(buffer);
219-
return jsi::Object::createFromHostObject(
220-
runtime, audioBufferHostObject);
221-
});
222-
}
205+
if (propName == "decodeAudioDataSource") {
206+
return jsi::Function::createFromHostFunction(
207+
runtime,
208+
propNameId,
209+
1,
210+
[this](
211+
jsi::Runtime &runtime,
212+
const jsi::Value &thisValue,
213+
const jsi::Value *arguments,
214+
size_t count) -> jsi::Value {
215+
std::string source = arguments[0].getString(runtime).utf8(runtime);
216+
auto buffer = wrapper_->decodeAudioDataSource(source);
217+
auto audioBufferHostObject =
218+
AudioBufferHostObject::createFromWrapper(buffer);
219+
return jsi::Object::createFromHostObject(
220+
runtime, audioBufferHostObject);
221+
});
222+
}
223223

224224
throw std::runtime_error("Not yet implemented!");
225225
}

packages/react-native-audio-api/common/cpp/core/AudioBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AudioBus;
1212
class AudioBuffer : public std::enable_shared_from_this<AudioBuffer> {
1313
public:
1414
explicit AudioBuffer(int numberOfChannels, int length, int sampleRate);
15-
AudioBuffer(AudioBus *bus);
15+
AudioBuffer(AudioBus *bus);
1616

1717
[[nodiscard]] int getLength() const;
1818
[[nodiscard]] int getSampleRate() const;

packages/react-native-audio-api/common/cpp/core/BaseAudioContext.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifdef ANDROID
22
#include "AudioPlayer.h"
33
#else
4-
#include "IOSAudioPlayer.h"
54
#include "IOSAudioDecoder.h"
5+
#include "IOSAudioPlayer.h"
66
#endif
77

88
#include "BaseAudioContext.h"
@@ -26,7 +26,8 @@ BaseAudioContext::BaseAudioContext() {
2626
audioPlayer_ = std::make_shared<AudioPlayer>(this->renderAudio());
2727
#else
2828
audioPlayer_ = std::make_shared<IOSAudioPlayer>(this->renderAudio());
29-
audioDecoder_ = std::make_shared<IOSAudioDecoder>(audioPlayer_->getSampleRate());
29+
audioDecoder_ =
30+
std::make_shared<IOSAudioDecoder>(audioPlayer_->getSampleRate());
3031
#endif
3132

3233
sampleRate_ = audioPlayer_->getSampleRate();
@@ -98,13 +99,15 @@ std::shared_ptr<PeriodicWave> BaseAudioContext::createPeriodicWave(
9899
}
99100

100101
#ifdef ANDROID
101-
std::shared_ptr<AudioBuffer> BaseAudioContext::decodeAudioDataSource(std::string source) {
102+
std::shared_ptr<AudioBuffer> BaseAudioContext::decodeAudioDataSource(
103+
std::string source) {
102104
return {nullptr};
103105
}
104106
#else
105-
std::shared_ptr<AudioBuffer> BaseAudioContext::decodeAudioDataSource(std::string source) {
106-
auto audioBus = audioDecoder_->decodeWithFilePath(source);
107-
return std::make_shared<AudioBuffer>(audioBus);
107+
std::shared_ptr<AudioBuffer> BaseAudioContext::decodeAudioDataSource(
108+
std::string source) {
109+
auto audioBus = audioDecoder_->decodeWithFilePath(source);
110+
return std::make_shared<AudioBuffer>(audioBus);
108111
}
109112
#endif
110113

packages/react-native-audio-api/common/cpp/utils/FFTFrame.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ namespace audioapi {
3838

3939
class FFTFrame {
4040
public:
41-
explicit FFTFrame(int size): size_(size), log2Size_(static_cast<int>(log2(size))), realData_(new float[size]), imaginaryData_(new float[size]) {}
41+
explicit FFTFrame(int size)
42+
: size_(size),
43+
log2Size_(static_cast<int>(log2(size))),
44+
realData_(new float[size]),
45+
imaginaryData_(new float[size]) {}
4246
~FFTFrame() {
4347
delete[] realData_;
4448
delete[] imaginaryData_;

packages/react-native-audio-api/common/cpp/utils/Locker.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ namespace audioapi {
77
// Small easy interface to manage locking
88
class Locker {
99
public:
10-
Locker(): lockPtr_(0) {}
11-
explicit Locker(std::mutex& lockPtr): lockPtr_(&lockPtr) {
10+
Locker() : lockPtr_(0) {}
11+
explicit Locker(std::mutex &lockPtr) : lockPtr_(&lockPtr) {
1212
lock();
1313
}
1414

1515
~Locker() {
1616
unlock();
1717
}
1818

19-
explicit operator bool() const { return !!lockPtr_; }
19+
explicit operator bool() const {
20+
return !!lockPtr_;
21+
}
2022

2123
void lock() {
2224
if (lockPtr_) {
@@ -26,11 +28,11 @@ class Locker {
2628

2729
void unlock() {
2830
if (lockPtr_) {
29-
lockPtr_->unlock();
31+
lockPtr_->unlock();
3032
}
3133
}
3234

33-
static Locker tryLock(std::mutex& lock) {
35+
static Locker tryLock(std::mutex &lock) {
3436
Locker result = Locker();
3537

3638
if (lock.try_lock()) {
@@ -41,7 +43,7 @@ class Locker {
4143
}
4244

4345
private:
44-
std::mutex* lockPtr_;
46+
std::mutex *lockPtr_;
4547
};
4648

4749
} // namespace audioapi

packages/react-native-audio-api/common/cpp/utils/VectorMath.cpp

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,20 @@ float maximumMagnitude(
115115
return maximumValue;
116116
}
117117

118-
void multiplyByScalarThenAddToOutput(const float* inputVector, float scalar, float* outputVector, size_t numberOfElementsToProcess) {
119-
vDSP_vsma(inputVector, 1, &scalar, outputVector, 1, outputVector, 1, numberOfElementsToProcess);
118+
void multiplyByScalarThenAddToOutput(
119+
const float *inputVector,
120+
float scalar,
121+
float *outputVector,
122+
size_t numberOfElementsToProcess) {
123+
vDSP_vsma(
124+
inputVector,
125+
1,
126+
&scalar,
127+
outputVector,
128+
1,
129+
outputVector,
130+
1,
131+
numberOfElementsToProcess);
120132
}
121133

122134
#else
@@ -609,69 +621,73 @@ float maximumMagnitude(
609621
return max;
610622
}
611623

612-
void multiplyByScalarThenAddToOutput(const float* inputVector, float scalar, float* outputVector, size_t numberOfElementsToProcess) {
613-
size_t n = numberOfElementsToProcess;
624+
void multiplyByScalarThenAddToOutput(
625+
const float *inputVector,
626+
float scalar,
627+
float *outputVector,
628+
size_t numberOfElementsToProcess) {
629+
size_t n = numberOfElementsToProcess;
614630

615631
#if HAVE_X86_SSE2
616-
// If the inputVector address is not 16-byte aligned, the first several frames (at most three) should be processed separately.
617-
while (!is16ByteAligned(inputVector) && n) {
618-
*outputVector += scalar * *inputVector;
619-
inputVector++;
620-
outputVector++;
621-
n--;
622-
}
632+
// If the inputVector address is not 16-byte aligned, the first several frames
633+
// (at most three) should be processed separately.
634+
while (!is16ByteAligned(inputVector) && n) {
635+
*outputVector += scalar * *inputVector;
636+
inputVector++;
637+
outputVector++;
638+
n--;
639+
}
623640

624-
// Now the inputVector is aligned, use SSE.
625-
size_t tailFrames = n % 4;
626-
const float* endP = outputVector + n - tailFrames;
627-
628-
__m128 pSource;
629-
__m128 dest;
630-
__m128 temp;
631-
__m128 mScale = _mm_set_ps1(scalar);
632-
633-
bool destAligned = is16ByteAligned(outputVector);
634-
635-
#define SSE2_MULT_ADD(loadInstr, storeInstr) \
636-
while (outputVector < endP) \
637-
{ \
638-
pSource = _mm_load_ps(inputVector); \
639-
temp = _mm_mul_ps(pSource, mScale); \
640-
dest = _mm_##loadInstr##_ps(outputVector); \
641-
dest = _mm_add_ps(dest, temp); \
642-
_mm_##storeInstr##_ps(outputVector, dest); \
643-
inputVector += 4; \
644-
outputVector += 4; \
645-
}
641+
// Now the inputVector is aligned, use SSE.
642+
size_t tailFrames = n % 4;
643+
const float *endP = outputVector + n - tailFrames;
644+
645+
__m128 pSource;
646+
__m128 dest;
647+
__m128 temp;
648+
__m128 mScale = _mm_set_ps1(scalar);
649+
650+
bool destAligned = is16ByteAligned(outputVector);
651+
652+
#define SSE2_MULT_ADD(loadInstr, storeInstr) \
653+
while (outputVector < endP) { \
654+
pSource = _mm_load_ps(inputVector); \
655+
temp = _mm_mul_ps(pSource, mScale); \
656+
dest = _mm_##loadInstr##_ps(outputVector); \
657+
dest = _mm_add_ps(dest, temp); \
658+
_mm_##storeInstr##_ps(outputVector, dest); \
659+
inputVector += 4; \
660+
outputVector += 4; \
661+
}
646662

647-
if (destAligned)
648-
SSE2_MULT_ADD(load, store)
649-
else
650-
SSE2_MULT_ADD(loadu, storeu)
663+
if (destAligned)
664+
SSE2_MULT_ADD(load, store)
665+
else
666+
SSE2_MULT_ADD(loadu, storeu)
651667

652-
n = tailFrames;
668+
n = tailFrames;
653669
#elif HAVE_ARM_NEON_INTRINSICS
654-
size_t tailFrames = n % 4;
655-
const float* endP = outputVector + n - tailFrames;
670+
size_t tailFrames = n % 4;
671+
const float *endP = outputVector + n - tailFrames;
656672

657-
float32x4_t k = vdupq_n_f32(scalar);
658-
while (outputVector < endP) {
659-
float32x4_t source = vld1q_f32(inputVector);
660-
float32x4_t dest = vld1q_f32(outputVector);
673+
float32x4_t k = vdupq_n_f32(scalar);
674+
while (outputVector < endP) {
675+
float32x4_t source = vld1q_f32(inputVector);
676+
float32x4_t dest = vld1q_f32(outputVector);
661677

662-
dest = vmlaq_f32(dest, source, k);
663-
vst1q_f32(outputVector, dest);
678+
dest = vmlaq_f32(dest, source, k);
679+
vst1q_f32(outputVector, dest);
664680

665-
inputVector += 4;
666-
outputVector += 4;
667-
}
668-
n = tailFrames;
681+
inputVector += 4;
682+
outputVector += 4;
683+
}
684+
n = tailFrames;
669685
#endif
670-
while (n--) {
671-
*outputVector += *inputVector * scalar;
672-
++inputVector;
673-
++outputVector;
674-
}
686+
while (n--) {
687+
*outputVector += *inputVector * scalar;
688+
++inputVector;
689+
++outputVector;
690+
}
675691
}
676692

677693
#endif

0 commit comments

Comments
 (0)