Fixing compiling error before optimization

- Relation of toString and toIndex helper functions for MixerOutput
- convertingMixerOutput back to enum to avoiding casts to size_t
pull/495/head
abscisys 2 years ago
parent 78f48e458a
commit b10d155379
  1. 35
      src/mixing_console.cpp
  2. 39
      src/mixing_console_constants.h
  3. 18
      src/test/CppOptimizationsTest.hpp
  4. 12
      src/test/Makefile
  5. 66
      src/test/MixerOutputTest.hpp
  6. 16
      src/test/UIMenuTest.hpp
  7. 3
      src/test/all_tests.cpp

@ -22,6 +22,41 @@
#include "mixing_console.h"
std::string_view toString(MixerOutput enum_val)
{
static constexpr std::array<std::string_view, MixerOutput::kFXCount> names
{
"Tube",
"Chorus",
"Flanger",
"Orbitone",
"Phaser",
"Delay",
"PlateReverb",
"ShimmerReverb",
"MainOutput"
};
static_assert(names.size() == MixerOutput::kFXCount, "Enum class and string array size mismatch");
return names[static_cast<size_t>(enum_val)];
}
MixerOutput toIndex(std::string str)
{
if(str == "Tube") return MixerOutput::FX_Tube;
if(str == "Chorus") return MixerOutput::FX_Chorus;
if(str == "Flanger") return MixerOutput::FX_Flanger;
if(str == "Orbitone") return MixerOutput::FX_Orbitone;
if(str == "Phaser") return MixerOutput::FX_Phaser;
if(str == "Delay") return MixerOutput::FX_Delay;
if(str == "PlateReverb") return MixerOutput::FX_PlateReverb;
if(str == "ShimmerReverb") return MixerOutput::FX_ShimmerReverb;
if(str == "MainOutput") return MixerOutput::MainOutput;
throw std::invalid_argument("Invalid MixerOutput string");
}
template<size_t nb_inputs>
MixingConsole<nb_inputs>::MixingConsole(float32_t sampling_rate, size_t buffer_size) :
FXBase(sampling_rate),

@ -2,14 +2,14 @@
#include "extra_features.h"
enum StereoChannels
enum StereoChannels : std::size_t
{
Left = 0,
Right,
kNumChannels
};
enum class MixerOutput
enum MixerOutput : std::size_t
{
OutputStart = 0,
FX_Tube = 0,
@ -24,36 +24,5 @@ enum class MixerOutput
kFXCount
};
template<typename T>
std::string_view getMixerOutputString(T enum_val)
{
static constexpr std::array<std::string_view, static_cast<size_t>(T::kFXCount)> names
{
"Tube",
"Chorus",
"Flanger",
"Orbitone",
"Phaser",
"Delay",
"PlateReverb",
"ShimmerReverb",
"MainOutput"
};
static_assert(names.size() == static_cast<size_t>(T::kFXCount),"Enum class and string array size mismatch");
return names[static_cast<size_t>(enum_val)];
}
MixerOutput getMixerOutputFromString(std::string str)
{
if(str == "Tube") return MixerOutput::FX_Tube;
if(str == "Chorus") return MixerOutput::FX_Chorus;
if(str == "Flanger") return MixerOutput::FX_Flanger;
if(str == "Orbitone") return MixerOutput::FX_Orbitone;
if(str == "Phaser") return MixerOutput::FX_Phaser;
if(str == "Delay") return MixerOutput::FX_Delay;
if(str == "PlateReverb") return MixerOutput::FX_PlateReverb;
if(str == "ShimmerReverb") return MixerOutput::FX_ShimmerReverb;
if(str == "MainOutput") return MixerOutput::MainOutput;
throw std::invalid_argument("Invalid MixerOutput string");
}
extern std::string_view toString(MixerOutput enum_val);
extern MixerOutput toIndex(std::string str);

@ -0,0 +1,18 @@
#pragma once
int nb = 0;
int NbIteration() {
nb++;
return 3;
}
TEST(CppOptimization, NbCallsInUpperBoudariesInForLoop)
{
for(int i = 0; i < NbIteration(); ++i)
{
// Does something
}
EXPECT_EQ(nb, 4);
}

@ -1,15 +1,15 @@
CXX := gcc
CXX := g++
# CXXFLAGS := -O2
CXXFLAGS := -g
CXXFLAGS := -g -std=c++20
DEFINES := -DCPU=x86 -DDEBUG=1
INCLUDES := -I../../CMSIS_5/CMSIS/DSP/Include/ \
-I../../CMSIS_5/CMSIS/Core/Include/ \
-I../../circle-stdlib/libs/circle/include \
-I../../circle-stdlib/libs/circle/addon \
-I../../Synth_Dexed/src
# -I../../circle-stdlib/libs/circle/include \
# -I../../circle-stdlib/libs/circle/addon \
GCC := $(CXX) $(INCLUDES) $(CXXFLAGS)
LD := gcc
LD := g++
LIBS := -lm -lstdc++ -lgtest -lpthread
OBJS := \
@ -117,7 +117,7 @@ arm_functions.o: arm_functions.cpp
# effect_platervbstereo.o: ../effect_platervbstereo.cpp
# $(CXX) $(DEFINES) $(INCLUDES) $(CXXFLAGS) -c $^ -o $@
fxrack_test.cpp: ../mixing_console.h ../mixing_console.cpp
fxrack_test.cpp: ../mixing_console.h ../mixing_console.cpp
touch $@
fxrack_test.o: fxrack_test.cpp

@ -2,100 +2,100 @@
#include <gtest/gtest.h>
#include "../mixing_console_constants.h"
#include "../mixing_console.h"
TEST(MixerOutputTest, GetMixerOutputStringForTube)
TEST(MixerOutputTest, toStringForTube)
{
auto v = getMixerOutputString(MixerOutput::FX_Tube);
auto v = toString(MixerOutput::FX_Tube);
EXPECT_EQ(v, "Tube");
}
TEST(MixerOutputTest, GetMixerOutputStringForChorus)
TEST(MixerOutputTest, toStringForChorus)
{
auto v = getMixerOutputString(MixerOutput::FX_Chorus);
auto v = toString(MixerOutput::FX_Chorus);
EXPECT_EQ(v, "Chorus");
}
TEST(MixerOutputTest, GetMixerOutputStringForFlanger)
TEST(MixerOutputTest, toStringForFlanger)
{
auto v = getMixerOutputString(MixerOutput::FX_Flanger);
auto v = toString(MixerOutput::FX_Flanger);
EXPECT_EQ(v, "Flanger");
}
TEST(MixerOutputTest, GetMixerOutputStringForOrbitone)
TEST(MixerOutputTest, toStringForOrbitone)
{
auto v = getMixerOutputString(MixerOutput::FX_Orbitone);
auto v = toString(MixerOutput::FX_Orbitone);
EXPECT_EQ(v, "Orbitone");
}
TEST(MixerOutputTest, GetMixerOutputStringForPhaser)
TEST(MixerOutputTest, toStringForPhaser)
{
auto v = getMixerOutputString(MixerOutput::FX_Phaser);
auto v = toString(MixerOutput::FX_Phaser);
EXPECT_EQ(v, "Phaser");
}
TEST(MixerOutputTest, GetMixerOutputStringForDelay)
TEST(MixerOutputTest, toStringForDelay)
{
auto v = getMixerOutputString(MixerOutput::FX_Delay);
auto v = toString(MixerOutput::FX_Delay);
EXPECT_EQ(v, "Delay");
}
TEST(MixerOutputTest, GetMixerOutputStringForPlateReverb)
TEST(MixerOutputTest, toStringForPlateReverb)
{
auto v = getMixerOutputString(MixerOutput::FX_PlateReverb);
auto v = toString(MixerOutput::FX_PlateReverb);
EXPECT_EQ(v, "PlateReverb");
}
TEST(MixerOutputTest, GetMixerOutputStringForShimmerReverb)
TEST(MixerOutputTest, toStringForShimmerReverb)
{
auto v = getMixerOutputString(MixerOutput::FX_ShimmerReverb);
auto v = toString(MixerOutput::FX_ShimmerReverb);
EXPECT_EQ(v, "ShimmerReverb");
}
TEST(MixerOutputTest, GetMixerOutputFromStringTube)
TEST(MixerOutputTest, toIndexTube)
{
MixerOutput v = getMixerOutputFromString("Tube");
MixerOutput v = toIndex("Tube");
EXPECT_EQ(v, MixerOutput::FX_Tube);
}
TEST(MixerOutputTest, GetMixerOutputFromStringChorus)
TEST(MixerOutputTest, toIndexChorus)
{
MixerOutput v = getMixerOutputFromString("Chorus");
MixerOutput v = toIndex("Chorus");
EXPECT_EQ(v, MixerOutput::FX_Chorus);
}
TEST(MixerOutputTest, GetMixerOutputFromStringFlanger)
TEST(MixerOutputTest, toIndexFlanger)
{
MixerOutput v = getMixerOutputFromString("Flanger");
MixerOutput v = toIndex("Flanger");
EXPECT_EQ(v, MixerOutput::FX_Flanger);
}
TEST(MixerOutputTest, GetMixerOutputFromStringOrbitone)
TEST(MixerOutputTest, toIndexOrbitone)
{
MixerOutput v = getMixerOutputFromString("Orbitone");
MixerOutput v = toIndex("Orbitone");
EXPECT_EQ(v, MixerOutput::FX_Orbitone);
}
TEST(MixerOutputTest, GetMixerOutputFromStringPhaser)
TEST(MixerOutputTest, toIndexPhaser)
{
MixerOutput v = getMixerOutputFromString("Phaser");
MixerOutput v = toIndex("Phaser");
EXPECT_EQ(v, MixerOutput::FX_Phaser);
}
TEST(MixerOutputTest, GetMixerOutputFromStringDelay)
TEST(MixerOutputTest, toIndexDelay)
{
MixerOutput v = getMixerOutputFromString("Delay");
MixerOutput v = toIndex("Delay");
EXPECT_EQ(v, MixerOutput::FX_Delay);
}
TEST(MixerOutputTest, GetMixerOutputFromStringPlateReverb)
TEST(MixerOutputTest, toIndexPlateReverb)
{
MixerOutput v = getMixerOutputFromString("PlateReverb");
MixerOutput v = toIndex("PlateReverb");
EXPECT_EQ(v, MixerOutput::FX_PlateReverb);
}
TEST(MixerOutputTest, GetMixerOutputFromStringShimmerReverb)
TEST(MixerOutputTest, toIndexShimmerReverb)
{
MixerOutput v = getMixerOutputFromString("ShimmerReverb");
MixerOutput v = toIndex("ShimmerReverb");
EXPECT_EQ(v, MixerOutput::FX_ShimmerReverb);
}

@ -1,12 +1,12 @@
#pragma once
#include <gtest/gtest.h>
// #include <gtest/gtest.h>
#include "../uimenu.h"
#include "../minidexed.h"
// #include "../uimenu.h"
// #include "../minidexed.h"
TEST(UIMenuTest, CountGlobalParams)
{
size_t nb = CMiniDexed::ParameterUnknown;
EXPECT_EQ(nb, 156);
}
// TEST(UIMenuTest, CountGlobalParams)
// {
// size_t nb = CMiniDexed::ParameterUnknown;
// EXPECT_EQ(nb, 156);
// }

@ -1,5 +1,6 @@
#include "MixerOutputTest.hpp"
#include "UIMenuTest.hpp"
// #include "UIMenuTest.hpp"
#include "CppOptimizationsTest.hpp"
int main(int argc, char **argv)
{

Loading…
Cancel
Save