Skip to content

Commit

Permalink
fix: linter howling
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsek committed Nov 15, 2024
1 parent d938b77 commit 9002e52
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 178 deletions.
12 changes: 6 additions & 6 deletions packages/react-native-audio-api/common/cpp/core/AudioArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace audioapi {

AudioArray::AudioArray(int size) : size_(size) {
resize(size);
};
}

AudioArray::~AudioArray() {
delete[] data_;
};
}

int AudioArray::getSize() const {
return size_;
Expand Down Expand Up @@ -54,7 +54,7 @@ void AudioArray::copy(const AudioArray* source) {

float AudioArray::getMaxAbsValue() const {
return VectorMath::maximumMagnitude(data_, size_);
};
}

void AudioArray::normalize() {
float maxAbsValue = getMaxAbsValue();
Expand All @@ -64,15 +64,15 @@ void AudioArray::normalize() {
}

VectorMath::multiplyByScalar(data_, 1.0f / maxAbsValue, data_, size_);
};
}

void AudioArray::scale(float value) {
VectorMath::multiplyByScalar(data_, value, data_, size_);
};
}

void AudioArray::sum(const AudioArray* source) {
VectorMath::add(data_, source->getData(), data_, size_);
};
}

} // namespace audioapi

36 changes: 18 additions & 18 deletions packages/react-native-audio-api/common/cpp/core/AudioArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
namespace audioapi {

class AudioArray {
public:
explicit AudioArray(int size);
~AudioArray();
public:
explicit AudioArray(int size);
~AudioArray();

[[nodiscard]] int getSize() const;
float* getData() const;
[[nodiscard]] int getSize() const;
float* getData() const;


float& operator[](int index);
const float& operator[](int index) const;
float& operator[](int index);
const float& operator[](int index) const;

void zero();
void resize(int size);
void copy(const AudioArray* source);
void zero();
void resize(int size);
void copy(const AudioArray* source);

float getMaxAbsValue() const;
float getMaxAbsValue() const;

void normalize();
void scale(float value);
void sum(const AudioArray* source);
void normalize();
void scale(float value);
void sum(const AudioArray* source);


private:
float *data_;
int size_;
private:
float *data_;
int size_;
};

}
} // namespace audioapi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ AudioBuffer::AudioBuffer(int numberOfChannels, int length, int sampleRate)
length_(length),
sampleRate_(sampleRate),
duration_(static_cast<double>(length) / sampleRate) {

}

} // namespace audioapi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class AudioBuffer : public std::enable_shared_from_this<AudioBuffer> {
int startInChannel);

private:

int numberOfChannels_;
int length_;
int sampleRate_;
Expand Down
41 changes: 20 additions & 21 deletions packages/react-native-audio-api/common/cpp/core/AudioBus.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>

#include "AudioBus.h"
#include "Constants.h"
Expand All @@ -22,47 +23,46 @@ AudioBus::AudioBus(BaseAudioContext *context)


createChannels();
};
}

AudioBus::AudioBus(BaseAudioContext *context, int numberOfChannels)
: context_(context), numberOfChannels_(numberOfChannels) {
sampleRate_ = context_->getSampleRate();
size_ = context_->getBufferSizeInFrames();

createChannels();
};
}

AudioBus::AudioBus(BaseAudioContext *context, int numberOfChannels, int size)
: context_(context), numberOfChannels_(numberOfChannels), size_(size) {
sampleRate_ = context_->getSampleRate();

createChannels();
};

}

AudioBus::~AudioBus() {
channels_.clear();
};
}

/**
* Public interfaces - getters
*/

int AudioBus::getNumberOfChannels() const {
return numberOfChannels_;
};
}

int AudioBus::getSampleRate() const {
return sampleRate_;
};
}

int AudioBus::getSize() const {
return size_;
};
}

AudioArray* AudioBus::getChannel(int index) const {
return channels_[index].get();
};
}

AudioArray* AudioBus::getChannelByType(int channelType) const {
switch (getNumberOfChannels()) {
Expand Down Expand Up @@ -111,7 +111,7 @@ AudioArray* AudioBus::getChannelByType(int channelType) const {
default:
return 0;
}
};
}

/**
* Public interfaces - audio processing and setters
Expand All @@ -121,7 +121,7 @@ void AudioBus::zero() {
for (auto it = channels_.begin(); it != channels_.end(); it += 1) {
it->get()->zero();
}
};
}

void AudioBus::normalize() {
float maxAbsValue = this->maxAbsValue();
Expand All @@ -132,13 +132,13 @@ void AudioBus::normalize() {

float scale = 1.0f / maxAbsValue;
this->scale(scale);
};
}

void AudioBus::scale(float value) {
for (auto it = channels_.begin(); it != channels_.end(); it += 1) {
it->get()->scale(value);
}
};
}

float AudioBus::maxAbsValue() const {
float maxAbsValue = 0.0f;
Expand All @@ -149,7 +149,7 @@ float AudioBus::maxAbsValue() const {
}

return maxAbsValue;
};
}

void AudioBus::copy(const AudioBus &source) {
if (&source == this) {
Expand All @@ -159,7 +159,7 @@ void AudioBus::copy(const AudioBus &source) {
// zero + sum is equivalent to copy, but takes care of up/down-mixing.
zero();
sum(source);
};
}

void AudioBus::sum(const AudioBus &source) {
if (&source == this) {
Expand All @@ -186,7 +186,7 @@ void AudioBus::sum(const AudioBus &source) {
for (int i = 0; i < numberOfChannels_; i++) {
channels_[i]->sum(source.getChannel(i));
}
};
}

/**
* Internal tooling - channel initialization
Expand All @@ -195,7 +195,7 @@ void AudioBus::sum(const AudioBus &source) {
void AudioBus::createChannels() {
// TODO: verify if its correct way of memory allocation
channels_ = std::vector<std::unique_ptr<AudioArray>>(numberOfChannels_, std::make_unique<AudioArray>(size_));
};
}

/**
* Internal tooling - channel summing
Expand All @@ -209,7 +209,7 @@ void AudioBus::discreteSum(const AudioBus &source) {
for (int i = 0; i < numberOfChannels; i++) {
getChannel(i)->sum(source.getChannel(i));
}
};
}

void AudioBus::sumByUpMixing(const AudioBus &source) {
int numberOfSourceChannels = source.getNumberOfChannels();
Expand All @@ -234,7 +234,6 @@ void AudioBus::sumByUpMixing(const AudioBus &source) {

// Stereo 2 to stereo 4 or 5.1 (2 -> 4, 6)
if (numberOfSourceChannels == 2 && (numberOfChannels == 4 || numberOfChannels == 6)) {

getChannelByType(ChannelLeft)->sum(source.getChannelByType(ChannelLeft));
getChannelByType(ChannelRight)->sum(source.getChannelByType(ChannelRight));
return;
Expand All @@ -250,7 +249,7 @@ void AudioBus::sumByUpMixing(const AudioBus &source) {
}

discreteSum(source);
};
}

void AudioBus::sumByDownMixing(const AudioBus &source) {
int numberOfSourceChannels = source.getNumberOfChannels();
Expand Down Expand Up @@ -336,6 +335,6 @@ void AudioBus::sumByDownMixing(const AudioBus &source) {
}

discreteSum(source);
};
}

} // namespace audioapi
88 changes: 44 additions & 44 deletions packages/react-native-audio-api/common/cpp/core/AudioBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@ class BaseAudioContext;
class AudioArray;

class AudioBus {
public:
enum {
ChannelMono = 0,
ChannelLeft = 0,
ChannelRight = 1,
ChannelCenter = 2,
ChannelLFE = 3,
ChannelSurroundLeft = 4,
ChannelSurroundRight = 5,
};

explicit AudioBus(BaseAudioContext *context);
explicit AudioBus(BaseAudioContext *context, int numberOfChannels);
explicit AudioBus(BaseAudioContext *context, int numberOfChannels, int size);
~AudioBus();

[[nodiscard]] int getNumberOfChannels() const;
[[nodiscard]] int getSampleRate() const;
[[nodiscard]] int getSize() const;
AudioArray* getChannel(int index) const;
AudioArray* getChannelByType(int channelType) const;

void zero();
void normalize();
void scale(float value);
float maxAbsValue() const;

void copy(const AudioBus &source);
void sum(const AudioBus &source);

private:
BaseAudioContext *context_;
std::vector<std::unique_ptr<AudioArray>> channels_;


int numberOfChannels_;
int sampleRate_;
int size_;

void createChannels();
void discreteSum(const AudioBus &source);
void sumByUpMixing(const AudioBus &source);
void sumByDownMixing(const AudioBus &source);
public:
enum {
ChannelMono = 0,
ChannelLeft = 0,
ChannelRight = 1,
ChannelCenter = 2,
ChannelLFE = 3,
ChannelSurroundLeft = 4,
ChannelSurroundRight = 5,
};

explicit AudioBus(BaseAudioContext *context);
explicit AudioBus(BaseAudioContext *context, int numberOfChannels);
explicit AudioBus(BaseAudioContext *context, int numberOfChannels, int size);
~AudioBus();

[[nodiscard]] int getNumberOfChannels() const;
[[nodiscard]] int getSampleRate() const;
[[nodiscard]] int getSize() const;
AudioArray* getChannel(int index) const;
AudioArray* getChannelByType(int channelType) const;

void zero();
void normalize();
void scale(float value);
float maxAbsValue() const;

void copy(const AudioBus &source);
void sum(const AudioBus &source);

private:
BaseAudioContext *context_;
std::vector<std::unique_ptr<AudioArray>> channels_;


int numberOfChannels_;
int sampleRate_;
int size_;

void createChannels();
void discreteSum(const AudioBus &source);
void sumByUpMixing(const AudioBus &source);
void sumByDownMixing(const AudioBus &source);
};

}
} // namespace audioapi
Loading

0 comments on commit 9002e52

Please sign in to comment.