Skip to content

Commit

Permalink
Merge pull request #10 from andre-tm-hui/feat/repitch-resample
Browse files Browse the repository at this point in the history
Feat/repitch resample
  • Loading branch information
andre-tm-hui authored Feb 11, 2023
2 parents 78c3ba4 + b5634a5 commit 17b3ce4
Show file tree
Hide file tree
Showing 27 changed files with 224 additions and 43 deletions.
3 changes: 3 additions & 0 deletions ReVox.pro
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SOURCES += \
ui/util/qttransitions.cpp \
ui/widgets/bindablebutton.cpp \
ui/widgets/customdial.cpp \
ui/widgets/fx/fxswitch.cpp \
ui/widgets/hotkeylistitemwidget.cpp \
ui/widgets/hotkeylistwidget.cpp \
ui/widgets/monitorslider.cpp \
Expand Down Expand Up @@ -97,6 +98,7 @@ HEADERS += \
ui/util/qttransitions.h \
ui/widgets/bindablebutton.h \
ui/widgets/customdial.h \
ui/widgets/fx/fxswitch.h \
ui/widgets/hotkeylistitemwidget.h \
ui/widgets/hotkeylistwidget.h \
ui/widgets/monitorslider.h \
Expand All @@ -121,6 +123,7 @@ FORMS += \
ui/titlebar.ui \
ui/components/fxtab.ui \
ui/menus/settingsmenu.ui \
ui/widgets/fx/fxswitch.ui \
ui/widgets/monitorslider.ui \
ui/widgets/fx/fxdial.ui \
ui/widgets/fx/fxkeypicker.ui
Expand Down
7 changes: 4 additions & 3 deletions audiofx/lib/pitchshift/pitchshifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ void PitchShifter::processRepitch(std::chrono::nanoseconds startTime) {
}

// repitch if enabled
if (repitch) factor *= repitchFactor;
if (repitch) {
factor *= repitchFactor;
}

// autotune if enabled
if (autotune) {
Expand Down Expand Up @@ -225,9 +227,8 @@ std::vector<float> PitchShifter::getWindow(float *buf, float period, float marke
for (int i = 0; i < windowSize; i++, startIdx++)
window.push_back(std::lerp(buf[startIdx], buf[startIdx + 1], lerpDistance) *
0.5f * (1.f - cos(2.f * M_PI * (float)i / (float)(windowSize - 1))));
//window = Window::Hann(window);

//if (factor != 1.f) window = resample(window, factor);
if (repitch && resampleWindows && factor != 1.f) window = resample(window, factor);
return window;
}

Expand Down
6 changes: 5 additions & 1 deletion audiofx/lib/pitchshift/pitchshifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class PitchShifter
void setAutotuneNotes(std::vector<bool> notes) { validNotes = notes; }
std::vector<bool> getAutotuneNotes() { return validNotes; }

void setRepitchResample(bool resample) { resampleWindows = resample; }
bool getRepitchResample() { return resampleWindows; }

void reset();

private:
Expand Down Expand Up @@ -73,7 +76,8 @@ class PitchShifter
repitchFactor = 1.f;
bool setupFlag = false,
autotune = false,
repitch = false;
repitch = false,
resampleWindows = false;

std::vector<bool> validNotes = {true, false, true, false, true, true, false, true, false, true, false, true};
};
Expand Down
7 changes: 6 additions & 1 deletion audiofx/repitcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Repitcher::Repitcher(std::shared_ptr<PitchShifter> ps) : IAudioFX(), ps(ps)
{
paramMap["Pitch"] = {"FXDial", "st", "Change the pitch in semitones", -12, 12};
paramMap["Resample"] = {"FXSwitch", "", "Resample to change how your voice sounds repitched. Turn it off if you want your voice to still be recognizable.", 0, 0};
}

void Repitcher::Process(float *buf) {
Expand All @@ -17,13 +18,17 @@ void Repitcher::Reset(int framesPerBuffer) {
float Repitcher::Get(std::string item) {
if (item == "Pitch")
return ps->getRepitchFactor(); // will need to be rounded when received on the other end
else if (item == "Resample")
return ps->getRepitchResample() ? 1.f : 0.f;

return 0.f;
}

void Repitcher::Set(std::string item, int val) {
if (item == "Pitch")
ps->setRepitchFactor(pow(2, val / 12)); // convert val (semitones) to frequency scalar
ps->setRepitchFactor(pow(2, (float)val / 12.f)); // convert val (semitones) to frequency scalar
else if (item == "Resample")
ps->setRepitchResample((bool)val);
}

bool Repitcher::GetEnabled() {
Expand Down
Binary file modified images/modkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/padding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/soundboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions interface/baseinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ json BaseInterface::GetSetting(std::string path) {
obj = obj[path.substr(0, path.find('/'))];
path = path.substr(path.find('/') + 1);
}
if (obj[path].is_null()) {
obj[path] = 0;
SaveSettings();
}

return obj[path];
}
Expand Down
2 changes: 1 addition & 1 deletion interface/baseinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BaseInterface
std::string rootDir = "";
std::string dataPath = "";
json settings = NULL;
//json defaultObj = R"({})"_json;
//sjson defaultObj = R"({})"_json;
};

#endif // BASEINTERFACE_H
2 changes: 0 additions & 2 deletions interface/basemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ struct RebindData {
int keycode;
};

//template <typename T> {};

class BaseManager : public BaseInterface
{
public:
Expand Down
32 changes: 2 additions & 30 deletions interface/fxmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,6 @@
FXManager::FXManager(std::string rootDir, int framesPerBuffer, int sampleRate) : BaseManager(rootDir), framesPerBuffer(framesPerBuffer), sampleRate(sampleRate)
{
ps.reset(new PitchShifter(2048, framesPerBuffer, sampleRate));
/*SF_INFO info = {};
info.format = 0;
SNDFILE *inputFile = sf_open((rootDir + "/samples/3.mp3").c_str(), SFM_READ, &info);
SF_INFO outInfo = {};
outInfo.channels = 1;
outInfo.samplerate = info.samplerate;
outInfo.format = info.format;
SNDFILE *outputFile = sf_open((rootDir + "/samples/3-autotuned.mp3").c_str(), SFM_WRITE, &outInfo);
sf_count_t count = 0;
float *in = new float[4096], *out = new float[2048];
int total = 0;
while (true) {
count = sf_read_float(inputFile, in, 4096);
for (int i = 0; i < 2048; i++) {
out[i] = in[2*i] + in[2*i+1];
}
ps->process(out);
//std::cout<<count<<std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(80));
if (total >= 2048 * 3) {
sf_write_float(outputFile, out, count / 2);
} else {
total+=2048;
}
//std::cout<<count<<std::endl;
if (count < 4096) break;
}
sf_close(inputFile);
sf_close(outputFile);*/
fxs.insert({"Repitcher", std::unique_ptr<IAudioFX>(new Repitcher(ps))});
fxs.insert({"Autotuner", std::unique_ptr<IAudioFX>(new Autotuner(ps))});
fxs.insert({"Reverberator", std::unique_ptr<IAudioFX>(new Reverberator(framesPerBuffer))});
Expand All @@ -56,7 +27,8 @@ FXManager::FXManager(std::string rootDir, int framesPerBuffer, int sampleRate) :
},
"Repitcher": {
"enabled": false,
"Pitch": 0
"Pitch": 0,
"Resample": 0
}
})"_json;

Expand Down
2 changes: 1 addition & 1 deletion interface/maininterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MAININTERFACE_H

#ifndef VER_NO
#define VER_NO "0.2.1"
#define VER_NO "0.3"
#endif

#ifndef ROOTNAME
Expand Down
2 changes: 2 additions & 0 deletions rc.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@
<file>rc/common/down_arrow_on.png</file>
<file>rc/common/up_arrow_off.png</file>
<file>rc/common/up_arrow_on.png</file>
<file>rc/fxMenu/toggleBasicOff.png</file>
<file>rc/fxMenu/toggleBasicOn.png</file>
</qresource>
</RCC>
Binary file added rc/common/down_arrow_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/common/down_arrow_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/common/up_arrow_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/common/up_arrow_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/fxMenu/toggleBasicOff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/fxMenu/toggleBasicOn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
<property name="styleSheet">
<string notr="true">background-color: #101010;
color: #D0D0D0;
font-family: &quot;Segoe UI&quot;;</string>
font-family: &quot;Segoe UI&quot;;
</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QGroupBox" name="sidebar">
Expand Down
2 changes: 2 additions & 0 deletions ui/menus/fxmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ FXMenu::FXMenu(std::shared_ptr<FXManager> fm, QWidget *parent) :
fxp = new FXDial(fm, fx, param, widget.unit, nullptr, widget.min, widget.max);
else if (widget.type == "FXKeyPicker")
fxp = new FXKeyPicker(fm, fx, param, nullptr);
else if (widget.type == "FXSwitch")
fxp = new FXSwitch(fm, fx, param, nullptr);

if (fxp != nullptr) {
fxp->setToolTip(QString::fromStdString(widget.toolTip));
Expand Down
1 change: 1 addition & 0 deletions ui/menus/fxmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../widgets/hotkeylistwidget.h"
#include "../widgets/fx/fxdial.h"
#include "../widgets/fx/fxkeypicker.h"
#include "../widgets/fx/fxswitch.h"
#include "../interface/fxmanager.h"

namespace Ui {
Expand Down
39 changes: 38 additions & 1 deletion ui/menus/settingsmenu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,44 @@
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true"/>
<string notr="true">QComboBox {
background-color: #282828;
border: 0px;
border-radius: 3px;
padding: 2px 33px 2px 5px;
}

QComboBox:editable {
background: #101010;
}

QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 30px;
background-color: #303030;
border-top-right-radius: 3px; /* same radius as the QComboBox */
border-bottom-right-radius: 3px;
}

QComboBox::drop-down:hover {
background-color: #383838;
}

QComboBox::down-arrow {
image: url(&quot;:/rc/common/down_arrow_on.png&quot;);
top: 2px;
width: 16px;
height: 16px;
}

QComboBox QAbstractItemView {
border: 0px;
border-top: 1px solid #282828;
background-color: #282828;
selection-background-color: #383838;
}
</string>
</property>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
Expand Down
2 changes: 0 additions & 2 deletions ui/widgets/fx/fxdial.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class FXDial : public FXParam

void setValue(int val) override;

signals:

protected:
void resizeEvent(QResizeEvent *event) override;

Expand Down
43 changes: 43 additions & 0 deletions ui/widgets/fx/fxswitch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "fxswitch.h"
#include "ui_fxswitch.h"

FXSwitch::FXSwitch(std::shared_ptr<FXManager> fm,
std::string fx,
std::string param,
QWidget *parent) :
FXParam(fm, fx, param, parent),
ui(new Ui::FXSwitch)
{
ui->setupUi(this);

connect(ui->toggle, SIGNAL(stateChanged(int)), this, SLOT(onToggled(int)));

ui->title->setText(QString::fromStdString(param));
ui->indicator->setEnabled(false);

resetIdx();
}

FXSwitch::~FXSwitch()
{
delete ui;
}

void FXSwitch::setValue(int val) {
ui->toggle->setCheckState(val == 0 ? Qt::CheckState::Unchecked : Qt::CheckState::Checked);
}

void FXSwitch::resizeEvent(QResizeEvent *event) {
ui->toggle->move((this->width() / 2) - (ui->toggle->width() / 2), ui->toggle->y());
ui->indicator->move((this->width() / 2) - (ui->indicator->width() / 2), ui->indicator->y());
ui->title->resize(this->width(), ui->title->height());
FXParam::resizeEvent(event);
}

void FXSwitch::onToggled(int val) {
if (idx == -1) return;
ui->indicator->setCheckState((Qt::CheckState)val);
val = val == 0 ? 0 : 1;
fm->UpdateSettings<int>(getPath(), val);
fm->ApplyFXSettings({{fx, {{param, val}}}});
}
34 changes: 34 additions & 0 deletions ui/widgets/fx/fxswitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef FXSWITCH_H
#define FXSWITCH_H

#include <QWidget>
#include "fxparam.h"

namespace Ui {
class FXSwitch;
}

class FXSwitch : public FXParam
{
Q_OBJECT

public:
explicit FXSwitch(std::shared_ptr<FXManager> fm,
std::string fx,
std::string param,
QWidget *parent = nullptr);
~FXSwitch();

void setValue(int val) override;

protected:
void resizeEvent(QResizeEvent *event) override;

private slots:
void onToggled(int val);

private:
Ui::FXSwitch *ui;
};

#endif // FXSWITCH_H
Loading

0 comments on commit 17b3ce4

Please sign in to comment.