closes #6
closes #9 pitch detection runs on known schedule fixed erratic pitch detection on launch
This commit is contained in:
@ -28,10 +28,10 @@ void Shifter::Init(float samplerate, int samplesPerBlock)
|
||||
{
|
||||
sample_rate_ = samplerate;
|
||||
blocksize = samplesPerBlock;
|
||||
out_midi_smoother.SetFrameTime((float)samplesPerBlock / samplerate);
|
||||
out_midi_smoother.SetFrameTime((float)256 / samplerate);
|
||||
volume = 1;
|
||||
helm.setframesize(1024);
|
||||
helm.setoverlap(1);
|
||||
helm.setoverlap(2);
|
||||
for (int i = 0; i < MAX_VOICES; ++i)
|
||||
{
|
||||
voices[i].Init(samplerate);
|
||||
@ -46,18 +46,21 @@ void Shifter::Init(float samplerate, int samplesPerBlock)
|
||||
for (int i = 0; i < 8192; ++i) {
|
||||
cos_lookup[i] = cos(2 * PI_F * i / 8192.0);
|
||||
}
|
||||
in_period = 0;
|
||||
}
|
||||
|
||||
void Shifter::Process(const float* const* in,
|
||||
float** out,
|
||||
size_t size)
|
||||
{
|
||||
DetectPitch(in, out, size);
|
||||
SetRates();
|
||||
// for (size_t i = 0; i < size; ++i) {
|
||||
// out[0][i] = 0;
|
||||
// }
|
||||
GetSamples(out, in[0], size);
|
||||
for (size_t i = 0; i < size; i += 256) {
|
||||
size_t offset = i;
|
||||
size_t lefover_size = std::min((size_t)256, size - i);
|
||||
DetectPitch(in, out, lefover_size, offset);
|
||||
SetRates();
|
||||
GetSamples(out, in[0], lefover_size, offset);
|
||||
}
|
||||
|
||||
//for (size_t i = 0; i < size; ++i)
|
||||
//{
|
||||
// // out[0][i] = osc.Process();
|
||||
@ -78,7 +81,7 @@ float findMedian(float a, float b, float c) {
|
||||
}
|
||||
|
||||
|
||||
void Shifter::DetectPitch(const float* const* in, float** out, size_t size)
|
||||
void Shifter::DetectPitch(const float* const* in, float** out, size_t size, size_t offset)
|
||||
{
|
||||
// detect current pitch
|
||||
// pitch_detect.update(in[0], size);
|
||||
@ -97,16 +100,16 @@ void Shifter::DetectPitch(const float* const* in, float** out, size_t size)
|
||||
// current_pitch = findMedian(last_freqs[0], last_freqs[1], last_freqs[2]);
|
||||
// in_period = 1.0 / current_pitch * 48000;
|
||||
|
||||
helm.iosamples(in[0], out[0], size);
|
||||
helm.iosamples(in[0]+offset, out[0]+offset, size);
|
||||
float period = helm.getperiod();
|
||||
float fidel = helm.getfidelity();
|
||||
//DBG("frequency: " << 48000 / period << " fidel: " << fidel);
|
||||
|
||||
// Adjustable filter amount (0.0f = no filtering, 1.0f = max filtering)
|
||||
static float in_period_filter_amount = 0.5f; // You can expose this as a parameter
|
||||
const float in_period_filter_amount = 0.5f; // You can expose this as a parameter
|
||||
|
||||
if (fidel > 0.95) {
|
||||
// Smoothly filter in_period changes
|
||||
// Smoothly filter in_`period changes
|
||||
in_period = in_period * in_period_filter_amount + period * (1.0f - in_period_filter_amount);
|
||||
}
|
||||
float in_freq = sample_rate_ / in_period;
|
||||
@ -201,7 +204,7 @@ void Shifter::AddInterpolatedFrame(int voice, int max_index, float resampling_pe
|
||||
}
|
||||
}
|
||||
|
||||
void Shifter::GetSamples(float** output, const float* input, size_t size)
|
||||
void Shifter::GetSamples(float** output, const float* input, size_t size, size_t offset)
|
||||
{
|
||||
if (freeze_needs_copy) {
|
||||
freeze_needs_copy = false;
|
||||
@ -273,13 +276,13 @@ void Shifter::GetSamples(float** output, const float* input, size_t size)
|
||||
|
||||
|
||||
//add input samples
|
||||
in_buffer[in_playhead] = input[i];
|
||||
in_buffer[in_playhead] = input[i+offset];
|
||||
|
||||
//output samples, set to 0
|
||||
for (int ch = 0; ch < 2; ++ch) {
|
||||
output[ch][i] = out_buffer[ch][out_playhead];
|
||||
output[ch][i+offset] = out_buffer[ch][out_playhead];
|
||||
if (!enable_autotune) {
|
||||
output[ch][i] += input[i] * melody_mix;
|
||||
output[ch][i+offset] += input[i+offset] * melody_mix;
|
||||
}
|
||||
out_buffer[ch][out_playhead] = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user