From 105b3b753f4ad2f0870e56e5f8185a03d9e5f232 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Thu, 26 Oct 2023 14:32:16 +0200 Subject: [PATCH] Formatting. --- architecture/comparator/compclass.cpp | 417 +++++++++--------- .../comparator/minimal-fixed-point.cpp | 117 +---- .../comparator/minimal-floating-point.cpp | 5 +- 3 files changed, 201 insertions(+), 338 deletions(-) diff --git a/architecture/comparator/compclass.cpp b/architecture/comparator/compclass.cpp index 3a6e417637..3e90a136ae 100644 --- a/architecture/comparator/compclass.cpp +++ b/architecture/comparator/compclass.cpp @@ -1,19 +1,21 @@ -#include "float.cpp" -#include "fixed.cpp" #include - #include -#include "faust/dsp/dsp-tools.h" -#include #include #include +#include +#include "faust/dsp/dsp-tools.h" + +// Auto-generated +#include "float.cpp" +#include "fixed.cpp" #ifndef FAUSTFLOAT #define FAUSTFLOAT float #endif -// typedef sf_count_t (* sample_read)(SNDFILE* sndfile, void* buffer, sf_count_t frames); +using namespace std; + typedef sf_count_t (* sample_write)(SNDFILE* sndfile, void* buffer, sf_count_t frames); class comparateur { @@ -34,25 +36,22 @@ class comparateur { FAUSTFLOAT** createbuffer (int chan, int buffer_size) { - FAUSTFLOAT** buffer = new FAUSTFLOAT*[chan]; - for (int i = 0; i < chan; i++) { - buffer[i] = new FAUSTFLOAT[buffer_size]; - memset(buffer[i], 0, sizeof(FAUSTFLOAT) * buffer_size); - } - return buffer; + for (int i = 0; i < chan; i++) { + buffer[i] = new FAUSTFLOAT[buffer_size]; + memset(buffer[i], 0, sizeof(FAUSTFLOAT) * buffer_size); + } + return buffer; } void deletebuffer (FAUSTFLOAT** buffer, int chan) { - for (int i = 0; i getNumOutputs()); } - - std::ofstream logging_file; - - if (logging) - { - std::string filename = "samples-"+name+".log"; - logging_file.open(filename.c_str()); - } - + + ofstream logging_file; + + if (logging) { + string filename = "samples-"+name+".log"; + logging_file.open(filename.c_str()); + } + sizechosen = size; int slice = size; comp = createbuffer(FL->getNumOutputs(),size); - - snr = 0; //signal to noise ratio - float power_signal = 0; - float power_noise = 0; - int t = 0; + snr = 0; //signal to noise ratio + float power_signal = 0; + float power_noise = 0; + + int t = 0; do { - int blocsize = std::min(buffersize, slice); - FX->compute(blocsize, inputs, FX_outputs); - FL->compute(blocsize, inputs, FL_outputs); - - for (int chan=0; changetNumOutputs(); ++chan) - { - FAUSTFLOAT* sub_comp = comp[chan]; - FAUSTFLOAT* sub_FL_outputs = FL_outputs[chan]; - FAUSTFLOAT* sub_FX_outputs = FX_outputs[chan]; - for (int frame=0; frame 0); - - snr = log(power_signal/power_noise); + int blocsize = min(buffersize, slice); + FX->compute(blocsize, inputs, FX_outputs); + FL->compute(blocsize, inputs, FL_outputs); + + for (int chan=0; changetNumOutputs(); ++chan) { + FAUSTFLOAT* sub_comp = comp[chan]; + FAUSTFLOAT* sub_FL_outputs = FL_outputs[chan]; + FAUSTFLOAT* sub_FX_outputs = FX_outputs[chan]; + for (int frame = 0; frame 0); + + snr = log(power_signal/power_noise); } void display() { FAUSTFLOAT totalcomp = 0; - FAUSTFLOAT compmax=0; - - for (int frame=0; frame < sizechosen; ++frame) - { - std::cout << "frame: "<< frame; - for (int chan=0; chan< FL->getNumOutputs(); ++chan) - { + FAUSTFLOAT compmax = 0; + + for (int frame=0; frame < sizechosen; ++frame) { + cout << "frame: "<< frame; + for (int chan = 0; chan< FL->getNumOutputs(); ++chan) { FAUSTFLOAT* sub_comp = comp[chan]; - - std::cout << " | Channel " << chan+1 << " :" << sub_comp[frame] << "\t"; - - totalcomp = totalcomp + std::abs(sub_comp[frame]); - compmax = std::max(compmax,std::abs(sub_comp[frame])); - } - - std::cout << std::endl; + cout << " | Channel " << chan+1 << " :" << sub_comp[frame] << "\t"; + totalcomp = totalcomp + abs(sub_comp[frame]); + compmax = max(compmax,abs(sub_comp[frame])); + } + cout << endl; } - std :: cout << "Total Amount : " << totalcomp << std::endl; - std :: cout << "Relative error : " << totalcomp/(FL->getNumOutputs()*sizechosen) << std::endl; - std :: cout << "Max : " << compmax << std::endl; - std :: cout << "SNR : " << snr << std::endl; + cout << "Total Amount : " << totalcomp << endl; + cout << "Relative error : " << totalcomp/(FL->getNumOutputs()*sizechosen) << endl; + cout << "Max : " << compmax << endl; + cout << "SNR : " << snr << endl; } virtual ~comparateur() @@ -150,154 +142,143 @@ class comparateur { }; -std::list GUI::fGuiList; -ztimedmap GUI::gTimedZoneMap; - int main(int argc, char* argv[]) { - // sample rate and buffer size - int samplerate = 44100; - int buffersize = 512; - - // parsing of options - int opt; - - bool execute = false; - bool logging = false; - bool help = false; - - while((opt = getopt(argc, argv, ":lwh")) != -1) - { - switch(opt) - { - case 'l': - logging = true; - break; - case 'w': - execute = true; - break; - case 'h': - help = true; - break; - } + // sample rate and buffer size + int samplerate = 44100; + int buffersize = 512; + + // parsing of options + int opt; + + bool execute = false; + bool logging = false; + bool help = false; + + while ((opt = getopt(argc, argv, ":lwh")) != -1) { + switch (opt) { + case 'l': + logging = true; + break; + case 'w': + execute = true; + break; + case 'h': + help = true; + break; + } } - - if (help) - { - std::cout << "Usage: " - << argv[0] << " [options]" << std::endl - << "Options :"<< std::endl - << "\t -w : writes the floating-point and fixed-point outputs to sound files" << std::endl - << "\t -l : logs the floating-point and fixed-point samples to a text file" << std::endl - << "\t -h : displays this help message" << std::endl ; - return 0; + + if (help) { + cout << "Usage: " + << argv[0] << " [options]" << endl + << "Options :"<< endl + << "\t -w : writes the floating-point and fixed-point outputs to sound files" << endl + << "\t -l : logs the floating-point and fixed-point samples to a text file" << endl + << "\t -h : displays this help message" << endl ; + return 0; } - - // init - fldsp FL; - fxdsp FX; - FL.init(samplerate); - FX.init(samplerate); - - std::string executable_name(argv[0]); - std::string filename = executable_name.substr(executable_name.rfind("/")+1); - if (execute){ - // number of samples to compute for each DSP - int audiolength = 3; - int samplenb = audiolength*samplerate; - - sample_write writer; - if (sizeof(FAUSTFLOAT) == 4) - writer = reinterpret_cast(sf_writef_float); - else - writer = reinterpret_cast(sf_writef_double); - - //////////////////////////////////// - // execute floating-point version // - //////////////////////////////////// - char name[256]; - snprintf(name, 256, "%s", ("float-"+filename+".wav").c_str()); - - /* FAUSTFLOAT** inputs = new FAUSTFLOAT*[FL.getNumInputs()]; - for (int i=0; i< FL.getNumInputs(); i++){ - inputs[i] = new FAUSTFLOAT[buffersize]; - memset(inputs[i], 0, sizeof(FAUSTFLOAT) * buffersize); - }*/ - - SF_INFO out_info = { - samplenb, - samplerate, - FL.getNumOutputs(), - SF_FORMAT_WAV|SF_FORMAT_PCM_24|SF_ENDIAN_LITTLE, - 0, - 0 - }; - - SNDFILE* out_sf_fl = sf_open(name, SFM_WRITE, &out_info); - if (!out_sf_fl) { - std::cerr << "ERROR : cannot write output file " << name << std::endl; - sf_perror(out_sf_fl); - exit(1); - } - - Interleaver ilvFL(buffersize, FL.getNumOutputs(), FL.getNumOutputs()); - - // compute samples - int cur_frame = 0; - do { - int blocsize = std::min(buffersize, samplenb - cur_frame); - - FL.compute(blocsize, nullptr, ilvFL.inputs()); - ilvFL.interleave(); - writer(out_sf_fl, ilvFL.output(), blocsize); - cur_frame += blocsize; - } while (cur_frame < samplenb); - - sf_close(out_sf_fl); - - ///////////////////////////////// - // execute fixed-point version // - ///////////////////////////////// - snprintf(name, 256, "%s", ("fixed-"+filename+".wav").c_str()); - - out_info = { - samplenb, - samplerate, - FX.getNumOutputs(), - SF_FORMAT_WAV|SF_FORMAT_PCM_24|SF_ENDIAN_LITTLE, - 0, - 0 - }; - std::cout << "Format = " << (int)(SF_FORMAT_WAV|SF_FORMAT_PCM_24|SF_ENDIAN_LITTLE) << std::endl; - SNDFILE* out_sf_fx = sf_open(name, SFM_WRITE, &out_info); - if (!out_sf_fx) { - std::cerr << "ERROR : cannot write output file " << name << std::endl; - sf_perror(out_sf_fx); - exit(1); - } - - Interleaver ilvFX(buffersize, FX.getNumOutputs(), FX.getNumOutputs()); - - // compute samples - cur_frame = 0; - do { - int blocsize = std::min(buffersize, samplenb - cur_frame); - - FX.compute(blocsize, nullptr, ilvFX.inputs()); - ilvFX.interleave(); - writer(out_sf_fx, ilvFX.output(), blocsize); - cur_frame += blocsize; - } while (cur_frame < samplenb); - - sf_close(out_sf_fx); - - + // init + fldsp FL; + fxdsp FX; + FL.init(samplerate); + FX.init(samplerate); + + string executable_name(argv[0]); + string filename = executable_name.substr(executable_name.rfind("/")+1); + + if (execute){ + // number of samples to compute for each DSP + int audiolength = 3; + int samplenb = audiolength*samplerate; + + sample_write writer; + if (sizeof(FAUSTFLOAT) == 4) { + writer = reinterpret_cast(sf_writef_float); + } else { + writer = reinterpret_cast(sf_writef_double); + } + + //////////////////////////////////// + // execute floating-point version // + //////////////////////////////////// + char name[256]; + snprintf(name, 256, "%s", ("float-"+filename+".wav").c_str()); + + /* FAUSTFLOAT** inputs = new FAUSTFLOAT*[FL.getNumInputs()]; + for (int i=0; i< FL.getNumInputs(); i++){ + inputs[i] = new FAUSTFLOAT[buffersize]; + memset(inputs[i], 0, sizeof(FAUSTFLOAT) * buffersize); + }*/ + + SF_INFO out_info = { + samplenb, + samplerate, + FL.getNumOutputs(), + SF_FORMAT_WAV|SF_FORMAT_PCM_24|SF_ENDIAN_LITTLE, + 0, + 0 + }; + + SNDFILE* out_sf_fl = sf_open(name, SFM_WRITE, &out_info); + if (!out_sf_fl) { + cerr << "ERROR : cannot write output file " << name << endl; + sf_perror(out_sf_fl); + exit(1); + } + Interleaver ilvFL(buffersize, FL.getNumOutputs(), FL.getNumOutputs()); + + // compute samples + int cur_frame = 0; + do { + int blocsize = min(buffersize, samplenb - cur_frame); + FL.compute(blocsize, nullptr, ilvFL.inputs()); + ilvFL.interleave(); + writer(out_sf_fl, ilvFL.output(), blocsize); + cur_frame += blocsize; + } while (cur_frame < samplenb); + + sf_close(out_sf_fl); + + ///////////////////////////////// + // execute fixed-point version // + ///////////////////////////////// + snprintf(name, 256, "%s", ("fixed-"+filename+".wav").c_str()); + + out_info = { + samplenb, + samplerate, + FX.getNumOutputs(), + SF_FORMAT_WAV|SF_FORMAT_PCM_24|SF_ENDIAN_LITTLE, + 0, + 0 + }; + cout << "Format = " << (int)(SF_FORMAT_WAV|SF_FORMAT_PCM_24|SF_ENDIAN_LITTLE) << endl; + SNDFILE* out_sf_fx = sf_open(name, SFM_WRITE, &out_info); + if (!out_sf_fx) { + cerr << "ERROR : cannot write output file " << name << endl; + sf_perror(out_sf_fx); + exit(1); + } + Interleaver ilvFX(buffersize, FX.getNumOutputs(), FX.getNumOutputs()); + + // compute samples + cur_frame = 0; + do { + int blocsize = min(buffersize, samplenb - cur_frame); + FX.compute(blocsize, nullptr, ilvFX.inputs()); + ilvFX.interleave(); + writer(out_sf_fx, ilvFX.output(), blocsize); + cur_frame += blocsize; + } while (cur_frame < samplenb); + + sf_close(out_sf_fx); } - + FL.init(48000); FX.init(48000); - + comparateur comp((dsp*) &FL, (dsp*) &FX); comp.compare(200, logging, filename); comp.display(); diff --git a/architecture/comparator/minimal-fixed-point.cpp b/architecture/comparator/minimal-fixed-point.cpp index 926c126b68..93341efa21 100644 --- a/architecture/comparator/minimal-fixed-point.cpp +++ b/architecture/comparator/minimal-fixed-point.cpp @@ -38,8 +38,6 @@ #include "faust/gui/UI.h" #include "faust/gui/meta.h" #include "faust/dsp/dsp.h" -#include "faust/audio/dummy-audio.h" -#include "faust/dsp/one-sample-dsp.h" #if defined(SOUNDFILE) #include "faust/gui/SoundUI.h" @@ -47,119 +45,13 @@ #include "ap_fixed.h" - - typedef ap_fixed<32,8,AP_RND_CONV,AP_SAT> fixpoint_t; + // m: position of the most significant bit of the value, without taking the sign bit into account // l: LSB with negative coding #define sfx_t(m,l) ap_fixed<((m+1)-l+1),(m+1)+1,AP_RND_CONV,AP_SAT> #define ufx_t(m,l) ap_ufixed<((m+1)-l),(m+1),AP_RND_CONV,AP_SAT> -/* -// fx version -inline fixpoint_t fabsfx(fixpoint_t x) -{ - return fixpoint_t(std::fabs(float(x))); -} -inline fixpoint_t acosfx(fixpoint_t x) -{ - return fixpoint_t(std::acos(float(x))); -} -inline fixpoint_t asinfx(fixpoint_t x) -{ - return fixpoint_t(std::asin(float(x))); -} -inline fixpoint_t atanfx(fixpoint_t x) -{ - return fixpoint_t(std::atan(float(x))); -} -inline fixpoint_t atan2fx(fixpoint_t x, fixpoint_t y) -{ - return fixpoint_t(std::atan2(float(x), float(y))); -} -inline fixpoint_t ceilfx(fixpoint_t x) -{ - return fixpoint_t(std::ceil(float(x))); -} -inline fixpoint_t cosfx(fixpoint_t x) -{ - return fixpoint_t(std::cos(float(x))); -} -inline fixpoint_t expfx(fixpoint_t x) -{ - return fixpoint_t(std::exp(float(x))); -} -inline fixpoint_t exp2fx(fixpoint_t x) -{ - return fixpoint_t(std::exp2(float(x))); -} -inline fixpoint_t exp10fx(fixpoint_t x) -{ -#ifdef __APPLE__ - return fixpoint_t(__exp10f(float(x))); -#else - return fixpoint_t(std::exp10(float(x))); -#endif -} -inline fixpoint_t floorfx(fixpoint_t x) -{ - return fixpoint_t(std::floor(float(x))); -} -inline fixpoint_t fmodfx(fixpoint_t x, fixpoint_t y) -{ - return fixpoint_t(std::fmod(float(x), float(y))); -} -inline fixpoint_t logfx(fixpoint_t x) -{ - return fixpoint_t(std::log(float(x))); -} -inline fixpoint_t log2fx(fixpoint_t x) -{ - return fixpoint_t(std::log2(float(x))); -} -inline fixpoint_t log10fx(fixpoint_t x) -{ - return fixpoint_t(std::log10(float(x))); -} -inline fixpoint_t powfx(fixpoint_t x, fixpoint_t y) -{ - return fixpoint_t(std::pow(float(x), float(y))); -} -inline fixpoint_t remainderfx(fixpoint_t x, fixpoint_t y) -{ - return fixpoint_t(std::remainder(float(x), float(y))); -} -inline fixpoint_t rintfx(fixpoint_t x) -{ - return fixpoint_t(std::rint(float(x))); -} -inline fixpoint_t roundfx(fixpoint_t x) -{ - return fixpoint_t(std::round(float(x))); -} -inline fixpoint_t sinfx(fixpoint_t x) -{ - return fixpoint_t(std::sin(float(x))); -} -inline fixpoint_t sqrtfx(fixpoint_t x) -{ - return fixpoint_t(std::sqrt(float(x))); -} -inline fixpoint_t tanfx(fixpoint_t x) -{ - return fixpoint_t(std::tan(float(x))); -} -// min/max -inline fixpoint_t fminfx(fixpoint_t x, fixpoint_t y) -{ - return fixpoint_t(std::min(float(x), float(y))); -} -inline fixpoint_t fmaxfx(fixpoint_t x, fixpoint_t y) -{ - return fixpoint_t(std::max(float(x), float(y))); -} -*/ - // fx version inline float fabsfx(float x) { @@ -253,11 +145,6 @@ inline float tanfx(float x) { return std::tan(x); } -// min/max -/* -#define minfx(x, y) { (((x) < (y)) ? (x) : (y)) } -#define maxfx(x, y) { (((x) < (y)) ? (y) : (x)) } -*/ inline float minfx(float x, float y) { return (x < y) ? x : y; } inline float maxfx(float x, float y) { return (x < y) ? y : x; } @@ -282,6 +169,4 @@ inline float maxfx(float x, float y) { return (x < y) ? y : x; } /*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/ - - /******************* END minimal-fixed-point.cpp ****************/ diff --git a/architecture/comparator/minimal-floating-point.cpp b/architecture/comparator/minimal-floating-point.cpp index 012cb41a3a..ce44a200f4 100644 --- a/architecture/comparator/minimal-floating-point.cpp +++ b/architecture/comparator/minimal-floating-point.cpp @@ -35,8 +35,7 @@ #include "faust/gui/PrintUI.h" #include "faust/gui/meta.h" -#include "faust/audio/dummy-audio.h" -#include "faust/dsp/one-sample-dsp.h" +#include "faust/dsp/dsp.h" // faust -a minimal.cpp noise.dsp -o noise.cpp && c++ -std=c++11 noise.cpp -o noise && ./noise @@ -60,7 +59,5 @@ /*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/ - - /******************* END minimal.cpp ****************/