diff --git a/CMakeLists.txt b/CMakeLists.txt index 104f108..f58cde9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ execute_process( COMMAND git describe OUTPUT_STRIP_TRAILING_WHITESPACE ) add_definitions( "-DATFA_VERSION=\"${ATFA_VERSION}\"" ) add_definitions( "-DATFA_DIR=\"${PROJECT_SOURCE_DIR}\"" ) +#add_definitions( "-DATFA_LOG_MATLAB" ) set( USUAL_FLAGS "${USUAL_FLAGS} -std=c++11 -Wall -Wextra -pedantic" ) set( DBG_FLAGS "${USUAL_FLAGS} -DATFA_DEBUG -O0 -g3 -fno-inline" ) diff --git a/src/ATFA.cpp b/src/ATFA.cpp index ed9e473..8024823 100644 --- a/src/ATFA.cpp +++ b/src/ATFA.cpp @@ -230,7 +230,6 @@ ATFA::ATFA(QWidget *parent) : delay_slider->setMinimum(0); delay_slider->setMaximum(500); delay_slider->setValue(30); - // TODO: if playback lags during sliding, disable tracking delay_layout->addWidget(delay_slider); stream.set_delay(delay_slider->value()); @@ -262,7 +261,6 @@ ATFA::ATFA(QWidget *parent) : vol_slider->setMinimum(0); vol_slider->setMaximum(100); vol_slider->setValue(50); - // TODO: if playback lags during sliding, disable tracking vol_layout->addWidget(vol_slider); vol_spin = new QSpinBox(vol_widget); diff --git a/src/Stream.cpp b/src/Stream.cpp index 128f8ae..61d3bf3 100644 --- a/src/Stream.cpp +++ b/src/Stream.cpp @@ -34,15 +34,11 @@ extern "C" { #include -/// TODO: DEBUG -#define ATFA_DEBUG -#ifdef ATFA_DEBUG -#undef ATFA_DEBUG - -#include -#include -#include -#include +#ifdef ATFA_LOG_MATLAB +# include +# include +# include +# include #endif #include "Stream.h" @@ -51,8 +47,9 @@ extern "C" { #include "AdaptiveFilter.h" #include "utils.h" -// TODO: DEBUG +#ifdef ATFA_LOG_MATLAB Stream::sample_t Stream::wvec[Stream::blks_in_buf*Stream::blk_size][128]; +#endif /// Callback function for dealing with PortAudio static int stream_callback( @@ -353,16 +350,13 @@ void Stream::stop(PaStream *s) { SCOUT("rir_thread deleted"); rir_thread = nullptr; -/// TODO: DEBUG -#define ATFA_DEBUG -#ifdef ATFA_DEBUG -#undef ATFA_DEBUG -#define ADBG_PASTE(x,y) x##y -#define MXVAR(NOME) ADBG_PASTE(mx_,NOME) -#define ADBG_STRINGIFY2(x) #x -#define ADBG_STRINGIFY(x) ADBG_STRINGIFY2(x) -#define STRMXVAR(NOME) ADBG_STRINGIFY(MXVAR(NOME)) -#define MKMXVAR(NOME, NOME_MX, III, JJJ, VAL_IJ) do { \ +#ifdef ATFA_LOG_MATLAB +# define ADBG_PASTE(x,y) x##y +# define MXVAR(NOME) ADBG_PASTE(mx_,NOME) +# define ADBG_STRINGIFY2(x) #x +# define ADBG_STRINGIFY(x) ADBG_STRINGIFY2(x) +# define STRMXVAR(NOME) ADBG_STRINGIFY(MXVAR(NOME)) +# define MKMXVAR(NOME, NOME_MX, III, JJJ, VAL_IJ) do { \ std::cout << "Criando " STRMXVAR(NOME) "..." << std::endl; \ unsigned long iii=(III), jjj=(JJJ); \ mxArray *MXVAR(NOME) = mxCreateDoubleMatrix(iii, jjj, mxREAL); \ @@ -383,7 +377,7 @@ void Stream::stop(PaStream *s) { mxDestroyArray(MXVAR(NOME)); \ } while (0) std::cout << "Abrindo arquivo..." << std::endl; - MATFile *pmat = matOpen("sampss_jan02.mat", "w"); + MATFile *pmat = matOpen("ATFA_LOG_MATLAB.mat", "w"); if (pmat == NULL) std::cout << "Erro ao abrir .mat ." << std::endl; constexpr unsigned long SAMPLES_IN_PMAT = 192000; diff --git a/src/Stream.h b/src/Stream.h index 6a009ab..c07efdc 100644 --- a/src/Stream.h +++ b/src/Stream.h @@ -24,8 +24,9 @@ extern "C" { # include } -// TODO: DEBUG -#include +#ifdef ATFA_LOG_MATLAB +# include +#endif #include #include @@ -161,10 +162,14 @@ class Stream while (read_ptr != read_end_ptr) { *out_buf = scene.volume * adapf->get_sample(*adapf_ptr, *read_ptr); - {sample_t *it; unsigned n; - adapf->get_impresp(&it, &n); - std::memcpy(&(wvec[w_ptr][0]), it, n*sizeof(sample_t)); - ++w_ptr;} // TODO: DEBUG +#ifdef ATFA_LOG_MATLAB + { + sample_t *it; unsigned n; + adapf->get_impresp(&it, &n); + std::memcpy(&(wvec[w_ptr][0]), it, n*sizeof(sample_t)); + ++w_ptr; + } +#endif ++read_ptr, ++adapf_ptr, ++out_buf; if (read_ptr == data_out.end()) read_ptr = data_out.begin(); @@ -190,6 +195,12 @@ class Stream blk_offset = current_offset % blk_size; } + +#ifdef ATFA_LOG_MATLAB +# define ATFA_STREAM_INIT_WPTR w_ptr(0), +#else +# define ATFA_STREAM_INIT_WPTR +#endif /// Contructs from a `Scenario` object /** * Constructs a Stream object from `Scenario` parameters. @@ -197,7 +208,8 @@ class Stream * \see Scenario */ Stream(LEDIndicatorWidget *ledw = nullptr, const Scenario& s = Scenario()) - : w_ptr(0), scene(s), adapf(new AdaptiveFilter()), + : ATFA_STREAM_INIT_WPTR + scene(s), adapf(new AdaptiveFilter()), is_running(false), data_in(buf_size), data_out(buf_size), vad(blks_in_buf), write_ptr(data_in.begin()), read_ptr(data_out.begin()), @@ -209,21 +221,30 @@ class Stream set_filter(scene.imp_resp, false); // sets h_freq_re and h_freq_im if (buf_size == 0) throw std::runtime_error("Stream: Bad buf_size"); if (samplerate == 0) throw std::runtime_error("Stream: Bad srate"); - {for (auto& w : wvec) - for (auto& x : w) - x = 0;} // TODO: DEBUG +#ifdef ATFA_LOG_MATLAB + { + for (auto& w : wvec) + for (auto& x : w) + x = 0; + } +#endif } - // TODO: DEBUG +#ifdef ATFA_LOG_MATLAB static sample_t wvec[blks_in_buf*blk_size][128]; int w_ptr; +#endif /// Runs the stream with predefined scenario parameters. PaStream *echo(); +#ifdef ATFA_LOG_MATLAB +# define ATFA_STREAM_STOP_ATTR __attribute__((optimize("-O0"))) +#else +# define ATFA_STREAM_STOP_ATTR +#endif /// Stops the stream that is running - // TODO: DEBUG - void stop(PaStream *s) __attribute__((optimize("-O0"))); + void stop(PaStream *s) ATFA_STREAM_STOP_ATTR; /// Sets the delay parameter, given in miliseconds /** diff --git a/src/main.cpp b/src/main.cpp index dd1240d..d62fdff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,6 @@ extern "C" { } #include "utils.h" -#include "Stream.h" // TODO: deletar isso #include "ATFA.h"