From b1d5b8aeabe45a8eb5e1ec7e312aca335f3c5f0d Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 1 Apr 2015 23:18:46 +0200 Subject: [PATCH] [DEV] set theoric calculation. --- drain/Equalizer.cpp | 15 ++ drain/Equalizer.h | 3 + tools/drainBiQuadProfiling/appl/Windows.cpp | 18 +- .../drainEqualizerProfiling/appl/Windows.cpp | 237 +++++++----------- tools/drainEqualizerProfiling/appl/Windows.h | 47 +++- .../appl/widget/DisplayFrequency.cpp | 17 +- tools/drainEqualizerProfiling/data/gui.xml | 62 +++-- 7 files changed, 203 insertions(+), 196 deletions(-) diff --git a/drain/Equalizer.cpp b/drain/Equalizer.cpp index 6208877..7143853 100644 --- a/drain/Equalizer.cpp +++ b/drain/Equalizer.cpp @@ -169,3 +169,18 @@ void drain::Equalizer::configureBiQuad() { } return; } + +std::vector > drain::Equalizer::calculateTheory() { + std::vector > out; + for (size_t iii=0; iii > tmp = m_biquads[0][iii].calculateTheory(getOutputFormat().getFrequency()); + for (size_t jjj=0; jjj< out.size(); ++jjj) { + out[jjj].second += tmp[jjj].second; + } + } + } + return out; +} \ No newline at end of file diff --git a/drain/Equalizer.h b/drain/Equalizer.h index 576202a..8b9ba38 100644 --- a/drain/Equalizer.h +++ b/drain/Equalizer.h @@ -52,6 +52,9 @@ namespace drain { * @brief Configure biquad with the user spec. */ void configureBiQuad(); + public: + // for debug & tools only + std::vector > calculateTheory(); }; }; diff --git a/tools/drainBiQuadProfiling/appl/Windows.cpp b/tools/drainBiQuadProfiling/appl/Windows.cpp index 2ce8b91..ca5980f 100644 --- a/tools/drainBiQuadProfiling/appl/Windows.cpp +++ b/tools/drainBiQuadProfiling/appl/Windows.cpp @@ -228,7 +228,7 @@ void appl::Windows::onCallbackStart16() { bq.setBiquad(m_type, m_cutFrequency, m_quality, m_gain, m_sampleRate); std::vector > pratic; size_t len = 512; - for (size_t iii=0; iii < len; iii++) { + for (size_t iii=1; iii < len; iii++) { float freq = iii / (len - 1.0) * m_sampleRate / 2.0; // To reset filter bq.reset(); @@ -250,11 +250,11 @@ void appl::Windows::onCallbackStart16() { void* outputVoid = nullptr; size_t outputNbChunk = 0; std11::chrono::system_clock::time_point time; - //RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_INPUT_16.raw",&data[0],data.size()); + RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_INPUT_16.raw",&data[0],data.size()); bq.processInt16(&data[0], &data[0], data.size(), 1, 1); - //RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT_16.raw",&data[0],data.size()); + RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT_16.raw",&data[0],data.size()); int16_t value = 0; - for (size_t iii=200; iii > pratic; size_t len = 512; - for (size_t iii=0; iii < len; iii++) { + for (size_t iii=1; iii < len; iii++) { float freq = iii / (len - 1.0) * m_sampleRate / 2.0; // To reset filter bq.reset(); @@ -289,11 +289,11 @@ void appl::Windows::onCallbackStartFloat() { m_phase -= 2*M_PI; } } - //RIVER_SAVE_FILE_MACRO(float,"aaa_test_INPUT_F.raw",&data[0],data.size()); + RIVER_SAVE_FILE_MACRO(float,"aaa_test_INPUT_F.raw",&data[0],data.size()); bq.processFloat(&data[0], &data[0], data.size(), 1, 1); - //RIVER_SAVE_FILE_MACRO(float,"aaa_test_OUTPUT_F.raw",&data[0],data.size()); - float value = 0; - for (size_t iii=200; iii=0) { - m_type = m_listType[iii]; - } else { - m_type = m_listType[m_listType.size()-1]; - } - ewol::parameterSetOnObjectNamed("type", "value", etk::to_string(m_type)); - onCallbackStart(); - return; - } - } - m_type = m_listType[0]; - ewol::parameterSetOnObjectNamed("type", "value", etk::to_string(m_type)); - onCallbackStart(); -} - - -void appl::Windows::onCallbackGain(const std::string& _value) { - m_gain = etk::string_to_float(_value); - ewol::parameterSetOnObjectNamed("gain-slider", "value", etk::to_string(_value)); - APPL_INFO("Gain " << m_gain); - onCallbackStart(); -} - -void appl::Windows::onCallbackGainSlider(const float& _value) { - m_gain = _value; - ewol::parameterSetOnObjectNamed("gain", "value", etk::to_string(_value)); - APPL_INFO("Gain " << m_gain); - onCallbackStart(); -} - - - -void appl::Windows::onCallbackQuality(const std::string& _value) { - m_quality = etk::string_to_float(_value); - ewol::parameterSetOnObjectNamed("quality-slider", "value", etk::to_string(_value)); - APPL_INFO("quality " << m_quality); - onCallbackStart(); -} - -void appl::Windows::onCallbackQualitySlider(const float& _value) { - m_quality = _value; - ewol::parameterSetOnObjectNamed("quality", "value", etk::to_string(_value)); - APPL_INFO("quality " << m_quality); - onCallbackStart(); -} - - -void appl::Windows::onCallbackFrequency(const std::string& _value) { - m_cutFrequency = etk::string_to_float(_value); - ewol::parameterSetOnObjectNamed("frequency-slider", "value", etk::to_string(_value)); - APPL_INFO("cut frequency " << m_cutFrequency); - onCallbackStart(); -} - -void appl::Windows::onCallbackFrequencySlider(const float& _value) { - m_cutFrequency = _value; - ewol::parameterSetOnObjectNamed("frequency", "value", etk::to_string(_value)); - APPL_INFO("cut frequency " << m_cutFrequency); - onCallbackStart(); -} #include -void appl::Windows::onCallbackStart() { - APPL_INFO("start "); - int32_t iii = 10; +std11::shared_ptr appl::Windows::createEqualizer(enum audio::format _format) { std::vector map; map.push_back(audio::channel_frontCenter); - //drain::IOFormatInterface format(map, audio::format_int16, m_sampleRate); - drain::IOFormatInterface format(map, audio::format_float, m_sampleRate); - // create biquad - drain::BiQuadFloat bq; - // configure parameter - bq.setBiquad(m_type, m_cutFrequency, m_quality, m_gain, m_sampleRate); - std::vector > theory = bq.calculateTheory(m_sampleRate); + drain::IOFormatInterface format(map, _format, m_sampleRate); + // create equalizer + std11::shared_ptr out = drain::Equalizer::create(); + // configure input + out->setInputFormat(format); + // configure output + out->setOutputFormat(format); + // create ejson: + std::string conf; + conf += "{\n"; + conf += " global: [\n"; + for (size_t iii=3; iiisetParameter("config", conf); + return out; +} + +void appl::Windows::onCallbackStart() { + APPL_INFO("start "); + std11::shared_ptr eq = appl::Windows::createEqualizer(); + std::vector > theory = eq->calculateTheory(); m_displayer->clear(); m_displayer->setValue(theory); } @@ -222,22 +169,18 @@ void appl::Windows::onCallbackStart() { void appl::Windows::onCallbackStart16() { APPL_INFO("start "); - // create biquad - drain::BiQuadFloat bq; - // configure parameter - bq.setBiquad(m_type, m_cutFrequency, m_quality, m_gain, m_sampleRate); + std11::shared_ptr eq = appl::Windows::createEqualizer(audio::format_int16); std::vector > pratic; size_t len = 512; - for (size_t iii=0; iii < len; iii++) { + std::vector data; + data.resize(16000, 0); + for (size_t iii=1; iii < len; iii++) { float freq = iii / (len - 1.0) * m_sampleRate / 2.0; // To reset filter - bq.reset(); + eq->setParameter("reset", ""); double m_phase = 0; double baseCycle = 2.0*M_PI/double(m_sampleRate) * double(freq); float gain = 0; - std::vector data; - // create sinus - data.resize(16000, 0); for (int32_t iii=0; iiiprocess(time, &data[0], data.size(), outputVoid, outputNbChunk); + output = static_cast(outputVoid); + RIVER_SAVE_FILE_MACRO(int16_t, "aaa_test_OUTPUT.raw", output, outputNbChunk); int16_t value = 0; - for (size_t iii=200; iii eq = appl::Windows::createEqualizer(audio::format_float); std::vector > pratic; size_t len = 512; - for (size_t iii=0; iii < len; iii++) { + std::vector data; + data.resize(16000, 0); + for (size_t iii=1; iii < len; iii++) { float freq = iii / (len - 1.0) * m_sampleRate / 2.0; // To reset filter - bq.reset(); + eq->setParameter("reset", ""); double m_phase = 0; double baseCycle = 2.0*M_PI/double(m_sampleRate) * double(freq); float gain = 0; - std::vector data; - // create sinus - data.resize(16000, 0); for (int32_t iii=0; iiiprocess(time, &data[0], data.size(), outputVoid, outputNbChunk); + output = static_cast(outputVoid); + RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT_F.raw",output, outputNbChunk); float value = 0; - for (size_t iii=200; iiisetValue(pratic); } - diff --git a/tools/drainEqualizerProfiling/appl/Windows.h b/tools/drainEqualizerProfiling/appl/Windows.h index ca3f173..7eb1c86 100644 --- a/tools/drainEqualizerProfiling/appl/Windows.h +++ b/tools/drainEqualizerProfiling/appl/Windows.h @@ -27,25 +27,46 @@ namespace appl { std::shared_ptr m_displayer; void onCallbackSampleRateLow(); void onCallbackSampleRateUp(); - void onCallbackTypeUp(); - void onCallbackTypeLow(); - void onCallbackGain(const std::string& _value); - void onCallbackGainSlider(const float& _value); - void onCallbackFrequency(const std::string& _value); - void onCallbackFrequencySlider(const float& _value); - void onCallbackQuality(const std::string& _value); - void onCallbackQualitySlider(const float& _value); + void onCallbackGain0(const float& _value) { + onCallbackGain(_value, 0); + } + void onCallbackGain1(const float& _value) { + onCallbackGain(_value, 1); + } + void onCallbackGain2(const float& _value) { + onCallbackGain(_value, 2); + } + void onCallbackGain3(const float& _value) { + onCallbackGain(_value, 3); + } + void onCallbackGain4(const float& _value) { + onCallbackGain(_value, 4); + } + void onCallbackGain5(const float& _value) { + onCallbackGain(_value, 5); + } + void onCallbackGain6(const float& _value) { + onCallbackGain(_value, 6); + } + void onCallbackGain7(const float& _value) { + onCallbackGain(_value, 7); + } + void onCallbackGain8(const float& _value) { + onCallbackGain(_value, 8); + } + void onCallbackGain9(const float& _value) { + onCallbackGain(_value, 9); + } + void onCallbackGain(const float& _value, int32_t _id); void onCallbackStart(); void onCallbackStart16(); void onCallbackStartFloat(); protected: int32_t m_sampleRate; std::vector m_listSampleRate; - enum drain::filterType m_type; - std::vector m_listType; - float m_cutFrequency; - float m_gain; - float m_quality; + + std::vector m_listGain; + std11::shared_ptr createEqualizer(enum audio::format _format = audio::format_float); }; }; diff --git a/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp b/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp index 84c971e..6911aaa 100644 --- a/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp +++ b/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp @@ -92,6 +92,7 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() { if (std::abs(m_data[kkk][iii].second) != std::numeric_limits::infinity()) { m_gainMax = std::max(m_gainMax, m_data[kkk][iii].second); m_gainMin = std::min(m_gainMin, m_data[kkk][iii].second); + //APPL_INFO("plop " << m_data[kkk][iii].second); } if (displayLog == false) { if (std::abs(m_data[kkk][iii].first) != std::numeric_limits::infinity()) { @@ -105,12 +106,15 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() { } m_frequencyMax = std::max(m_frequencyMax, std::log(m_data[kkk][iii].first)); m_frequencyMin = std::min(m_frequencyMin, std::log(m_data[kkk][iii].first)); - APPL_INFO("plop " << m_data[kkk][iii].first << " " << std::log(m_data[kkk][iii].first)); + //APPL_INFO("plop " << m_data[kkk][iii].first << " " << std::log(m_data[kkk][iii].first)); } } } } // TODO : limit unit at a unit value. + + m_gainMin = int32_t(m_gainMin - 1); + m_gainMax = int32_t(m_gainMax + 1); /* for (size_t iii=0; iii - - - - - + + - - - + - + - - - + - + - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +