From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Aufgabenblatt1/Quantization/.cproject | 945 +++++++++++++++++++++ .../Aufgabenblatt1/Quantization/.project | 82 ++ .../Quantization/src/Quantization.cpp | 103 +++ .../Aufgabenblatt1/Quantization/src/Quantization.h | 45 + .../Quantization/src/QuantizationController.cpp | 95 +++ .../Quantization/src/QuantizationController.h | 51 ++ .../Quantization/src/QuantizationParameters.h | 55 ++ .../Aufgabenblatt1/Quantization/src/main.cpp | 22 + .../Quantization/ui/quantization.glade | 216 +++++ 9 files changed, 1614 insertions(+) create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade (limited to 'Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization') diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject new file mode 100644 index 0000000..61aefe9 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.cproject @@ -0,0 +1,945 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project new file mode 100644 index 0000000..68f108b --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/.project @@ -0,0 +1,82 @@ + + + Quantization + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/Quantization/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp new file mode 100644 index 0000000..9198223 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.cpp @@ -0,0 +1,103 @@ +/* + * Quantization.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATION_H_ + #include "Quantization.h" +#endif + +#ifndef _GLIBCXX_FSTREAM + #include +#endif + +#ifndef _GLIBCXX_NUMERIC_LIMITS + #include +#endif + +#ifndef _GLIBCXX_CMATH + #include +#endif + +#ifndef _GLIBCXX_IOSTREAM + #include +#endif + +Quantization::Quantization(QuantizationParameters& params) +:mParams(params) +{ + calcQuantizationValues(); + std::ifstream inFile; + std::ofstream outFile; + inFile.open(mParams.getInputFile().c_str(), std::ios::in | std::ios::binary ); + outFile.open(mParams.getOutputFile().c_str(), std::ios::out | std::ios::binary); + int dataLenOffset = 0x28; + char header[dataLenOffset]; + inFile.read(&header[0],dataLenOffset); + outFile.write(&header[0],dataLenOffset); + int numSamples = 0; + inFile.read((char*) &numSamples,sizeof(numSamples)); + outFile.write((char*) &numSamples,sizeof(numSamples)); + short data; + short quantizationized; +// unsigned counter = 0; + for (int i=0; i < numSamples;) { + inFile.read((char*) &data, sizeof(data) ); + quantizationized = getQuantizationValue(data); + outFile.write((char*) &quantizationized, sizeof(quantizationized) ); +// std::cout << counter++ << " " << quantizationized << std::endl; + i += sizeof(short); + } + inFile.close(); + outFile.close(); + std::cout << "quantization done" << std::endl; +} + +Quantization::~Quantization() +{ + QuantizationRangesIter it = mQuantizationRanges.begin(); + for ( ;it < mQuantizationRanges.end(); ) + { + delete *it++; + } + mQuantizationRanges.clear(); +} + +short Quantization::getQuantizationValue(short val) +{ + // shift to unsigned posivitives values + unsigned short shiftedVal = val - std::numeric_limits::min(); + QuantizationRangesIter it = mQuantizationRanges.begin(); + for(; it < mQuantizationRanges.end(); it++) { + QuantizationRange* quantRangePtr = *it; + if (quantRangePtr->IsInRange(shiftedVal)) { + // shift back + return quantRangePtr->mRangeValue + std::numeric_limits::min(); + } + } + std::cout << val << " " << shiftedVal << " not quantizationized" << std::endl; + return -1; +} + +void Quantization::calcQuantizationValues() +{ + mNumQuantizationValues = 1 << mParams.getBits(); +// std::cout << mNumQuantizationValues << " quantization values" << std::endl; + unsigned short valueRangeWidth = std::numeric_limits::max() / mNumQuantizationValues; +// std::cout << "value range width " << valueRangeWidth << std::endl; + unsigned short rangeMiddle = valueRangeWidth / 2; +// std::cout << "value range middle " << rangeMiddle << std::endl; + QuantizationRange* quantRangePtr = NULL; + for (unsigned i=0; imMinValue = i * valueRangeWidth; + quantRangePtr->mMaxValue = ((i+1) * valueRangeWidth) - 1; + quantRangePtr->mRangeValue = quantRangePtr->mMinValue + rangeMiddle; + quantRangePtr->mRangeWidth = valueRangeWidth; +// std::cout << "quantization value "<< (i+1) << ": " << quantRangePtr->mRangeValue << std::endl; +// std::cout << "Range: "<< quantRangePtr->mMinValue << " - " << quantRangePtr->mMaxValue << std::endl; + mQuantizationRanges.push_back(quantRangePtr); + } +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h new file mode 100644 index 0000000..5939591 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/Quantization.h @@ -0,0 +1,45 @@ +/* + * Quantization.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATION_H_ +#define QUANTIZATION_H_ + +#ifndef QUANTIZATIONPARAMETERS_H_ + #include "QuantizationParameters.h" +#endif + +#ifndef _GLIBCXX_VECTOR + #include +#endif + +struct QuantizationRange { + unsigned short mMinValue; + unsigned short mMaxValue; + unsigned short mRangeWidth; + unsigned short mRangeValue; + bool IsInRange(unsigned short val) + { + return ((val >= mMinValue) && (val <= mMaxValue)); + } +}; + +typedef std::vector QuantizationRanges; +typedef std::vector::iterator QuantizationRangesIter; + +class Quantization { +public: + Quantization(QuantizationParameters& params); + virtual ~Quantization(); +private: + QuantizationParameters& mParams; + unsigned mNumQuantizationValues; + QuantizationRanges mQuantizationRanges; + short getQuantizationValue(short); + void calcQuantizationValues(); +}; + +#endif /* QUANTIZATION_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp new file mode 100644 index 0000000..47196bd --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.cpp @@ -0,0 +1,95 @@ +/* + * QuantizationController.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ +#ifndef QUANTIZATIONCONTROLLER_H_ + #include "QuantizationController.h" +#endif + +#ifndef QUANTIZATION_H_ + #include "Quantization.h" +#endif + +const char* QuantizationController::UI_FILENAME = "ui/quantization.glade"; +const double QuantizationController::QUANTIZATIONBITS_DEFAULT = 8.0; +const double QuantizationController::QUANTIZATIONBITS_MIN = 1.0; +const double QuantizationController::QUANTIZATIONBITS_MAX = 16.0; + +QuantizationController::QuantizationController() +:mQuantizationBitsAdj(QUANTIZATIONBITS_DEFAULT,QUANTIZATIONBITS_MIN,QUANTIZATIONBITS_MAX) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + builder->get_widget("mainwindow",mPtrMainWin); + builder->get_widget("quantizationbits",mPtrQuantizationBits); + builder->get_widget("openinputbtn",mPtrOpenInputBtn); + builder->get_widget("openoutputbtn",mPtrOpenOutputBtn); + builder->get_widget("startbtn",mPtrStartBtn); + builder->get_widget("inputfile",mPtrInputFile); + builder->get_widget("outputfile",mPtrOutputFile); + mPtrQuantizationBits->set_adjustment(mQuantizationBitsAdj); + mPtrStartBtn->signal_clicked().connect(sigc::mem_fun(this,&QuantizationController::on_start_btn)); + mPtrOpenInputBtn->signal_clicked().connect(sigc::mem_fun(this,&QuantizationController::on_open_input_btn)); + mPtrOpenOutputBtn->signal_clicked().connect(sigc::mem_fun(this,&QuantizationController::on_open_output_btn)); + mPtrQuantizationBits->signal_value_changed().connect(sigc::mem_fun(this,&QuantizationController::on_quantizationbits_changed)); + mParams.setBits(mPtrQuantizationBits->get_value_as_int()); +} + +QuantizationController::~QuantizationController() { + // TODO Auto-generated destructor stub +} +void QuantizationController::startApp(Gtk::Main& kit) +{ + kit.run(*mPtrMainWin); +} + +void QuantizationController::on_open_input_btn() +{ + std::string filename; + choose_file(filename); + mParams.setInputFile(filename); + mPtrInputFile->set_text(mParams.getInputFile()); +} + +void QuantizationController::on_open_output_btn() +{ + std::string filename; + choose_file(filename); + mParams.setOutputFile(filename); + mPtrOutputFile->set_text(mParams.getOutputFile()); +} + +void QuantizationController::on_quantizationbits_changed() +{ + mParams.setBits(mPtrQuantizationBits->get_value_as_int()); +} + +void QuantizationController::on_start_btn() +{ + Quantization quantization(mParams); +} + +void QuantizationController::choose_file(std::string& filename) +{ + Glib::RefPtr builder = Gtk::Builder::create_from_file(UI_FILENAME); + Gtk::FileChooserDialog* ptrFilechooser; + builder->get_widget("filechooserdialog",ptrFilechooser); + Gtk::FileFilter waveFilter; + waveFilter.set_name("Wave files"); + waveFilter.add_pattern("*.wav"); + ptrFilechooser->add_filter(waveFilter); + ptrFilechooser->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + ptrFilechooser->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + ptrFilechooser->set_transient_for(*mPtrMainWin); + int result = ptrFilechooser->run(); + switch (result) + { + case Gtk::RESPONSE_OK: + filename = ptrFilechooser->get_filename(); + break; + default: + break; + } + delete ptrFilechooser; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h new file mode 100644 index 0000000..ea19c64 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationController.h @@ -0,0 +1,51 @@ +/* + * QuantizationController.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATIONCONTROLLER_H_ +#define QUANTIZATIONCONTROLLER_H_ + +#ifndef QUANTIZATIONPARAMETERS_H_ + #include "QuantizationParameters.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +#ifndef _GLIBCXX_STRING + #include +#endif + +class QuantizationController { +public: + QuantizationController(); + virtual ~QuantizationController(); + void startApp(Gtk::Main& kit); +private: + static const char* UI_FILENAME; + static const double QUANTIZATIONBITS_DEFAULT; + static const double QUANTIZATIONBITS_MIN; + static const double QUANTIZATIONBITS_MAX; + Gtk::Window* mPtrMainWin; + Gtk::Entry* mPtrInputFile; + Gtk::Entry* mPtrOutputFile; + Gtk::SpinButton* mPtrQuantizationBits; + Gtk::Button* mPtrOpenInputBtn; + Gtk::Button* mPtrOpenOutputBtn; + Gtk::Button* mPtrStartBtn; + + Gtk::Adjustment mQuantizationBitsAdj; + QuantizationParameters mParams; + + void on_open_input_btn(); + void on_open_output_btn(); + void on_start_btn(); + void on_quantizationbits_changed(); + void choose_file(std::string&); +}; + +#endif /* QUANTIZATIONCONTROLLER_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h new file mode 100644 index 0000000..06be668 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/QuantizationParameters.h @@ -0,0 +1,55 @@ +/* + * QuantizationParameters.h + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATIONPARAMETERS_H_ +#define QUANTIZATIONPARAMETERS_H_ + +#ifndef _GLIBCXX_STRING + #include +#endif + +class QuantizationParameters +{ +public: +private: + std::string mInputFile; + std::string mOutputFile; + int mBits; +public: + int getBits() const + { + return mBits; + } + + std::string getInputFile() const + { + return mInputFile; + } + + std::string getOutputFile() const + { + return mOutputFile; + } + + void setBits(int mBits) + { + this->mBits = mBits; + } + + void setInputFile(std::string& mInputFile) + { + this->mInputFile = mInputFile; + } + + void setOutputFile(std::string& mOutputFile) + { + this->mOutputFile = mOutputFile; + } + +}; + +#endif /* QUANTIZATIONPARAMETERS_H_ */ diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp new file mode 100644 index 0000000..7257265 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/src/main.cpp @@ -0,0 +1,22 @@ +/* + * main.cpp + * + * Created on: 02.04.2011 + * Author: sven + */ + +#ifndef QUANTIZATIONCONTROLLER_H_ + #include "QuantizationController.h" +#endif + +#ifndef _GTKMM_H + #include +#endif + +int main(int argc, char* argv[]) +{ + Gtk::Main kit(argc,argv); + QuantizationController quantCtrl; + quantCtrl.startApp(kit); + return 0; +} diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade new file mode 100644 index 0000000..ac30962 --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt1/Quantization/ui/quantization.glade @@ -0,0 +1,216 @@ + + + + + + Quantization + + + True + 5 + 5 + + + True + 0 + Input wave file + + + 1 + 2 + 1 + 2 + + + + + True + 0 + Quantization (bit) + + + 1 + 2 + 2 + 3 + + + + + True + 0 + Output wave file + + + 1 + 2 + 3 + 4 + + + + + True + True + + + + 2 + 3 + 2 + 3 + + + + + 480 + True + True + False + + + + 2 + 3 + 1 + 2 + + + + + True + True + False + + + + 2 + 3 + 3 + 4 + + + + + ... + True + True + True + + + 3 + 4 + 1 + 2 + + + + + ... + True + True + True + + + 3 + 4 + 3 + 4 + + + + + Start + True + True + True + + + 3 + 4 + 4 + 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + normal + + + True + 2 + + + + + + True + end + + + + + + + + + False + end + 0 + + + + + + -- cgit v1.2.3