From 52a22d53c44325a55c065401ac5d122c3114dada Mon Sep 17 00:00:00 2001 From: rkcf Date: Mon, 27 Feb 2023 03:52:01 -0600 Subject: [PATCH 1/3] Refactor: create common.h and move logging function there --- src/common.h | 17 +++++++++++++++++ src/wtpp.cpp | 12 +++--------- 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/common.h diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..71bf13a --- /dev/null +++ b/src/common.h @@ -0,0 +1,17 @@ +/*! @file common.h + @brief Header for shared utilities and constants + */ +#ifndef COMMON_H_ +#define COMMON_H_ + +#include +#include + +/*! Logs a message + @param message The string to be logged + */ +static void log(std::string message) { + std::cout << "wtpp: " << message << '\n'; +} + +#endif // COMMON_H_ diff --git a/src/wtpp.cpp b/src/wtpp.cpp index e00d1b2..edbea90 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -1,12 +1,14 @@ #include #include #include -#include #include #include #include +#include "ini.h" + +#include "common.h" #include "wave.h" #include "generators.h" #include "wavetable.h" @@ -14,14 +16,6 @@ static const uint32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate static const uint8_t DEFAULT_BIT_DEPTH = 12; -/*! Logs a message - @param message The string to be logged - */ -static void log(std::string message) -{ - std::cout << "wtpp: " << message << '\n'; -} - int main() { log("Generating wave cycle lookup tables"); From 8d7bc51d6bf5e0f8286741e21a517ec96990e837 Mon Sep 17 00:00:00 2001 From: rkcf Date: Mon, 27 Feb 2023 04:45:37 -0600 Subject: [PATCH 2/3] Refactor: move constants to common and fix logging --- Makefile | 2 +- src/common.h | 22 ++++++++++++++++------ src/generators.cpp | 1 + src/generators.h | 3 --- src/wave.h | 13 ++++++------- src/wavetable.h | 5 +---- src/wtpp.cpp | 19 +++++++------------ 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 7b57192..5b73fda 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ OLEVEL = -O2 CFLAGS = -Wall -std=c++17 $(OLEVEL) -o $(PROJ) -OBJECTS = src/wtpp.cpp src/wave.cpp src/wavetable.cpp src/generators.cpp +OBJECTS = src/wtpp.cpp src/wave.cpp src/wavetable.cpp src/generators.cpp src/common.cpp build: $(CC) $(CFLAGS) $(OBJECTS) diff --git a/src/common.h b/src/common.h index 71bf13a..b8eb0a0 100644 --- a/src/common.h +++ b/src/common.h @@ -1,17 +1,27 @@ /*! @file common.h - @brief Header for shared utilities and constants + @brief Header for constants, types, utilities */ #ifndef COMMON_H_ #define COMMON_H_ +#include #include -#include -/*! Logs a message +/*! + Constants + */ +const uint32_t DEFAULT_SAMPLE_RATE = 22050; /*!< 22.05 kHz sampling rate */ +const uint8_t DEFAULT_BIT_DEPTH = 12; /*!< 12bit samples */ +const uint16_t DEFAULT_N_SAMPLES = 1024; /*!< 1024 samples per wave cycle */ +const uint16_t DEFAULT_N_WAVES = 64; /*!< Number of Wave cycle objects in Wavetable */ + +/*! + TYPES + */ + +/*! Logs a message to console @param message The string to be logged */ -static void log(std::string message) { - std::cout << "wtpp: " << message << '\n'; -} +void clog(std::string message); #endif // COMMON_H_ diff --git a/src/generators.cpp b/src/generators.cpp index 8470bea..efbd2c7 100644 --- a/src/generators.cpp +++ b/src/generators.cpp @@ -1,3 +1,4 @@ +#include #include "generators.h" #include "wave.h" diff --git a/src/generators.h b/src/generators.h index 9e84223..c48cb1b 100644 --- a/src/generators.h +++ b/src/generators.h @@ -4,9 +4,6 @@ #ifndef GENERATORS_H_ #define GENERATORS_H_ -#include "math.h" -#include - #include "wave.h" /*! Generate sine wave data diff --git a/src/wave.h b/src/wave.h index ddcba66..7ec6ce9 100644 --- a/src/wave.h +++ b/src/wave.h @@ -4,18 +4,17 @@ #ifndef WAVE_H_ #define WAVE_H_ -#include +#include "common.h" #include +#include #include +#include +#include -#include - -const uint16_t DEFAULT_N_SAMPLES = 1024; - -using sample_table_t = std::array; +using sample_table_t = std::array; /*!< Array of waveform sample data*/ /*! @class Wave wave.h "wave.h" - @brief Single cycle wave object with lookup table + @brief Single cycle wave object with lookup table */ class Wave { diff --git a/src/wavetable.h b/src/wavetable.h index 6acd1f8..3eefe27 100644 --- a/src/wavetable.h +++ b/src/wavetable.h @@ -10,10 +10,7 @@ #include "wave.h" -/* Number of Wave cycle objects in table */ -const uint16_t DEFAULT_N_WAVES = 256; - -using wave_table_t = std::array; +using wave_table_t = std::array; /*!< Array of Wave objects */ /*! @class Wavetable wavetable.h "wavetable.h" @brief Object containing a table of single cycle Wave objects diff --git a/src/wtpp.cpp b/src/wtpp.cpp index edbea90..a1534ab 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -1,7 +1,5 @@ #include -#include #include -#include #include #include @@ -13,12 +11,9 @@ #include "generators.h" #include "wavetable.h" -static const uint32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate -static const uint8_t DEFAULT_BIT_DEPTH = 12; - int main() { - log("Generating wave cycle lookup tables"); + clog("Generating wave cycle lookup tables"); Wave sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave; // Calculate fundamental wave values @@ -35,21 +30,21 @@ int main() tri_wave.setTable(tri_vals); isaw_wave.setTable(isaw_vals); - log("Printing head of sine table"); + clog("Printing head of sine table"); sin_wave.print_head(); - log("Printing head of square table"); + clog("Printing head of square table"); squ_wave.print_head(); - log("Printing head of saw table"); + clog("Printing head of saw table"); saw_wave.print_head(); - log("Printing head of triangle table"); + clog("Printing head of triangle table"); tri_wave.print_head(); - log("Printing head of inverse saw table"); + clog("Printing head of inverse saw table"); isaw_wave.print_head(); // Create wave table of all fundamental Wave objects wave_table_t fundies = {sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave}; Wavetable wt_01{"Fundamental Waves", fundies}; - log(wt_01.name()); + clog(wt_01.name()); // Write sine wave table to file sin_wave.export_csv("data/sine.csv"); From 306b558f8fae1ad479a0b267fbe07f2caaff9fb1 Mon Sep 17 00:00:00 2001 From: rkcf Date: Mon, 27 Feb 2023 04:48:10 -0600 Subject: [PATCH 3/3] Fix: add forgotten common.cpp file --- src/common.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/common.cpp diff --git a/src/common.cpp b/src/common.cpp new file mode 100644 index 0000000..e000947 --- /dev/null +++ b/src/common.cpp @@ -0,0 +1,8 @@ +#include +#include +#include "common.h" + +void clog(std::string message) +{ + std::cout << "wtpp: " << message << '\n'; +}