Skip to content

Commit

Permalink
Merge pull request #3 from AkiyukiOkayasu/develop
Browse files Browse the repository at this point in the history
v1.2.3
  • Loading branch information
AkiyukiOkayasu authored Mar 10, 2023
2 parents 22563e8 + a4b2def commit 132e0f2
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checks: '-*,bugprone-*,clang-analyzer-*,-cppcoreguidelines-*,performance-*,portability-*,readability-*,-readability-uppercase-literal-suffix,-readability-magic-numbers, -readability-else-after-return'
Checks: '-*,bugprone-*,clang-analyzer-*,-cppcoreguidelines-*,performance-*,portability-*,readability-*,-readability-uppercase-literal-suffix,-readability-magic-numbers, -readability-else-after-return, -readability-identifier-length, -readability-identifier-naming, -bugprone-easily-swappable-parameters'
HeaderFilterRegex: '.*'
CheckOptions:
- key: readability-identifier-naming.ClassCase
Expand Down
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Determine if doctest is built as a subproject (using add_subdirectory) or if it is the main project.
set(MAIN_PROJECT OFF)

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
endif()

if(MAIN_PROJECT)
if(MAIN_PROJECT)
message(STATUS "AME Unit test settings begin")
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.16)
project(ame LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)#C++20
set(CMAKE_CXX_STANDARD 20) # C++20

include(CTest)
include(FetchContent)
FetchContent_Declare(doctest GIT_REPOSITORY https://github.com/onqtam/doctest GIT_TAG 2.4.5)
FetchContent_Declare(doctest GIT_REPOSITORY https://github.com/onqtam/doctest GIT_TAG v2.4.10)
FetchContent_MakeAvailable(doctest)
enable_testing()
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
Expand All @@ -26,12 +27,13 @@ if(MAIN_PROJECT)
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/test
)

# add_link_options("-fuse-ld=mold") # How to use custom linker (mold, lld, gold etc..)
target_compile_options(tests PUBLIC -O2 -Wall -fconstexpr-depth=2147483647)
target_compile_features(tests PUBLIC cxx_std_20)
target_link_libraries(tests PRIVATE doctest::doctest)
message(STATUS "AME Unit test settings end")
else()
message(STATUS "AME - C++ header-only DSP library for Cortex-M")
add_library(ame INTERFACE)
message(STATUS "AME - C++ header-only DSP library for Cortex-M")
add_library(ame INTERFACE)
target_include_directories(ame INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()
12 changes: 9 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

image:https://github.com/AkiyukiOkayasu/ame/actions/workflows/cmake.yml/badge.svg[UnitTest] image:https://github.com/AkiyukiOkayasu/ame/actions/workflows/doxygen.yml/badge.svg[link=https://akiyukiokayasu.github.io/ame/] image:https://img.shields.io/github/v/release/AkiyukiOkayasu/ame[link=https://github.com/AkiyukiOkayasu/ame/releases/latest] image:https://img.shields.io/github/license/AkiyukiOkayasu/ame[link=LICENSE]

AME is a C++ header-only library focused on fast audio processing on Cortex-M, such as i.MXRT. +
AME is a C++ header-only library focused on fast audio processing on Cortex-M. +
Specifically, AME provides a function that is missing from the CMSIS-DSP for audio processing. +
If CMSIS-DSP is available, use it, but it is not required. This means that ame can run on non-Cortex-M environments. +

Expand All @@ -16,7 +16,7 @@ Major changes may be added to this project. +
* https://arm-software.github.io/CMSIS_5/DSP/html/index.html[ARM CMSIS-DSP] +


== Feautures
== Features
* Audio buffer that can only be allocatable at compile time
* Oscillator and noise generator
* Filters
Expand All @@ -30,6 +30,7 @@ Major changes may be added to this project. +
** Decibel and Amplitude
** Frequency and Period
** MIDI note and Frequency
** Radian and Degree


== How to use
Expand All @@ -41,7 +42,7 @@ If you are using CMake, you can install ame using https://cmake.org/cmake/help/l
[source,cmake]
----
# CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.16)
project(example_project)
add_executable(example_project main.cpp)
Expand All @@ -61,3 +62,8 @@ Be aware that the order of audio samples in ame is interleaved. +

== Other document
See the https://akiyukiokayasu.github.io/ame/[document] for details.

== Contribution
Contributions are welcome. +
To keep your source code clean, remember to run clang-format before submitting your PR and check it with clang-tidy. The configuration files are located in the root of Project. +
Refer to the https://www.aes.org/par/guide/[Pro Audio Style Guide] for the technical terms used in doxygen comments.
1 change: 1 addition & 0 deletions include/ame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ame_Ambisonics.hpp"
#include "ame_AudioBuffer.hpp"
#include "ame_Biquad.hpp"
#include "ame_Circuit.hpp"
#include "ame_Conversion.hpp"
#include "ame_DcBlock.hpp"
#include "ame_Delay.hpp"
Expand Down
6 changes: 3 additions & 3 deletions include/ame_AudioBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class AudioBlockView
*/
AudioBlockView (std::span<ElementType, Extent> view, const uint_fast32_t numChannels) noexcept
: view (view),
numChannels (numChannels)
numChannels (numChannels),
numSamplesPerChannel (view.size() / numChannels)
{
numSamplesPerChannel = view.size() / numChannels;
}
~AudioBlockView() = default;

Expand Down Expand Up @@ -146,8 +146,8 @@ class AudioBlockView
std::span<ElementType, Extent> view;

private:
uint_fast32_t numSamplesPerChannel;
uint_fast32_t numChannels;
uint_fast32_t numSamplesPerChannel;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions include/ame_Biquad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Biquad
return coef;
}

/// LowPass coefficients calculation from RBJ cookbook.
/// Low-pass coefficients calculation from RBJ cookbook.
void makeLowPass (const FloatType cutOffFrequency, const FloatType Q) noexcept
{
const FloatType w0 = twoPi<FloatType> * cutOffFrequency / sampleRate;
Expand All @@ -89,7 +89,7 @@ class Biquad
normalizeCoefficientsByA0();
}

/// HighPass coefficients calculation from RBJ cookbook.
/// High-pass coefficients calculation from RBJ cookbook.
void makeHighPass (const FloatType cutOffFrequency, const FloatType Q) noexcept
{
const FloatType w0 = twoPi<FloatType> * cutOffFrequency / sampleRate;
Expand Down
28 changes: 28 additions & 0 deletions include/ame_Circuit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
Analog circuit modelings
@file ame_Circuit.hpp
@author Akiyuki Okayasu ([email protected])
@copyright Copyright (c) 2021 - Akiyuki Okayasu
AME is released under the MIT license.
*/

#pragma once

#include <concepts>

namespace ame
{
/** diode modeling.
https://jatinchowdhury18.medium.com/complex-nonlinearities-epsiode-2-harmonic-exciter-cd883d888a43
@param x
@return FloatType
@note When the input is 1.0, the output is larger than 1.0
*/
template <std::floating_point FloatType>
inline FloatType diode (FloatType x)
{
return static_cast<FloatType> (0.2) * (std::exp (x * static_cast<FloatType> (0.05 / 0.0259)) - static_cast<FloatType> (1.0));
}
} // namespace ame
46 changes: 22 additions & 24 deletions include/ame_Conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ constexpr void q23ToFloat (const int32_t src[], float dest[], const uint32_t blo
}
}

/**
Split channel→Interleave convertion.
/** Split channel→Interleave conversion.
@param source Split channel samples
@param dest Interleave array
@param numSamples
Expand All @@ -99,8 +98,7 @@ constexpr void interleaveSamples (const float** source, float* dest, const uint_
}
}

/**
Interleave→Split channel convertion.
/** Interleave→Split channel conversion.
@param source Interleave samples
@param dest Split channel array
@param numSamples
Expand All @@ -127,8 +125,8 @@ inline void deinterleaveSamples (const float* source, float** dest, const uint_f
@param semitone
@return frequency ratio
@code
semitoneToRatio(12.0f)// 2.0f
semitoneToRatio(-12.0f)// 0.5f
semitoneToRatio(12.0f); // 2.0f
semitoneToRatio(-12.0f);// 0.5f
@endcode
*/
inline float semitoneToRatio (const float semitone)
Expand All @@ -149,19 +147,19 @@ constexpr float freqToPeriod (const float freq) noexcept { return 1.0f / freq; }
constexpr float periodToFreq (const float period) noexcept { return 1.0f / period; }

/** Convert frequency to MIDI note number.
@param frequency
@param A3Freq Frequency for A3 (MIDI note 69). 440Hz is default.
@return MIDI note
*/
@param frequency
@param A3Freq Frequency for A3 (MIDI note 69). 440Hz is default.
@return MIDI note
*/
inline float freqToMidi (const float freq, const float A3Freq = 440.0f)
{
return 12.0f * std::log2f (freq / A3Freq) + 69.0f;
}

/** Convert MIDI note number to frequency.
@param midiNote
@param A3Freq Frequency for A3 (MIDI note 69). 440Hz is default.
@return frequency in Hz
@param midiNote
@param A3Freq Frequency for A3 (MIDI note 69). 440Hz is default.
@return frequency in Hz
*/
inline float midiToFreq (const float midiNote, const float A3Freq = 440.0f)
{
Expand Down Expand Up @@ -199,7 +197,7 @@ inline std::pair<float, float> poltocar (const float amplitude, const float angl
//==============================================================================
//time

/** Convert BPM to ms
/** Convert BPM to ms.
@param bpm
@return ms
@code
Expand All @@ -208,7 +206,7 @@ inline std::pair<float, float> poltocar (const float amplitude, const float angl
*/
constexpr float bpmToMs (float bpm) { return 60000.0f / bpm; }

/** Convert ms to BPM
/** Convert ms to BPM.
@param ms
@return BPM
@code
Expand Down Expand Up @@ -240,8 +238,8 @@ constexpr float decibelsToGain (const float dB) noexcept
@return dB decibels value
@note Outputs Outputs -100dB if the input is less than 0.00001.
@code
gainToDecibels (1.0f); // 0.0f
gainToDecibels (0.1f); // -20.0f
gainToDecibels (1.0f); // 0dB
gainToDecibels (0.1f); // -20.0dB
@endcode
*/
constexpr float gainToDecibels (const float gain) noexcept
Expand All @@ -253,20 +251,20 @@ constexpr float gainToDecibels (const float gain) noexcept

//==============================================================================
/** Degree to Radians.
@tparam FloatType float or double
@param degree
@return constexpr FloatType Radian
@tparam FloatType float or double
@param degree
@return constexpr FloatType Radian
*/
template <std::floating_point FloatType>
constexpr FloatType deg2rad (FloatType degree) noexcept
{
return degree * (ame::pi<FloatType> / static_cast<FloatType> (180.0));
}

/** Radian to Degree
@tparam FloatType float or double
@param radian
@return constexpr FloatType degree
/** Radian to Degree.
@tparam FloatType float or double
@param radian
@return constexpr FloatType degree
*/
template <std::floating_point FloatType>
constexpr FloatType rad2deg (FloatType radian) noexcept
Expand Down
3 changes: 3 additions & 0 deletions include/ame_Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ extern "C"
#ifdef __cplusplus
}
#endif

#ifndef USE_CMSIS_DSP
#define USE_CMSIS_DSP
#pragma message("CMSIS-DSP is used.")
#endif
#else
#include <cmath>
#pragma message("CMSIS-DSP is NOT used. cmath is used instead.")
#endif

#include <concepts>
Expand Down
4 changes: 2 additions & 2 deletions include/ame_Oscillator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class WavetableOscillator
/** Generate single sample.
@return generated latest sample
*/
FloatType nextSample() noexcept
FloatTypeBase nextSample() noexcept
{
const uint32_t aIndex = std::floor (tableIndex.get());
const uint32_t bIndex = std::floor (tableIndex.get (1));
Expand Down Expand Up @@ -131,7 +131,7 @@ class SineOscillator

public:
/** Create sine wave oscillator instance.
@param sampleRate The sample rate that will be used for calclate the oscillator phase increment.
@param sampleRate The sample rate that will be used for calculate the oscillator phase increment.
@param frequency Initial frequency
*/
SineOscillator (FloatType sampleRate) noexcept
Expand Down
2 changes: 1 addition & 1 deletion include/ame_Pcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class WavPlayer
template <typename FloatType, size_t N>
void process (AudioBlockView<FloatType, N>& block)
{
if (playing.load() == false)
if (! playing.load())
{
return;
}
Expand Down
15 changes: 7 additions & 8 deletions include/ame_Random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ inline uint32_t next (void)

namespace ame
{
/** random.
@return float [0, 1]
@see ame::noise()
@note Adapted from David Blackman and Sebastiano Vigna's xoshiro128+
https://prng.di.unimi.it/xoshiro128plus.c
/** Random.
@return float [0, 1]
@see ame::noise()
@note Adapted from David Blackman and Sebastiano Vigna's xoshiro128+ https://prng.di.unimi.it/xoshiro128plus.c
*/
inline float random()
{
return (next() >> 8) * FLOAT_UNIT;
}

/** white noise.
@return float [-1, 1]
@see ame::random()
/** White noise.
@return float [-1, 1]
@see ame::random()
*/
inline float noise()
{
Expand Down
2 changes: 1 addition & 1 deletion include/ame_RcLowPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace ame::dsp
{
/** RC lowpass filter for parameter smoothing.
/** RC low-pass filter for parameter smoothing.
y[t] = x[t] * coef + (1-coef) * y[t-1]
@tparam FloatType float or double
Expand Down
2 changes: 1 addition & 1 deletion include/ame_Reverb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Freeverb
output += comb[ch][cmb].process (input, damping, feedback);
}

for (int ap = 0; ap < numAllPasses; ++ap) // run the allpass filters in series
for (int ap = 0; ap < numAllPasses; ++ap) // run the all-pass filters in series
{
output = allPass[ch][ap].process (output);
}
Expand Down
4 changes: 2 additions & 2 deletions include/ame_Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class Wrap
@param offset
@return int_fast32_t [0, length-1]
*/
T get (T offset = 0) const noexcept
[[nodiscard]] T get (T offset = 0) const noexcept
{
auto n = num + offset;
while (n >= length)
Expand All @@ -310,7 +310,7 @@ class Wrap
length = newLength;
}

T getLength() const noexcept
[[nodiscard]] T getLength() const noexcept
{
return length;
}
Expand Down
Loading

0 comments on commit 132e0f2

Please sign in to comment.