diff --git a/drain/Equalizer.cpp b/drain/Equalizer.cpp index b2fd917..1e327be 100644 --- a/drain/Equalizer.cpp +++ b/drain/Equalizer.cpp @@ -308,3 +308,32 @@ void drain::Equalizer::calcBiquad(enum drain::filterType _type, double _frequenc break; } } + +static const char* listValues[] = { + "none", + "low-pass", + "high-pass", + "band-pass", + "notch", + "peak", + "low-shelf", + "high-shelf" +}; +static int32_t listValuesSize = sizeof(listValues)/sizeof(char*); + + +namespace etk { + template<> std::string to_string(const enum drain::filterType& _variable) { + return listValues[_variable]; + } + template <> bool from_string(enum drain::filterType& _variableRet, const std::string& _value) { + for (int32_t iii=0; iii(iii); + return true; + } + } + _variableRet = drain::filterType_none; + return false; + } +} diff --git a/tools/drainEqualizerProfiling/appl/Windows.cpp b/tools/drainEqualizerProfiling/appl/Windows.cpp index cb12851..928ed6f 100644 --- a/tools/drainEqualizerProfiling/appl/Windows.cpp +++ b/tools/drainEqualizerProfiling/appl/Windows.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #undef __class__ #define __class__ "Windows" @@ -20,9 +21,29 @@ appl::Windows::Windows() : m_sampleRate(48000), m_type(drain::filterType::filterType_lowPass), m_cutFrequency(8000.0), - m_gain(6.0), - m_bandWidth(0.1) { + m_gain(0.0), + m_quality(0.707) { addObjectType("appl::Windows"); + m_listSampleRate.push_back(192000); + m_listSampleRate.push_back(176400); + m_listSampleRate.push_back(96000); + m_listSampleRate.push_back(88200); + m_listSampleRate.push_back(48000); + m_listSampleRate.push_back(44100); + m_listSampleRate.push_back(32000); + m_listSampleRate.push_back(22050); + m_listSampleRate.push_back(16000); + m_listSampleRate.push_back(11025); + m_listSampleRate.push_back(8000); + m_listSampleRate.push_back(4000); + m_listType.push_back(drain::filterType_none); + m_listType.push_back(drain::filterType_lowPass); + m_listType.push_back(drain::filterType_highPass); + m_listType.push_back(drain::filterType_bandPass); + m_listType.push_back(drain::filterType_notch); + m_listType.push_back(drain::filterType_peak); + m_listType.push_back(drain::filterType_lowShelf); + m_listType.push_back(drain::filterType_highShelf); } void appl::Windows::init() { @@ -33,54 +54,150 @@ void appl::Windows::init() { if (m_gui != nullptr) { setSubWidget(m_gui); } - subBind(ewol::widget::Entry, "sample-rate", signalModify, shared_from_this(), &appl::Windows::onCallbackSampleRate); - subBind(ewol::widget::Entry, "type", signalModify, shared_from_this(), &appl::Windows::onCallbackType); + subBind(ewol::widget::Button, "sample-rate-low", signalPressed, shared_from_this(), &appl::Windows::onCallbackSampleRateLow); + subBind(ewol::widget::Button, "sample-rate-up", signalPressed, shared_from_this(), &appl::Windows::onCallbackSampleRateUp); + subBind(ewol::widget::Button, "type-low", signalPressed, shared_from_this(), &appl::Windows::onCallbackTypeLow); + subBind(ewol::widget::Button, "type-up", signalPressed, shared_from_this(), &appl::Windows::onCallbackTypeUp); + subBind(ewol::widget::Entry, "gain", signalModify, shared_from_this(), &appl::Windows::onCallbackGain); + subBind(ewol::widget::Slider, "gain-slider", signalChange, shared_from_this(), &appl::Windows::onCallbackGainSlider); + subBind(ewol::widget::Entry, "frequency", signalModify, shared_from_this(), &appl::Windows::onCallbackFrequency); - subBind(ewol::widget::Entry, "band-width", signalModify, shared_from_this(), &appl::Windows::onCallbackBandWidth); + subBind(ewol::widget::Slider, "frequency-slider", signalChange, shared_from_this(), &appl::Windows::onCallbackFrequencySlider); + + subBind(ewol::widget::Entry, "quality", signalModify, shared_from_this(), &appl::Windows::onCallbackQuality); + subBind(ewol::widget::Slider, "quality-slider", signalChange, shared_from_this(), &appl::Windows::onCallbackQualitySlider); + subBind(ewol::widget::Button, "display", signalPressed, shared_from_this(), &appl::Windows::onCallbackStart); m_displayer = std11::dynamic_pointer_cast(getSubObjectNamed("displayer")); + onCallbackStart(); } -void appl::Windows::onCallbackSampleRate(const std::string& _value) { - APPL_INFO("SampleRate " << _value); - std::vector list; - list.push_back(96000); - list.push_back(48000); - list.push_back(44100); - list.push_back(32000); - list.push_back(22050); - list.push_back(16000); - list.push_back(8000); - if (etk::isIn(etk::string_to_int32_t(_value), list) == true) { - ewol::parameterSetOnObjectNamed("sample-rate-valid", "color", "green"); - } else { - ewol::parameterSetOnObjectNamed("sample-rate-valid", "color", "red"); + +void appl::Windows::onCallbackSampleRateUp() { + for (int32_t iii=0; iii list; - list.push_back("HPF"); - list.push_back("LPF"); - if (etk::isIn(_value, list) == true) { - ewol::parameterSetOnObjectNamed("type-valid", "color", "green"); - } else { - ewol::parameterSetOnObjectNamed("type-valid", "color", "red"); +void appl::Windows::onCallbackSampleRateLow() { + for (int32_t iii=0; iii=0) { + m_sampleRate = m_listSampleRate[iii]; + } else { + m_sampleRate = m_listSampleRate[m_listSampleRate.size()-1]; + } + ewol::parameterSetOnObjectNamed("sample-rate", "value", etk::to_string(m_sampleRate)); + ewol::parameterSetOnObjectNamed("frequency-slider", "max", etk::to_string(m_sampleRate/2)); + onCallbackStart(); + return; + } } + m_sampleRate = m_listSampleRate[0]; + ewol::parameterSetOnObjectNamed("sample-rate", "value", etk::to_string(m_sampleRate)); + ewol::parameterSetOnObjectNamed("frequency-slider", "max", etk::to_string(m_sampleRate/2)); + onCallbackStart(); } +void appl::Windows::onCallbackTypeUp() { + for (int32_t iii=0; 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) { - APPL_INFO("Gain " << _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_gain = _value; + ewol::parameterSetOnObjectNamed("quality", "value", etk::to_string(_value)); + APPL_INFO("quality " << m_quality); + onCallbackStart(); +} + + void appl::Windows::onCallbackFrequency(const std::string& _value) { - APPL_INFO("Frequency " << _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::onCallbackBandWidth(const std::string& _value) { - APPL_INFO("BandWidth " << _value); +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 @@ -90,7 +207,8 @@ void appl::Windows::onCallbackStart() { int32_t iii = 10; std::vector map; map.push_back(audio::channel_frontCenter); - drain::IOFormatInterface format(map, audio::format_int16, m_sampleRate); + //drain::IOFormatInterface format(map, audio::format_int16, m_sampleRate); + drain::IOFormatInterface format(map, audio::format_float, m_sampleRate); // create equalizer std11::shared_ptr eq = drain::Equalizer::create(); // configure input @@ -98,102 +216,74 @@ void appl::Windows::onCallbackStart() { // configure output eq->setOutputFormat(format); // configure parameter - /* - eq->setParameter("type", "APF"); - eq->setParameter("gain", etk::to_string(m_gain)); - eq->setParameter("frequency", etk::to_string(m_cutFrequency)); - eq->setParameter("band-width", etk::to_string(m_bandWidth)); - */ - //eq->calcBiquad(drain::filterType_none, m_cutFrequency, 0.707, m_gain); - eq->calcBiquad(drain::filterType_lowPass, m_cutFrequency, 0.707, m_gain); - //eq->calcBiquad(drain::filterType_highPass, m_cutFrequency, 0.707, m_gain); - std::vector > theory = calculateTheory(48000, eq->getCoef()); + eq->calcBiquad(m_type, m_cutFrequency, m_quality, m_gain); + std::vector > theory = calculateTheory(m_sampleRate, eq->getCoef()); m_displayer->clear(); m_displayer->setValue(theory); std::vector > pratic; size_t len = 512; for (size_t iii=0; iii < len; iii++) { - double w; - //if (buildLinear == true) { - // 0 to pi, linear scale - w = iii / (len - 1.0) * M_PI; - //} else { - // 0.001 to 1, times pi, log scale - // w = std::exp(std::log(1.0 / 0.001) * iii / (len - 1.0)) * 0.001 * M_PI; - //} - double freq = iii / (len - 1.0) * 48000 / 2.0; - - //while (iii < m_sampleRate/2) { - std::vector data; - //APPL_INFO("TEST : " << iii); + float freq = iii / (len - 1.0) * m_sampleRate / 2.0; // To reset filter eq->setParameter("reset", ""); - // create sinus - data.resize(4096, 0); double m_phase = 0; double baseCycle = 2.0*M_PI/double(m_sampleRate) * double(freq); - for (int32_t iii=0; iii= 2*M_PI) { - m_phase -= 2*M_PI; + float gain = 0; + if (format.getFormat() == audio::format_int16) { + std::vector data; + // create sinus + data.resize(16000, 0); + for (int32_t iii=0; iii= 2*M_PI) { + m_phase -= 2*M_PI; + } } - } - // process - int16_t* output = nullptr; - void* outputVoid = nullptr; - size_t outputNbChunk = 0; - std11::chrono::system_clock::time_point time; - RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_INPUT.raw",&data[0],data.size()); - eq->process(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=20; iii(iii,float(value)/30000.0f)); - iii += 10; - } - /* - while (iii < m_sampleRate/2) { - std::vector data; - //APPL_INFO("TEST : " << iii); - // To reset filter - eq->setParameter("reset", ""); - // create sinus - data.resize(4096, 0); - double m_phase = 0; - double baseCycle = 2.0*M_PI/double(m_sampleRate) * double(iii); - for (int32_t iii=0; iii= 2*M_PI) { - m_phase -= 2*M_PI; + // process + int16_t* output = nullptr; + void* outputVoid = nullptr; + size_t outputNbChunk = 0; + std11::chrono::system_clock::time_point time; + //RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_INPUT.raw",&data[0],data.size()); + eq->process(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 data; + // create sinus + data.resize(16000, 0); + for (int32_t iii=0; iii= 2*M_PI) { + m_phase -= 2*M_PI; + } + } + // process + float* output = nullptr; + void* outputVoid = nullptr; + size_t outputNbChunk = 0; + std11::chrono::system_clock::time_point time; + //RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_INPUT.raw",&data[0],data.size()); + eq->process(time, &data[0], data.size(), outputVoid, outputNbChunk); + output = static_cast(outputVoid); + //RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT.raw",output,outputNbChunk); + float value = 0; + for (size_t iii=200; iiiprocess(time, &data[0], data.size(), outputVoid, outputNbChunk); - output = static_cast(outputVoid); - RIVER_SAVE_FILE_MACRO(float,"aaa_test_OUTPUT_F.raw",output,outputNbChunk); - double value = 0; - for (size_t iii=0; iii(iii,float(value))); - iii += 10; + pratic.push_back(std::make_pair(float(freq),float(gain))); } - */ m_displayer->setValue(pratic); } @@ -223,6 +313,7 @@ std::vector > appl::Windows::calculateTheory(double _samp // 0.001 to 1, times pi, log scale w = std::exp(std::log(1.0 / 0.001) * iii / (len - 1.0)) * 0.001 * M_PI; } + double freq = iii / (len - 1.0) * _sampleRate / 2.0; double phi = std::pow(std::sin(w/2.0), 2.0); double y = std::log( std::pow(m_a[0]+m_a[1]+m_a[2], 2.0) - 4.0*(m_a[0]*m_a[1] + 4.0*m_a[0]*m_a[2] + m_a[1]*m_a[2])*phi @@ -236,8 +327,8 @@ std::vector > appl::Windows::calculateTheory(double _samp y = -200.0; } - APPL_INFO("theory = " << iii / (len - 1.0) * _sampleRate / 2.0 << " power=" << y); - out.push_back(std::make_pair(iii / (len - 1.0) * _sampleRate / 2.0, y + 0.5)); + APPL_DEBUG("theory = " << freq << " power=" << y); + out.push_back(std::make_pair(freq, y)); } return out; } diff --git a/tools/drainEqualizerProfiling/appl/Windows.h b/tools/drainEqualizerProfiling/appl/Windows.h index bb339b1..4d4b938 100644 --- a/tools/drainEqualizerProfiling/appl/Windows.h +++ b/tools/drainEqualizerProfiling/appl/Windows.h @@ -25,18 +25,25 @@ namespace appl { protected: std::shared_ptr m_gui; std::shared_ptr m_displayer; - void onCallbackSampleRate(const std::string& _value); - void onCallbackType(const std::string& _value); + 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 onCallbackBandWidth(const std::string& _value); + void onCallbackFrequencySlider(const float& _value); + void onCallbackQuality(const std::string& _value); + void onCallbackQualitySlider(const float& _value); void onCallbackStart(); 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_bandWidth; + float m_quality; std::vector > calculateTheory(double _sampleRate, std::vector _coef); }; }; diff --git a/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp b/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp index 37669bb..ab70d0b 100644 --- a/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp +++ b/tools/drainEqualizerProfiling/appl/widget/DisplayFrequency.cpp @@ -20,6 +20,7 @@ appl::widget::DisplayFrequency::DisplayFrequency() : m_frequencyMin(0.0f), m_frequencyMax(24000.0f) { addObjectType("appl::widget::DisplayFrequency"); + m_text.setFontSize(13); } void appl::widget::DisplayFrequency::init() { @@ -52,6 +53,7 @@ void appl::widget::DisplayFrequency::setFrequencyRange(float _min, float _max) { void appl::widget::DisplayFrequency::onDraw() { m_draw.draw(); + m_text.draw(); } @@ -62,11 +64,11 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() { } // remove previous data m_draw.clear(); + m_text.clear(); m_borderSize = m_size * 0.05; - // set background m_draw.setColor(etk::color::black); m_draw.setPos(vec2(0,0)); @@ -91,18 +93,27 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() { m_frequencyMax = -99999999.0; for (size_t kkk=0; kkk::infinity()) { + m_gainMax = std::max(m_gainMax, m_data[kkk][iii].second); + m_gainMin = std::min(m_gainMin, m_data[kkk][iii].second); + } + if (std::abs(m_data[kkk][iii].first) != std::numeric_limits::infinity()) { + m_frequencyMax = std::max(m_frequencyMax, m_data[kkk][iii].first); + m_frequencyMin = std::min(m_frequencyMin, m_data[kkk][iii].first); + } } } - m_gainMin = -20; + // TODO : limit unit at a unit value. + /* + for (size_t iii=0; iii #include +#include #include namespace appl { @@ -19,6 +20,7 @@ namespace appl { class DisplayFrequency : public ewol::Widget { private: ewol::compositing::Drawing m_draw; //!< drawing instance + ewol::compositing::Text m_text; //!< drawing instance protected: //! @brief constructor DisplayFrequency(); diff --git a/tools/drainEqualizerProfiling/data/gui.xml b/tools/drainEqualizerProfiling/data/gui.xml index 00cb884..9352242 100644 --- a/tools/drainEqualizerProfiling/data/gui.xml +++ b/tools/drainEqualizerProfiling/data/gui.xml @@ -14,50 +14,55 @@ + - - - - + + + + - - - - + + + + + - - + + + + - + - + + + - - - + + +