forked from omeryusufyagci/fast-music-remover
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add DeepFilterCommandBuilder to MediaProcessor (omeryusufyag…
…ci#42) Initial implementation of DeepFilterCommandBuilder --------- Co-authored-by: George Olson <[email protected]> Co-authored-by: omeryusufyagci <[email protected]>
- Loading branch information
1 parent
c3d0caf
commit 80827ea
Showing
8 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "DeepFilterCommandBuilder.h" | ||
|
||
#include <sstream> | ||
#include <stdexcept> | ||
|
||
#include "Utils.h" | ||
|
||
namespace MediaProcessor { | ||
|
||
DeepFilterCommandBuilder& DeepFilterCommandBuilder::setInputFile( | ||
const std::string& inputAudioPath) { | ||
/** | ||
* FIXME: Find a solution to ensure flexibility in calling `setInputFile()`. | ||
* See the header for more details on the problem. | ||
*/ | ||
|
||
m_inputAudioPath = inputAudioPath; | ||
addArgument(inputAudioPath); | ||
|
||
return *this; | ||
} | ||
|
||
DeepFilterCommandBuilder& DeepFilterCommandBuilder::setOutputFile( | ||
const std::string& outputAudioPath) { | ||
m_outputAudioPath = outputAudioPath; | ||
addFlag("--output-dir", outputAudioPath); | ||
|
||
return *this; | ||
} | ||
|
||
DeepFilterCommandBuilder& DeepFilterCommandBuilder::setNoiseReductionLevel(double level) { | ||
if (!Utils::isWithinRange(level, 0.0, 1.0)) { | ||
throw std::invalid_argument("Noise reduction level must be between 0.0 and 1.0"); | ||
} | ||
m_noiseReductionLevel = level; | ||
addFlag("--noise-reduction", std::to_string(level)); | ||
|
||
return *this; | ||
} | ||
|
||
DeepFilterCommandBuilder& DeepFilterCommandBuilder::enableDelayCompensation() { | ||
addFlag("--compensate-delay"); | ||
|
||
return *this; | ||
} | ||
|
||
std::string DeepFilterCommandBuilder::build() const { | ||
if (m_inputAudioPath.empty()) { | ||
throw std::runtime_error("Input audio path must be specified."); | ||
} | ||
if (m_outputAudioPath.empty()) { | ||
throw std::runtime_error("Output audio path must be specified."); | ||
} | ||
|
||
return CommandBuilder::build(); | ||
} | ||
|
||
} // namespace MediaProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef DEEPFILTERCOMMANDBUILDER_H | ||
#define DEEPFILTERCOMMANDBUILDER_H | ||
|
||
#include "CommandBuilder.h" | ||
|
||
namespace MediaProcessor { | ||
|
||
/** | ||
* @brief A builder class for constructing DeepFilter commands. | ||
*/ | ||
class DeepFilterCommandBuilder : public CommandBuilder { | ||
public: | ||
/** | ||
* @brief Sets the input audio file for the DeepFilter command. | ||
* | ||
* @note | ||
* To ensure the correct behavior, please call `setInputFile()` as the first | ||
* method when configuring this builder. This guarantees that the input file | ||
* is added in the proper order before other optional parameters. | ||
* | ||
* DeepFilter not providing an input file flag poses challenges to implement | ||
* this without breaking the builder pattern or sacrificing const-correctness. | ||
* We'll try to find a good solution for this ASAP. | ||
* | ||
* @return A reference to the updated object for method chaining. | ||
*/ | ||
DeepFilterCommandBuilder& setInputFile(const std::string& inputAudioPath); | ||
|
||
/** | ||
* @brief Sets the output audio file for the DeepFilter command. | ||
* | ||
* @return A reference to the updated object for method chaining. | ||
*/ | ||
DeepFilterCommandBuilder& setOutputFile(const std::string& outputAudioPath); | ||
|
||
/** | ||
* @brief Sets the noise reduction level for the DeepFilter command. | ||
* | ||
* @param level The noise reduction level: from 0.0 (no reduction) to 1.0 (max reduction). | ||
* @return A reference to the updated DeepFilterCommandBuilder instance. | ||
* | ||
* @throws std::invalid_argument if the level is not within the range [0.0, 1.0]. | ||
*/ | ||
DeepFilterCommandBuilder& setNoiseReductionLevel(double level); | ||
|
||
/** | ||
* @brief Enabled filtering delay compensation for the DeepFilter command. | ||
* | ||
* @return A reference to the updated DeepFilterCommandBuilder instance. | ||
*/ | ||
DeepFilterCommandBuilder& enableDelayCompensation(); | ||
|
||
/** | ||
* @brief Builds the final DeepFilter command string. | ||
* | ||
* Constructs the command string using the provided parameters and options. | ||
* | ||
* @return The constructed command string. | ||
* | ||
* @throws std::runtime_error if required parameters (input or output file) are missing. | ||
*/ | ||
std::string build() const override; | ||
|
||
private: | ||
std::string m_inputAudioPath; | ||
std::string m_outputAudioPath; | ||
double m_noiseReductionLevel = 0.5; | ||
}; | ||
|
||
} // namespace MediaProcessor | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters