-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add low latency mode #2 * Update DelayedCore.cpp * Report effect delay #2 * Fix DelayedCore * Fix missing typecast * Fix latency callback * Fix span * Fix latency callback * Use symmetric window in delayed core * Fix latency callback * Update InstantCore.cpp * Delete audacity plugin cache * Update screenshot.png * Update MANUAL.md * Log latency * Fix typecast
- Loading branch information
Showing
14 changed files
with
281 additions
and
102 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,69 @@ | ||
#include <StftPitchShiftPlugin/Core/DelayedCore.h> | ||
|
||
DelayedCore::DelayedCore(const double samplerate, const int blocksize, const int dftsize, const int overlap) : | ||
InstantCore(samplerate, dftsize + dftsize, dftsize, overlap), host_block_size(blocksize) | ||
{ | ||
const auto total_buffer_size = analysis_window_size + synthesis_window_size; | ||
|
||
buffer.input.resize(total_buffer_size); | ||
buffer.output.resize(total_buffer_size); | ||
|
||
samples = 0; | ||
} | ||
|
||
DelayedCore::~DelayedCore() | ||
{ | ||
} | ||
|
||
int DelayedCore::latency() const | ||
{ | ||
return 6 * dftsize - host_block_size; | ||
} | ||
|
||
bool DelayedCore::compatible(const int blocksize) const | ||
{ | ||
return static_cast<size_t>(blocksize) <= synthesis_window_size; | ||
} | ||
|
||
void DelayedCore::process(const std::span<const float> input, const std::span<float> output) | ||
{ | ||
const auto minsamples = input.size(); | ||
const auto maxsamples = synthesis_window_size; | ||
|
||
// shift input buffer | ||
std::copy( | ||
buffer.input.begin() + minsamples, | ||
buffer.input.end(), | ||
buffer.input.begin()); | ||
|
||
// copy new input samples | ||
std::copy( | ||
input.begin(), | ||
input.end(), | ||
buffer.input.end() - minsamples); | ||
|
||
// start processing as soon as enough samples are buffered | ||
if ((samples += minsamples) >= maxsamples) | ||
{ | ||
const auto x = buffer.input.data() + buffer.input.size(); | ||
const auto y = buffer.output.data() + buffer.output.size(); | ||
|
||
InstantCore::process( | ||
std::span(x - samples, maxsamples), | ||
std::span(y - samples, maxsamples)); | ||
|
||
samples %= maxsamples; | ||
} | ||
|
||
// copy new output samples back | ||
std::copy( | ||
buffer.output.begin(), | ||
buffer.output.begin() + minsamples, | ||
output.begin()); | ||
|
||
// shift output buffer | ||
std::copy( | ||
buffer.output.begin() + minsamples, | ||
buffer.output.end(), | ||
buffer.output.begin()); | ||
} |
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,25 @@ | ||
#pragma once | ||
|
||
#include <StftPitchShiftPlugin/Core/InstantCore.h> | ||
|
||
class DelayedCore : public InstantCore | ||
{ | ||
|
||
public: | ||
|
||
DelayedCore(const double samplerate, const int blocksize, const int dftsize, const int overlap); | ||
~DelayedCore(); | ||
|
||
int latency() const override; | ||
bool compatible(const int blocksize) const override; | ||
void process(const std::span<const float> input, const std::span<float> output) override; | ||
|
||
private: | ||
|
||
const int host_block_size; | ||
|
||
struct { std::vector<float> input, output; } buffer; | ||
|
||
size_t samples; | ||
|
||
}; |
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,62 @@ | ||
#include <StftPitchShiftPlugin/Core/InstantCore.h> | ||
|
||
InstantCore::InstantCore(const double samplerate, const int blocksize, const int dftsize, const int overlap) : | ||
Core(samplerate, blocksize, dftsize, overlap) | ||
{ | ||
const auto total_buffer_size = analysis_window_size + synthesis_window_size; | ||
|
||
buffer.input.resize(total_buffer_size); | ||
buffer.output.resize(total_buffer_size); | ||
} | ||
|
||
InstantCore::~InstantCore() | ||
{ | ||
} | ||
|
||
int InstantCore::latency() const | ||
{ | ||
return static_cast<int>(synthesis_window_size); | ||
} | ||
|
||
bool InstantCore::compatible(const int blocksize) const | ||
{ | ||
return static_cast<size_t>(blocksize) == synthesis_window_size; | ||
} | ||
|
||
void InstantCore::process(const std::span<const float> input, const std::span<float> output) | ||
{ | ||
// shift input buffer | ||
std::copy( | ||
buffer.input.begin() + synthesis_window_size, | ||
buffer.input.end(), | ||
buffer.input.begin()); | ||
|
||
// copy new input samples | ||
std::transform( | ||
input.begin(), | ||
input.end(), | ||
buffer.input.begin() + analysis_window_size, | ||
transform<float, double>); | ||
|
||
// apply pitch shifting within the built-in STFT routine | ||
stft_pitch_shift(buffer.input, buffer.output); | ||
|
||
// copy new output samples back | ||
std::transform( | ||
buffer.output.begin() - synthesis_window_size + analysis_window_size, | ||
buffer.output.end() - synthesis_window_size, | ||
output.begin(), | ||
transform<double, float>); | ||
|
||
// shift output buffer | ||
std::copy( | ||
buffer.output.begin() + synthesis_window_size, | ||
buffer.output.end(), | ||
buffer.output.begin()); | ||
|
||
// prepare for the next callback | ||
std::fill( | ||
buffer.output.begin() + analysis_window_size, | ||
buffer.output.end(), | ||
0); | ||
} |
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,24 @@ | ||
#pragma once | ||
|
||
#include <StftPitchShiftPlugin/Core.h> | ||
|
||
class InstantCore : public Core | ||
{ | ||
|
||
public: | ||
|
||
InstantCore(const double samplerate, const int blocksize, const int dftsize, const int overlap); | ||
~InstantCore(); | ||
|
||
int latency() const override; | ||
bool compatible(const int blocksize) const override; | ||
void process(const std::span<const float> input, const std::span<float> output) override; | ||
|
||
private: | ||
|
||
struct { std::vector<double> input, output; } buffer; | ||
|
||
template<typename X, typename Y> | ||
static Y transform(const X x) { return static_cast<Y>(x); } | ||
|
||
}; |
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
Oops, something went wrong.