-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: declared different constructor of PeriodicWave
- Loading branch information
Maciej Makowski
committed
Nov 7, 2024
1 parent
436a5eb
commit 1b58071
Showing
2 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
packages/react-native-audio-api/common/cpp/core/PeriodicWave.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,74 @@ | ||
/* | ||
* Copyright (C) 2012 Google Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. Neither the name of Apple Inc. ("Apple") nor the names of | ||
* its contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "PeriodicWave.h" | ||
|
||
// The number of bands per octave. Each octave will have this many entries in the wave tables. | ||
constexpr unsigned NumberOfOctaveBands = 3; | ||
|
||
constexpr float CentsPerRange = 1200.0f / NumberOfOctaveBands; | ||
|
||
namespace audioapi { | ||
PeriodicWave::PeriodicWave(int sampleRate): sampleRate_(sampleRate) { | ||
numberOfRanges_ = lround(NumberOfOctaveBands * log2f(static_cast<float>(getPeriodicWaveSize()))); | ||
auto nyquistFrequency = sampleRate_ / 2; | ||
lowestFundamentalFrequency_ = static_cast<float>(nyquistFrequency) / static_cast<float>(getMaxNumberOfPartials()); | ||
rateScale_ = static_cast<float>(getPeriodicWaveSize()) / static_cast<float>(sampleRate_); | ||
waveTable_ = new float[getPeriodicWaveSize()]; | ||
} | ||
|
||
PeriodicWave::PeriodicWave(int sampleRate, audioapi::OscillatorType type): PeriodicWave(sampleRate) { | ||
//get waveTable for type | ||
} | ||
|
||
PeriodicWave::PeriodicWave(int sampleRate, float *real, float *imaginary): PeriodicWave(sampleRate) { | ||
//get waveTable for real and imaginary | ||
} | ||
|
||
int PeriodicWave::getPeriodicWaveSize() const { | ||
if(sampleRate_ <= 24000) { | ||
return 2048; | ||
} | ||
|
||
if(sampleRate_ <= 88200) { | ||
return 4096; | ||
} | ||
|
||
return 16384; | ||
} | ||
|
||
void PeriodicWave::generateBasicWaveForm(OscillatorType type) { | ||
auto n = getPeriodicWaveSize(); | ||
|
||
|
||
} | ||
|
||
int PeriodicWave::getMaxNumberOfPartials() const { | ||
return getPeriodicWaveSize() / 2; | ||
} | ||
} |
54 changes: 50 additions & 4 deletions
54
packages/react-native-audio-api/common/cpp/core/PeriodicWave.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,64 @@ | ||
/* | ||
* Copyright (C) 2012 Google Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. Neither the name of Apple Inc. ("Apple") nor the names of | ||
* its contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cmath> | ||
#include <memory> | ||
|
||
#include "OscillatorType.h" | ||
|
||
namespace audioapi { | ||
class PeriodicWave { | ||
public: | ||
explicit PeriodicWave(int sampleRate, OscillatorType type); | ||
explicit PeriodicWave(int sampleRate, float *real, float *imaginary); | ||
|
||
int getPeriodicWaveSize() const; | ||
|
||
private: | ||
explicit PeriodicWave(unsigned sampleRate); | ||
explicit PeriodicWave(int sampleRate); | ||
|
||
int getMaxNumberOfPartials() const; | ||
|
||
void generateBasicWaveForm(OscillatorType type); | ||
|
||
// determines the time resolution of the waveform. | ||
unsigned sampleRate_; | ||
int sampleRate_; | ||
// determines number of frequency segments (or bands) the signal is divided. | ||
unsigned numberOfRanges_; | ||
int numberOfRanges_; | ||
// the lowest frequency (in hertz) where playback will include all of the partials. | ||
float lowestFundamentalFrequency; | ||
float lowestFundamentalFrequency_; | ||
// scaling factor used to adjust size of period of waveform to the sample rate. | ||
float rateScale_; | ||
|
||
float *waveTable_; | ||
//float **bandLimitedTables_; | ||
|
||
}; | ||
} // namespace audioapi |
1b58071
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (2)
lround
nyquist
To accept these unrecognized words as correct, you could run the following commands
... in a clone of the [email protected]:software-mansion-labs/react-native-audio-api.git repository
on the
feat/periodic-wave
branch (ℹ️ how do I use this?):Available 📚 dictionaries could cover words not in the 📘 dictionary
Consider adding them (in
.github/workflows/spelling.yml
) injobs:
/spelling:
foruses: check-spelling/check-spelling@main
in itswith
:To stop checking additional dictionaries, add (in
.github/workflows/spelling.yml
) foruses: check-spelling/check-spelling@main
in itswith
:If the flagged items are 🤯 false positives
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using).well-formed pattern.
If you can write a pattern that would match it,
try adding it to the
patterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
🚂 If you're seeing this message and your PR is from a branch that doesn't have check-spelling,
please merge to your PR's base branch to get the version configured for your repository.