[DEV] biquad work corectly
This commit is contained in:
parent
cdfb632a9e
commit
ceda8f8d06
@ -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<enum drain::filterType>(const enum drain::filterType& _variable) {
|
||||
return listValues[_variable];
|
||||
}
|
||||
template <> bool from_string<enum drain::filterType>(enum drain::filterType& _variableRet, const std::string& _value) {
|
||||
for (int32_t iii=0; iii<listValuesSize; ++iii) {
|
||||
if (_value == listValues[iii]) {
|
||||
_variableRet = static_cast<enum drain::filterType>(iii);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_variableRet = drain::filterType_none;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <ewol/widget/Label.h>
|
||||
#include <ewol/widget/Entry.h>
|
||||
#include <ewol/widget/Button.h>
|
||||
#include <ewol/widget/Slider.h>
|
||||
|
||||
#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<appl::widget::DisplayFrequency>(getSubObjectNamed("displayer"));
|
||||
onCallbackStart();
|
||||
}
|
||||
|
||||
void appl::Windows::onCallbackSampleRate(const std::string& _value) {
|
||||
APPL_INFO("SampleRate " << _value);
|
||||
std::vector<int32_t> 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");
|
||||
|
||||
void appl::Windows::onCallbackSampleRateUp() {
|
||||
for (int32_t iii=0; iii<m_listSampleRate.size(); ++iii) {
|
||||
if (m_sampleRate == m_listSampleRate[iii]) {
|
||||
iii++;
|
||||
if (iii<m_listSampleRate.size()) {
|
||||
m_sampleRate = m_listSampleRate[iii];
|
||||
} else {
|
||||
ewol::parameterSetOnObjectNamed("sample-rate-valid", "color", "red");
|
||||
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();
|
||||
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::onCallbackType(const std::string& _value) {
|
||||
APPL_INFO("Type " << _value);
|
||||
std::vector<std::string> list;
|
||||
list.push_back("HPF");
|
||||
list.push_back("LPF");
|
||||
if (etk::isIn(_value, list) == true) {
|
||||
ewol::parameterSetOnObjectNamed("type-valid", "color", "green");
|
||||
void appl::Windows::onCallbackSampleRateLow() {
|
||||
for (int32_t iii=0; iii<m_listSampleRate.size(); ++iii) {
|
||||
if (m_sampleRate == m_listSampleRate[iii]) {
|
||||
iii--;
|
||||
if (iii>=0) {
|
||||
m_sampleRate = m_listSampleRate[iii];
|
||||
} else {
|
||||
ewol::parameterSetOnObjectNamed("type-valid", "color", "red");
|
||||
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<m_listType.size(); ++iii) {
|
||||
if (m_type == m_listType[iii]) {
|
||||
iii++;
|
||||
if (iii<m_listType.size()) {
|
||||
m_type = m_listType[iii];
|
||||
} else {
|
||||
m_type = m_listType[0];
|
||||
}
|
||||
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::onCallbackTypeLow() {
|
||||
for (int32_t iii=0; iii<m_listType.size(); ++iii) {
|
||||
if (m_type == m_listType[iii]) {
|
||||
iii--;
|
||||
if (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 <river/debug.h>
|
||||
@ -90,7 +207,8 @@ void appl::Windows::onCallbackStart() {
|
||||
int32_t iii = 10;
|
||||
std::vector<audio::channel> 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<drain::Equalizer> eq = drain::Equalizer::create();
|
||||
// configure input
|
||||
@ -98,42 +216,25 @@ 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<std::pair<float,float> > theory = calculateTheory(48000, eq->getCoef());
|
||||
eq->calcBiquad(m_type, m_cutFrequency, m_quality, m_gain);
|
||||
std::vector<std::pair<float,float> > theory = calculateTheory(m_sampleRate, eq->getCoef());
|
||||
m_displayer->clear();
|
||||
m_displayer->setValue(theory);
|
||||
std::vector<std::pair<float,float> > 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<int16_t> 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);
|
||||
float gain = 0;
|
||||
if (format.getFormat() == audio::format_int16) {
|
||||
std::vector<int16_t> data;
|
||||
// create sinus
|
||||
data.resize(16000, 0);
|
||||
for (int32_t iii=0; iii<data.size(); iii++) {
|
||||
data[iii] = cos(m_phase) * 30000;
|
||||
data[iii] = cos(m_phase) * 32000;
|
||||
m_phase += baseCycle;
|
||||
if (m_phase >= 2*M_PI) {
|
||||
m_phase -= 2*M_PI;
|
||||
@ -144,29 +245,20 @@ void appl::Windows::onCallbackStart() {
|
||||
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());
|
||||
//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<int16_t*>(outputVoid);
|
||||
RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT.raw",output,outputNbChunk);
|
||||
//RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT.raw",output,outputNbChunk);
|
||||
int16_t value = 0;
|
||||
for (size_t iii=20; iii<outputNbChunk-20; ++iii) {
|
||||
for (size_t iii=200; iii<outputNbChunk-200; ++iii) {
|
||||
value = std::max(value, output[iii]);
|
||||
}
|
||||
float gain = 20.0 * std::log10(double(value)/30000.0);
|
||||
APPL_INFO("LEVEL " << iii << " out = " << value << " % : " << gain);
|
||||
pratic.push_back(std::make_pair<float, float>(iii,float(value)/30000.0f));
|
||||
iii += 10;
|
||||
}
|
||||
/*
|
||||
while (iii < m_sampleRate/2) {
|
||||
gain = 20.0 * std::log10(double(value)/32000.0);
|
||||
APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain);
|
||||
} else if (format.getFormat() == audio::format_float) {
|
||||
std::vector<float> 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);
|
||||
data.resize(16000, 0);
|
||||
for (int32_t iii=0; iii<data.size(); iii++) {
|
||||
data[iii] = cos(m_phase);
|
||||
m_phase += baseCycle;
|
||||
@ -179,21 +271,19 @@ void appl::Windows::onCallbackStart() {
|
||||
void* outputVoid = nullptr;
|
||||
size_t outputNbChunk = 0;
|
||||
std11::chrono::system_clock::time_point time;
|
||||
RIVER_SAVE_FILE_MACRO(float,"aaa_test_INPUT_F.raw",&data[0],data.size());
|
||||
//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<float*>(outputVoid);
|
||||
RIVER_SAVE_FILE_MACRO(float,"aaa_test_OUTPUT_F.raw",output,outputNbChunk);
|
||||
double value = 0;
|
||||
for (size_t iii=0; iii<outputNbChunk; ++iii) {
|
||||
value += std::abs(output[iii]);
|
||||
//RIVER_SAVE_FILE_MACRO(int16_t,"aaa_test_OUTPUT.raw",output,outputNbChunk);
|
||||
float value = 0;
|
||||
for (size_t iii=200; iii<outputNbChunk-200; ++iii) {
|
||||
value = std::max(value, output[iii]);
|
||||
}
|
||||
value /= (outputNbChunk);
|
||||
float gain = 20.0 * std::log10(float(value));
|
||||
APPL_INFO("LEVEL " << iii << " out = " << value << " % : " << gain);
|
||||
pratic.push_back(std::make_pair<float, float>(iii,float(value)));
|
||||
iii += 10;
|
||||
gain = 20.0 * std::log10(double(value)/1.0);
|
||||
APPL_VERBOSE("LEVEL " << iii << " out = " << value << " % : " << gain);
|
||||
}
|
||||
pratic.push_back(std::make_pair<float, float>(float(freq),float(gain)));
|
||||
}
|
||||
*/
|
||||
m_displayer->setValue(pratic);
|
||||
}
|
||||
|
||||
@ -223,6 +313,7 @@ std::vector<std::pair<float,float> > 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<std::pair<float,float> > 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<float,float>(iii / (len - 1.0) * _sampleRate / 2.0, y + 0.5));
|
||||
APPL_DEBUG("theory = " << freq << " power=" << y);
|
||||
out.push_back(std::make_pair<float,float>(freq, y));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -25,18 +25,25 @@ namespace appl {
|
||||
protected:
|
||||
std::shared_ptr<ewol::widget::Composer> m_gui;
|
||||
std::shared_ptr<appl::widget::DisplayFrequency> 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<int32_t> m_listSampleRate;
|
||||
enum drain::filterType m_type;
|
||||
std::vector<enum drain::filterType> m_listType;
|
||||
float m_cutFrequency;
|
||||
float m_gain;
|
||||
float m_bandWidth;
|
||||
float m_quality;
|
||||
std::vector<std::pair<float,float> > calculateTheory(double _sampleRate, std::vector<float> _coef);
|
||||
};
|
||||
};
|
||||
|
@ -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<m_data.size(); kkk++) {
|
||||
for (size_t iii=0; iii<m_data[kkk].size(); ++iii) {
|
||||
if (std::abs(m_data[kkk][iii].second) != std::numeric_limits<float>::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<float>::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<m_data[0].size() && m_data[1].size(); ++iii) {
|
||||
APPL_INFO(" f=" << m_data[0][iii].first << " val=" << m_data[0][iii].second << " f=" << m_data[1][iii].first << " val=" << m_data[1][iii].second);
|
||||
}
|
||||
*/
|
||||
// set all the line:
|
||||
m_draw.setThickness(1);
|
||||
APPL_ERROR("---------------------------");
|
||||
//APPL_ERROR("---------------------------");
|
||||
for (size_t kkk=0; kkk<m_data.size(); ++kkk) {
|
||||
APPL_ERROR("kjhkjhkj " << kkk << " " << m_data.size());
|
||||
//APPL_ERROR("kjhkjhkj " << kkk << " " << m_data.size());
|
||||
if (kkk == 0) {
|
||||
m_draw.setColor(etk::color::green);
|
||||
} else if (kkk == 0) {
|
||||
@ -123,6 +134,25 @@ void appl::widget::DisplayFrequency::onRegenerateDisplay() {
|
||||
ratioY*(m_data[kkk][iii].second - m_gainMin)));
|
||||
}
|
||||
}
|
||||
// TODO : Draw text ...
|
||||
m_text.setDefaultColorFg(etk::color::green);
|
||||
std::string textToDisplay = etk::to_string(m_frequencyMin) + " Hz";
|
||||
vec3 size = m_text.calculateSize(textToDisplay);
|
||||
m_text.setPos(vec2(m_borderSize.x(), m_borderSize.y()-size.y()));
|
||||
m_text.print(textToDisplay);
|
||||
|
||||
textToDisplay = etk::to_string(m_frequencyMax) + " Hz";
|
||||
size = m_text.calculateSize(textToDisplay);
|
||||
m_text.setPos(vec2(m_size.x()-m_borderSize.x()-size.x(), m_borderSize.y()-size.y()));
|
||||
m_text.print(textToDisplay);
|
||||
|
||||
m_text.setDefaultColorFg(etk::color::blue);
|
||||
textToDisplay = etk::to_string(m_gainMin) + " dB";
|
||||
size = m_text.calculateSize(textToDisplay);
|
||||
m_text.setPos(vec2(m_borderSize.x(), m_borderSize.y()));
|
||||
m_text.print(textToDisplay);
|
||||
|
||||
textToDisplay = etk::to_string(m_gainMax) + " dB";
|
||||
size = m_text.calculateSize(textToDisplay);
|
||||
m_text.setPos(vec2(m_borderSize.x(), m_size.y() - m_borderSize.y()));
|
||||
m_text.print(textToDisplay);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include <ewol/widget/Widget.h>
|
||||
#include <ewol/compositing/Drawing.h>
|
||||
#include <ewol/compositing/Text.h>
|
||||
#include <ewol/widget/Manager.h>
|
||||
|
||||
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();
|
||||
|
@ -14,50 +14,55 @@
|
||||
<label>Global parameter: .........</label>
|
||||
<sizer mode="vert" expand="true,false" lock="true" border="0.2%" addmode="invert">
|
||||
<spacer min-size="5,5px"/>
|
||||
<label>Sample rate:</label>
|
||||
<sizer mode="hori">
|
||||
<label>SampleRate:</label>
|
||||
<entry expand="true" fill="true" name="sample-rate" regex="[0-9]*" value="48000"/>
|
||||
<Spacer name="sample-rate-valid" min-size="10,10px" max-size="10,10px" color="green"/>
|
||||
<!--
|
||||
<combo expand="true" name="sample-rate" select="48">
|
||||
<item value="96">96000</item>
|
||||
<item value="48">48000</item>
|
||||
<item value="32">32000</item>
|
||||
<item value="16">16000</item>
|
||||
<item value="8">8000</item>
|
||||
</combo>
|
||||
-->
|
||||
<button name="sample-rate-low">
|
||||
<label>---</label>
|
||||
</button>
|
||||
<label expand="true" fill="true" name="sample-rate">
|
||||
48000
|
||||
</label>
|
||||
<button name="sample-rate-up">
|
||||
<label>+++</label>
|
||||
</button>
|
||||
</sizer>
|
||||
</sizer>
|
||||
<label>Filter:</label>
|
||||
<sizer mode="vert" expand="true,false" lock="true" border="0.2%" addmode="invert">
|
||||
<spacer min-size="5,5px"/>
|
||||
<sizer mode="hori">
|
||||
<label>type:</label>
|
||||
<entry expand="true" fill="true" name="type" value="HPF"/>
|
||||
<Spacer name="type-valid" min-size="10,10px" max-size="10,10px" color="green"/>
|
||||
<!--
|
||||
<combo expand="true" name="type" select="HPF">
|
||||
<item value="HPF">High Pass Filter</item>
|
||||
<item value="LPF">Low Pass Filter</item>
|
||||
</combo>
|
||||
-->
|
||||
<sizer mode="hori">
|
||||
<button name="type-low">
|
||||
<label>---</label>
|
||||
</button>
|
||||
<label expand="true" fill="true" name="type">
|
||||
Low-pass
|
||||
</label>
|
||||
<button name="type-up">
|
||||
<label>+++</label>
|
||||
</button>
|
||||
</sizer>
|
||||
<spacer min-size="5,5px"/>
|
||||
|
||||
<sizer mode="hori">
|
||||
<label>gain:</label>
|
||||
<entry expand="true" fill="true" name="gain" regex="-?[0-9]*" value="0"/>
|
||||
<Spacer name="gain-valid" min-size="10,10px" max-size="10,10px" color="green"/>
|
||||
<entry expand="true" fill="true" name="gain" regex="-?(\.|[0-9])*" value="0"/>
|
||||
</sizer>
|
||||
<slider expand="true" name="gain-slider" value="0" min="-30" max="+30" step="0.01"/>
|
||||
<spacer min-size="5,5px"/>
|
||||
|
||||
<sizer mode="hori">
|
||||
<label>frequency:</label>
|
||||
<label>cut frequency:</label>
|
||||
<entry expand="true" fill="true" name="frequency" regex="[0-9]*" value="1000"/>
|
||||
<Spacer name="frequency-valid" min-size="10,10px" max-size="10,10px" color="green"/>
|
||||
</sizer>
|
||||
<slider expand="true" name="frequency-slider" value="8000" min="1" max="24000" step="0.01"/>
|
||||
<spacer min-size="5,5px"/>
|
||||
|
||||
<sizer mode="hori">
|
||||
<label>Band width:</label>
|
||||
<entry expand="true" fill="true" name="band-width" regex="[0-9]*" value="100"/>
|
||||
<Spacer name="band-width-valid" min-size="10,10px" max-size="10,10px" color="green"/>
|
||||
<label>Quality factor:</label>
|
||||
<entry expand="true" fill="true" name="quality" regex="[0-9]*" value="100"/>
|
||||
</sizer>
|
||||
<slider expand="true" name="quality-slider" value="0.707" min="0.001" max="50" step="0.001"/>
|
||||
</sizer>
|
||||
<button name="display">
|
||||
<label>Display</label>
|
||||
|
Loading…
Reference in New Issue
Block a user