diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 057af4a..38c5a39 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -171,10 +171,6 @@ bool Application::initGLFW() { glfwMakeContextCurrent(m_window); #ifdef __EMSCRIPTEN__ - // Register mouseup event on the window object to register if a slider is released - // when the mouse is outside of the window. - emscripten_set_mouseup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, - emsMouseCallback); #else // Register content scale events. glfwSetWindowContentScaleCallback(m_window, glfwScaleCallback); @@ -223,6 +219,11 @@ bool Application::setupImGui() { // Register HTML5 events on Emscripten. emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, emsUiCallback); + + // Register mouseup event on the window object to register if a slider is released + // when the mouse is outside of the window. + emscripten_set_mouseup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, + emsMouseCallback); #endif return true; diff --git a/src/app/GeneratorSpectrum.cpp b/src/app/GeneratorSpectrum.cpp index a09bb04..fe48766 100644 --- a/src/app/GeneratorSpectrum.cpp +++ b/src/app/GeneratorSpectrum.cpp @@ -99,7 +99,11 @@ void GeneratorSpectrum::constructWindow() { m_window.resize(m_nfft); m_values.resize(m_nfft); +#ifdef __EMSCRIPTEN__ + m_window = windows::blackmanHarris(m_nfft, true); +#else m_window = windows::chebwin(m_nfft, 320, true); +#endif } void GeneratorSpectrum::constructFrequencyArray() { diff --git a/src/app/GlottalFlow.cpp b/src/app/GlottalFlow.cpp index 390fb78..d91ac33 100644 --- a/src/app/GlottalFlow.cpp +++ b/src/app/GlottalFlow.cpp @@ -90,7 +90,7 @@ void GlottalFlow::updateSamples() { m_flow[i] = gauss_kronrod::integrate( [this](double t) -> double { return m_model->evaluate(t); }, 0, m_times[i], 8, 1e-6); - #elif defined(USING_DOUBLE_FLOAT) m_flow[i] = + #elif defined(USING_DOUBLE_FLOAT) gauss_kronrod::integrate( [this](double t) -> double { return m_model->evaluate(t); }, 0, m_times[i], 15, 1e-6); diff --git a/src/app/SourceModelApp.cpp b/src/app/SourceModelApp.cpp index 3edadd4..80e6b50 100644 --- a/src/app/SourceModelApp.cpp +++ b/src/app/SourceModelApp.cpp @@ -26,7 +26,9 @@ SourceModelApp::SourceModelApp(const int initialWidth, const int initialHeight) m_showAdvancedSourceParams(false), m_doBypassFilter(false), m_doNormalizeFlowPlot(true), - m_spectrumFrequencyScale(FrequencyScale_Mel) { + m_spectrumFrequencyScale(FrequencyScale_Mel), + m_logVolume(90), + m_linVolume(0.6561) { ImPlot::CreateContext(); m_audioOutput.setBufferCallback([this](std::vector& out) { @@ -41,14 +43,15 @@ SourceModelApp::SourceModelApp(const int initialWidth, const int initialHeight) } else { m_formantGenerator.fillBuffer(out); } + for (auto& x : out) x *= m_linVolume; return true; }); m_glottalFlow.setSampleCount(1024); m_glottalFlow.setModelType(GlottalFlowModel_LF); // Default model to LF. - m_sourceSpectrum.setResponseTime(0.025); - m_formantSpectrum.setResponseTime(0.025); + m_sourceSpectrum.setResponseTime(0.00125); + m_formantSpectrum.setResponseTime(0.00125); m_sourceSpectrum.setTransformSize(4096); m_formantSpectrum.setTransformSize(4096); @@ -118,6 +121,14 @@ void SourceModelApp::renderMenuBar() { ImGui::Separator(); + ImGui::SetNextItemWidth(5 * em()); + if (ImGui::SliderFloatOrDouble("##Volume", &m_logVolume, 0.0_f, 100.0_f, "%.0f %%")) { + // Using x^4 as an approximation. + m_linVolume = std::pow(m_logVolume / 100.0_f, 4.0_f); + } + + ImGui::Separator(); + // No point in showing audio settings on Web if (ImGui::BeginMenu("Audio settings")) { #ifdef USING_RTAUDIO diff --git a/src/app/SourceModelApp.h b/src/app/SourceModelApp.h index c0cc856..a5d4b67 100644 --- a/src/app/SourceModelApp.h +++ b/src/app/SourceModelApp.h @@ -112,6 +112,8 @@ class SourceModelApp : public Application { bool m_doBypassFilter; bool m_doNormalizeFlowPlot; FrequencyScale m_spectrumFrequencyScale; + Scalar m_logVolume; + Scalar m_linVolume; }; #endif // SOURCEMODEL__SOURCEMODELAPP_H \ No newline at end of file diff --git a/src/app/math/windows.h b/src/app/math/windows.h index 73127f3..357d6c7 100644 --- a/src/app/math/windows.h +++ b/src/app/math/windows.h @@ -1,6 +1,7 @@ #ifndef SOURCEMODEL__MATH_WINDOWS_H #define SOURCEMODEL__MATH_WINDOWS_H +#include #include #include #include @@ -66,7 +67,7 @@ class linspace { // Sum-of-cosine templates template inline T cosineSum(T x) { - constexpr size_t n = std::tuple_size::value; + constexpr size_t n(coefs.size()); T v(coefs[0]); int s = -1; for (size_t i = 1; i < n; ++i) { @@ -267,7 +268,7 @@ std::vector chebwin(int M, const T at, const bool sym = true) { // Compute the parameter beta const T order = M - 1; - const T beta = std::cosh(1.0 / order * acosh(std::pow(10.0, std::abs(at) / 20.0))); + const T beta = std::cosh(T(1) / order * acosh(std::pow(T(10), std::abs(at) / T(20)))); std::vector x(M); for (int i = 0; i < M; ++i) { x[i] = beta * cos_pi(T(i) / T(M));