Skip to content

Commit

Permalink
Leveled encoder/synthesizer commands via Application class
Browse files Browse the repository at this point in the history
  • Loading branch information
tornupnegatives committed May 19, 2024
1 parent 44707bb commit bd216bd
Show file tree
Hide file tree
Showing 16 changed files with 1,003 additions and 391 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_definitions(-Wall -Wextra -Wpedantic)

###############################################################################
Expand Down Expand Up @@ -50,7 +51,11 @@ add_executable(
src/encoding/Synthesizer.cpp
src/bitstream/BitstreamGenerator.cpp
src/bitstream/PathUtils.cpp
src/ui/Application.cpp
src/ui/cli/EncoderCommand.cpp
src/ui/cli/SynthesizerCommand.cpp
src/ui/cli/CommandLineApp.cpp
src/ui/cli/GuiCommand.cpp
src/main.cpp)

if(TMSEXPRESS_BUILD_GUI)
Expand Down
68 changes: 51 additions & 17 deletions src/bitstream/BitstreamGeneratorParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,82 @@ enum EncoderStyle {
ENCODER_STYLE_C_ARDUINO,

/// @brief Bitstream as JSON file
ENCODER_STYLE_JSON
ENCODER_STYLE_JSON,

//ENCODER_STYLE_BIN
};

/// @brief Supported LPC model order (number of coefficients)
enum ModelOrder { MODEL_ORDER_10 = 10 };

/// @brief Supported sample rates (in Hertz)
enum SampleRate { SAMPLE_RATE_8KHZ = 8000 };

///////////////////////////////////////////////////////////////////////////////
// Constants //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/// @brief Instructs bitstream generator to ignore a given parameter
static const int kDisableParameter = -1;

// Defaults
static const SampleRate kDefaultSampleRateHz = SAMPLE_RATE_8KHZ;
static const float kDefaultWindowWidthMs = 25.0F;
static const int kDefaultHighpassCutoffHz = kDisableParameter;
static const int kDefaultLowpassCutoffHz = kDisableParameter;
static const float kDefaultPreEmphasisAlpha = kDisableParameter;
static const int kDefaultMaxPitchHz = 500;
static const int kDefaultMinPitchHz = 50;
static const ModelOrder kDefaultModelOrder = MODEL_ORDER_10;
static const EncoderStyle kDefaultStyle = ENCODER_STYLE_ASCII;
static const bool kDefaultIncludeStopFrame = true;
static const int kDefaultGainShift = 0;
static const bool kDefaultNormalizeGain = true;
static const float kDefaultUnvoicedGainDb = 30.0F;
static const float kDefaultVoicedGainDb = 37.5F;
static const bool kDefaultDetectRepeatFrames = false;

///////////////////////////////////////////////////////////////////////////////
// Parameter Structs //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/// @brief Defines parameters which must match for all analysis structures
struct SharedParameters {
/// @brief Sampling rate of source audio, in Hertz
int sample_rate_hz;
SampleRate sample_rate_hz = kDefaultSampleRateHz;

/// @brief Segmentation/analysis window width (frame length) in milliseconds
float window_width_ms;
float window_width_ms = kDefaultWindowWidthMs;
};

/// @brief Defines upper vocal tract (LPC analysis) parameters
struct UpperVocalTractParameters {
int highpass_cutoff_hz;
int lowpass_cutoff_hz;
float pre_emphasis_alpha;
int highpass_cutoff_hz = kDefaultHighpassCutoffHz;
int lowpass_cutoff_hz = kDefaultLowpassCutoffHz;
float pre_emphasis_alpha = kDefaultPreEmphasisAlpha;
int model_order = kDefaultModelOrder;
};

/// @brief Defines lower vocal tract (pitch and voicing analysis) parameters
struct LowerVocalTractParameters {
int highpass_cutoff_hz;
int lowpass_cutoff_hz;
float pre_emphasis_alpha;
int max_pitch_hz;
int min_pitch_hz;
int highpass_cutoff_hz = kDefaultHighpassCutoffHz;
int lowpass_cutoff_hz = kDefaultLowpassCutoffHz;
float pre_emphasis_alpha = kDefaultPreEmphasisAlpha;
int max_pitch_hz = kDefaultMaxPitchHz;
int min_pitch_hz = kDefaultMinPitchHz;
};

struct BitstreamParameters {
EncoderStyle encoder_style;
bool include_stop_frame;
EncoderStyle encoder_style = kDefaultStyle;
bool include_stop_frame = kDefaultIncludeStopFrame;
};

struct PostProcessorParameters {
int gain_shift;
float max_voiced_gain_db;
float max_unvoiced_gain_db;
bool detect_repeat_frames;
int gain_shift = kDefaultGainShift;
bool normalize_gain = kDefaultNormalizeGain;
float max_voiced_gain_db = kDefaultUnvoicedGainDb;
float max_unvoiced_gain_db = kDefaultVoicedGainDb;
bool detect_repeat_frames = kDefaultDetectRepeatFrames;
};

}; // namespace tms_express
Expand Down
2 changes: 1 addition & 1 deletion src/encoding/FrameEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FrameEncoder {
/// @brief Imports ASCII bitstream from disk
/// @param path Path to ASCII bitstream file
/// @return Number of Frames imported from file
size_t importASCIIFromFile(const std::string &path);
[[deprecated]] size_t importASCIIFromFile(const std::string &path);

/// @brief Imports ASCII bitstream from string
/// @param flat_bitstream String of comma-delimited ASCII hex bytes
Expand Down
43 changes: 4 additions & 39 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
// Copyright 2023 Joseph Bellahcen <[email protected]>

#ifdef TMSEXPRESS_GUI
#include <QApplication>
#endif // TMSEXPRESS_GUI
// Copyright (C) 2022-2024 Joseph Bellahcen <[email protected]>

#include "ui/cli/CommandLineApp.hpp"

#ifdef TMSEXPRESS_GUI
#include "ui/gui/MainWindow.hpp"
#endif // TMSEXPRESS_GUI

int runCommandLineApp(int argc, char **argv) {
int main(int argc, char** argv) {
auto cli = tms_express::ui::CommandLineApp();
int status = cli.run(argc, argv);
return status;
}

#ifdef TMSEXPRESS_GUI
int runGraphicalApp(int argc, char **argv) {
QApplication app(argc, argv);

tms_express::ui::MainWindow w;
w.show();

return app.exec();
}
#endif // TMSEXPRESS_GUI

int main(int argc, char **argv) {
// If no arguments are passed, launch GUI
if (argc == 1) {
#ifdef TMSEXPRESS_GUI
runGraphicalApp(argc, argv);
#else
runCommandLineApp(argc, argv);
#endif
}

// Otherwise, use command-line interface
if (argc > 1) {
runCommandLineApp(argc, argv);
}
CLI11_PARSE(cli, argc, argv);
return 0;
}
Loading

0 comments on commit bd216bd

Please sign in to comment.