Skip to content

Commit

Permalink
Added voice robotization and whisperization effect working
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Jul 10, 2021
1 parent 02f8936 commit 22b7408
Show file tree
Hide file tree
Showing 11 changed files with 1,235 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -131,10 +131,13 @@ set(EFFECTS_SOURCES
effects/Saturation.cpp
effects/Shift.cpp
effects/Wave.cpp
audio_effects/STFT.cpp
audio_effects/Noise.cpp
audio_effects/Distortion.cpp
audio_effects/ParametricEQ.cpp
audio_effects/Compressor.cpp)
audio_effects/Compressor.cpp
audio_effects/Pitch.cpp
audio_effects/Robotization.cpp)

# Qt video player components
set(QT_PLAYER_SOURCES
Expand Down Expand Up @@ -294,7 +297,7 @@ mark_as_advanced(QT_VERSION_STR)
# Find FFmpeg libraries (used for video encoding / decoding)
find_package(FFmpeg REQUIRED COMPONENTS avcodec avformat avutil swscale)

set(all_comps avcodec avformat avutil swscale avresample)
set(all_comps avcodec avformat avutil swscale)
if(TARGET FFmpeg::swresample)
list(APPEND all_comps swresample)
else()
Expand Down
8 changes: 8 additions & 0 deletions src/EffectInfo.cpp
Expand Up @@ -100,6 +100,12 @@ EffectBase* EffectInfo::CreateEffect(std::string effect_type) {
else if(effect_type == "Compressor")
return new Compressor();

else if(effect_type == "Pitch")
return new Pitch();

else if(effect_type == "Robotization")
return new Robotization();

#ifdef USE_OPENCV
else if(effect_type == "Stabilizer")
return new Stabilizer();
Expand Down Expand Up @@ -141,6 +147,8 @@ Json::Value EffectInfo::JsonValue() {
root.append(Distortion().JsonInfo());
root.append(ParametricEQ().JsonInfo());
root.append(Compressor().JsonInfo());
root.append(Pitch().JsonInfo());
root.append(Robotization().JsonInfo());

#ifdef USE_OPENCV
root.append(Stabilizer().JsonInfo());
Expand Down
2 changes: 2 additions & 0 deletions src/Effects.h
Expand Up @@ -53,6 +53,8 @@
#include "audio_effects/Distortion.h"
#include "audio_effects/ParametricEQ.h"
#include "audio_effects/Compressor.h"
#include "audio_effects/Pitch.h"
#include "audio_effects/Robotization.h"

/* OpenCV Effects */
#ifdef USE_OPENCV
Expand Down
36 changes: 36 additions & 0 deletions src/Enums.h
Expand Up @@ -112,5 +112,41 @@ namespace openshot
EXPANDER,
NOISE_GATE,
};

/// This enumeration determines the FFT size.
enum FFTSize
{
FFT_SIZE_32,
FFT_SIZE_64,
FFT_SIZE_128,
FFT_SIZE_256,
FFT_SIZE_512,
FFT_SIZE_1024,
FFT_SIZE_2048,
FFT_SIZE_4096,
FFT_SIZE_8192,
};

/// This enumeration determines the hop size.
enum HopSize {
HOP_SIZE_2,
HOP_SIZE_4,
HOP_SIZE_8,
};

/// This enumeration determines the window type.
enum WindowType {
RECTANGULAR,
BART_LETT,
HANN,
HAMMING,
};

enum RobotizationEffectType {
PASS_THROUGH,
ROBOTIZATION,
WHISPERIZATION,
};

}
#endif
10 changes: 5 additions & 5 deletions src/audio_effects/Distortion.cpp
Expand Up @@ -78,15 +78,15 @@ std::shared_ptr<openshot::Frame> Distortion::GetFrame(std::shared_ptr<openshot::
for (int channel = 0; channel < frame->audio->getNumChannels(); channel++)
{
//auto *inBuffer = frame->audio->getReadPointer(channel);
auto *channelData = frame->audio->getWritePointer(channel);
auto *channel_data = frame->audio->getWritePointer(channel);
float out;

for (auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
{

const int input_gain_value = (int)input_gain.GetValue(frame_number);
const int output_gain_value = (int)output_gain.GetValue(frame_number);
const float in = channelData[sample]*powf(10.0f, input_gain_value * 0.05f);
const float in = channel_data[sample]*powf(10.0f, input_gain_value * 0.05f);

// Use the current distortion type
switch (distortion_type) {
Expand Down Expand Up @@ -142,7 +142,7 @@ std::shared_ptr<openshot::Frame> Distortion::GetFrame(std::shared_ptr<openshot::
}

float filtered = filters[channel]->processSingleSampleRaw(out);
channelData[sample] = filtered*powf(10.0f, output_gain_value * 0.05f);
channel_data[sample] = filtered*powf(10.0f, output_gain_value * 0.05f);
}
}

Expand All @@ -152,11 +152,11 @@ std::shared_ptr<openshot::Frame> Distortion::GetFrame(std::shared_ptr<openshot::

void Distortion::updateFilters(int64_t frame_number)
{
double discreteFrequency = M_PI * 0.01;
double discrete_frequency = M_PI * 0.01;
double gain = pow(10.0, (float)tone.GetValue(frame_number) * 0.05);

for (int i = 0; i < filters.size(); ++i)
filters[i]->updateCoefficients(discreteFrequency, gain);
filters[i]->updateCoefficients(discrete_frequency, gain);
}

// Generate JSON string of this object
Expand Down

0 comments on commit 22b7408

Please sign in to comment.