Compare commits
No commits in common. "bf90991e9c58278b15d5bc2f95e33c49ec9530a6" and "0b2d815509ebc3a22b958796ab43792fc536e3cf" have entirely different histories.
bf90991e9c
...
0b2d815509
|
|
@ -1,40 +0,0 @@
|
||||||
cmake_minimum_required(VERSION 3.14)
|
|
||||||
project(wtpp)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
|
|
||||||
add_library (wave src/wave.cpp)
|
|
||||||
add_library (wavetable src/wavetable.cpp)
|
|
||||||
add_library (common src/common.cpp)
|
|
||||||
add_library (generators src/generators.cpp)
|
|
||||||
|
|
||||||
add_executable(wtpp src/wtpp.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(wtpp wave wavetable common generators)
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
googletest
|
|
||||||
URL https://github.com/google/googletest/archive/95d8c7ac4389b38b197bc7521dffb62508653eb5.zip
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(googletest)
|
|
||||||
|
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
add_executable(wtpp_test tests/wtpp_test.cpp)
|
|
||||||
add_executable(wave_test tests/wave_test.cpp)
|
|
||||||
add_executable(wavetable_test tests/wavetable_test.cpp)
|
|
||||||
add_executable(generators_test tests/generators_test.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(wtpp_test GTest::gtest_main)
|
|
||||||
target_link_libraries(wave_test wave GTest::gtest_main)
|
|
||||||
target_link_libraries(wavetable_test wave wavetable GTest::gtest_main)
|
|
||||||
target_link_libraries(generators_test generators GTest::gtest_main)
|
|
||||||
|
|
||||||
include(GoogleTest)
|
|
||||||
|
|
||||||
gtest_discover_tests(wtpp_test)
|
|
||||||
gtest_discover_tests(wave_test)
|
|
||||||
gtest_discover_tests(wavetable_test)
|
|
||||||
gtest_discover_tests(generators_test)
|
|
||||||
21
Makefile
21
Makefile
|
|
@ -1,20 +1,17 @@
|
||||||
PROJ = wtpp
|
PROJ = wtpp
|
||||||
CC = /usr/bin/clang++
|
CC = /usr/bin/clang++
|
||||||
GDB = /usr/bin/gdb
|
GDB = /usr/bin/gdb
|
||||||
|
OLEVEL = -O2
|
||||||
|
|
||||||
build-release:
|
CFLAGS = -Wall -std=c++17 $(OLEVEL) -o $(PROJ)
|
||||||
cmake --build build
|
|
||||||
|
OBJECTS = src/wtpp.cpp src/wave.cpp src/wavetable.cpp src/generators.cpp src/common.cpp
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(CC) $(CFLAGS) $(OBJECTS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm build/wtpp
|
rm wtpp
|
||||||
|
|
||||||
test: build
|
debug: build
|
||||||
cd build && ctest --output-on-failure
|
|
||||||
|
|
||||||
debug:
|
|
||||||
$(CC) -g $(CFLAGS) $(OBJECTS)
|
|
||||||
$(GDB) $(PROJ)
|
$(GDB) $(PROJ)
|
||||||
|
|
||||||
web-debug:
|
|
||||||
$(CC) -g $(CFLAGS) $(OBJECTS)
|
|
||||||
gdbgui $(PROJ)
|
|
||||||
|
|
|
||||||
56
src/wtpp.cpp
56
src/wtpp.cpp
|
|
@ -1,6 +1,60 @@
|
||||||
#include <iostream>
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "ini.h"
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "wave.h"
|
||||||
|
#include "generators.h"
|
||||||
|
#include "wavetable.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
clog("Generating wave cycle lookup tables");
|
||||||
|
Wave sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave;
|
||||||
|
|
||||||
|
// Calculate fundamental wave values
|
||||||
|
sample_table_t sin_vals = gen_sin();
|
||||||
|
sample_table_t squ_vals = gen_squ();
|
||||||
|
sample_table_t saw_vals = gen_saw();
|
||||||
|
sample_table_t tri_vals = gen_tri();
|
||||||
|
sample_table_t isaw_vals = gen_isaw();
|
||||||
|
|
||||||
|
// Set wave lookup table values
|
||||||
|
sin_wave.setTable(sin_vals);
|
||||||
|
squ_wave.setTable(squ_vals);
|
||||||
|
saw_wave.setTable(saw_vals);
|
||||||
|
tri_wave.setTable(tri_vals);
|
||||||
|
isaw_wave.setTable(isaw_vals);
|
||||||
|
|
||||||
|
clog("Printing head of sine table");
|
||||||
|
sin_wave.print_head();
|
||||||
|
clog("Printing head of square table");
|
||||||
|
squ_wave.print_head();
|
||||||
|
clog("Printing head of saw table");
|
||||||
|
saw_wave.print_head();
|
||||||
|
clog("Printing head of triangle table");
|
||||||
|
tri_wave.print_head();
|
||||||
|
clog("Printing head of inverse saw table");
|
||||||
|
isaw_wave.print_head();
|
||||||
|
|
||||||
|
Wavetable wt_01{"Fundamental Waves"};
|
||||||
|
clog(wt_01.name());
|
||||||
|
|
||||||
|
// Add fundamental waves to wt_01
|
||||||
|
std::array<Wave, 5> fundies = {sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave};
|
||||||
|
for (uint8_t i = 0; i < 5; i++){
|
||||||
|
wt_01.setWave(i, fundies[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write sine wave table to file
|
||||||
|
sin_wave.export_csv("data/sine.csv");
|
||||||
|
|
||||||
|
// Write full Wavetable data to file
|
||||||
|
wt_01.export_csv("data");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
#include "../src/generators.h"
|
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
TEST(Generator, SineWave)
|
|
||||||
{
|
|
||||||
sample_table_t t = gen_sin();
|
|
||||||
// Starts at 0
|
|
||||||
EXPECT_EQ(t[0], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Generator, SquareWave) {
|
|
||||||
sample_table_t t = gen_squ();
|
|
||||||
// Starts at 1
|
|
||||||
EXPECT_EQ(t[0], 1);
|
|
||||||
// Ends at -1
|
|
||||||
EXPECT_EQ(t[DEFAULT_N_SAMPLES - 1], -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Generator, SawWave) {
|
|
||||||
sample_table_t t = gen_saw();
|
|
||||||
// Starts at -1
|
|
||||||
EXPECT_EQ(t[0], -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Generator, TriangleWave) {
|
|
||||||
sample_table_t t = gen_tri();
|
|
||||||
// Starts at -1
|
|
||||||
EXPECT_EQ(t[0], -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Generator, InverseSawWave) {
|
|
||||||
sample_table_t t = gen_isaw();
|
|
||||||
// Starts at 1
|
|
||||||
EXPECT_EQ(t[0], 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
#include "../src/wave.h"
|
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
TEST(Wave, DefaultConstructor)
|
|
||||||
{
|
|
||||||
Wave w1, w2;
|
|
||||||
// Check that ids are correct
|
|
||||||
EXPECT_EQ(w1.getId(), 0);
|
|
||||||
EXPECT_EQ(w2.getId(), 1);
|
|
||||||
// Sample table should be 0 initialized
|
|
||||||
EXPECT_EQ(w1.getVal(0), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Wave, CopyConstructor) {
|
|
||||||
Wave w1;
|
|
||||||
Wave w2(w1);
|
|
||||||
// Check id is correct
|
|
||||||
EXPECT_EQ(w2.getId(), 0);
|
|
||||||
// Sample table should be 0 initialized
|
|
||||||
EXPECT_EQ(w2.getVal(0), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Wave, CopyAssignment)
|
|
||||||
{
|
|
||||||
Wave w1;
|
|
||||||
Wave w2 = w1;
|
|
||||||
// Check id is correct
|
|
||||||
EXPECT_EQ(w2.getId(), 0);
|
|
||||||
// Sample table should be 0 initialized
|
|
||||||
EXPECT_EQ(w2.getVal(0), 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
#include "../src/wavetable.h"
|
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
TEST(Wavetable, DefaultConstructor)
|
|
||||||
{
|
|
||||||
Wavetable w1("PPG"), w2("!PPG");
|
|
||||||
// Check ids are correct
|
|
||||||
EXPECT_EQ(w1.getId(), 0);
|
|
||||||
EXPECT_EQ(w2.getId(), 1);
|
|
||||||
// Check name is correct
|
|
||||||
// std::string name = w1.name();
|
|
||||||
EXPECT_EQ(w1.name(), "0: PPG");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Wavetable, CopyConstructor) {
|
|
||||||
Wavetable w1("PPG");
|
|
||||||
Wavetable w2(w1);
|
|
||||||
// Check id is correct
|
|
||||||
EXPECT_EQ(w2.getId(), 0);
|
|
||||||
// Sample name is correct
|
|
||||||
EXPECT_EQ(w2.name(), "0: PPG");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Wavetable, CopyAssignment) {
|
|
||||||
Wavetable w1("PPG");
|
|
||||||
Wavetable w2 = w1;
|
|
||||||
// Check id is correct
|
|
||||||
EXPECT_EQ(w2.getId(), 0);
|
|
||||||
// Check name is correct
|
|
||||||
EXPECT_EQ(w2.name(), "0: PPG");
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue