diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 1d4e3ba..ef63121 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -132,6 +132,9 @@ void nam::convnet::ConvNet::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const // Copy to required output array (TODO tighten this up) for (int s = 0; s < num_frames; s++) output[s] = this->_head_output(s); + + // Prepare for next call: + nam::Buffer::_advance_input_buffer_(num_frames); } void nam::convnet::ConvNet::_verify_weights(const int channels, const std::vector& dilations, const bool batchnorm, diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index d068eed..c94cb73 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -31,7 +31,6 @@ void nam::DSP::prewarm() for (long i = 0; i < _prewarm_samples; i++) { this->process(sample_ptr, sample_ptr, 1); - this->finalize_(1); sample = 0; } } @@ -58,8 +57,6 @@ void nam::DSP::SetLoudness(const double loudness) mHasLoudness = true; } -void nam::DSP::finalize_(const int num_frames) {} - // Buffer ===================================================================== nam::Buffer::Buffer(const int receptive_field, const double expected_sample_rate) @@ -128,9 +125,8 @@ void nam::Buffer::_reset_input_buffer() this->_input_buffer_offset = this->_receptive_field; } -void nam::Buffer::finalize_(const int num_frames) +void nam::Buffer::_advance_input_buffer_(const int num_frames) { - this->nam::DSP::finalize_(num_frames); this->_input_buffer_offset += num_frames; } @@ -163,6 +159,9 @@ void nam::Linear::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_f auto input = Eigen::Map(&this->_input_buffer[offset], this->_receptive_field); output[i] = this->_bias + this->_weight.dot(input); } + + // Prepare for next call: + nam::Buffer::_advance_input_buffer_(num_frames); } // NN modules ================================================================= diff --git a/NAM/dsp.h b/NAM/dsp.h index d55941f..fd176da 100644 --- a/NAM/dsp.h +++ b/NAM/dsp.h @@ -52,10 +52,6 @@ class DSP // overridden in subclasses). // 2. The output level is applied and the result stored to `output`. virtual void process(NAM_SAMPLE* input, NAM_SAMPLE* output, const int num_frames); - // Anything to take care of before next buffer comes in. - // For example: - // * Move the buffer index forward - virtual void finalize_(const int num_frames); // Expected sample rate, in Hz. // TODO throw if it doesn't know. double GetExpectedSampleRate() const { return mExpectedSampleRate; }; @@ -86,7 +82,6 @@ class Buffer : public DSP { public: Buffer(const int receptive_field, const double expected_sample_rate = -1.0); - void finalize_(const int num_frames); protected: // Input buffer @@ -97,6 +92,7 @@ class Buffer : public DSP std::vector _input_buffer; std::vector _output_buffer; + void _advance_input_buffer_(const int num_frames); void _set_receptive_field(const int new_receptive_field, const int input_buffer_size); void _set_receptive_field(const int new_receptive_field); void _reset_input_buffer(); diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index 6ecec56..6941f81 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -30,7 +30,6 @@ void nam::wavenet::_Layer::process_(const Eigen::MatrixXf& input, const Eigen::M // Mix-in condition this->_z += this->_input_mixin.process(condition); - if (!this->_gated) { @@ -40,7 +39,8 @@ void nam::wavenet::_Layer::process_(const Eigen::MatrixXf& input, const Eigen::M { this->_activation->apply(this->_z.topRows(channels)); activations::Activation::get_activation("Sigmoid")->apply(this->_z.bottomRows(channels)); - //activations::Activation::get_activation("Sigmoid")->apply(this->_z.block(channels, 0, channels, this->_z.cols())); + // activations::Activation::get_activation("Sigmoid")->apply(this->_z.block(channels, 0, channels, + // this->_z.cols())); this->_z.topRows(channels).array() *= this->_z.bottomRows(channels).array(); // this->_z.topRows(channels) = this->_z.topRows(channels).cwiseProduct( @@ -272,12 +272,6 @@ nam::wavenet::WaveNet::WaveNet(const std::vector _prewarm_samples += this->_layer_arrays[i].get_receptive_field(); } -void nam::wavenet::WaveNet::finalize_(const int num_frames) -{ - this->DSP::finalize_(num_frames); - this->_advance_buffers_(num_frames); -} - void nam::wavenet::WaveNet::set_weights_(std::vector& weights) { std::vector::iterator it = weights.begin(); @@ -347,6 +341,9 @@ void nam::wavenet::WaveNet::process(NAM_SAMPLE* input, NAM_SAMPLE* output, const float out = this->_head_scale * this->_head_arrays[final_head_array](0, s); output[s] = out; } + + // Finalize to rpepare for the next call: + this->_advance_buffers_(num_frames); } void nam::wavenet::WaveNet::_set_num_frames_(const long num_frames) diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 9441587..745b3e7 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -171,7 +171,6 @@ class WaveNet : public DSP std::vector weights, const double expected_sample_rate = -1.0); ~WaveNet() = default; - void finalize_(const int num_frames) override; void set_weights_(std::vector& weights); private: diff --git a/tools/benchmodel.cpp b/tools/benchmodel.cpp index 46178d2..4b1c3e3 100644 --- a/tools/benchmodel.cpp +++ b/tools/benchmodel.cpp @@ -46,7 +46,6 @@ int main(int argc, char* argv[]) for (size_t i = 0; i < numBuffers; i++) { model->process(buffer, buffer, AUDIO_BUFFER_SIZE); - model->finalize_(AUDIO_BUFFER_SIZE); } std::cout << "Finished\n";