Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Log das variáveis em .mat é opcional (macro ATFA_LOG_MATLAB)
Browse files Browse the repository at this point in the history
  • Loading branch information
fofoni committed Jan 15, 2017
1 parent 11cfdcd commit 79d27ad
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
2 changes: 0 additions & 2 deletions src/ATFA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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);
Expand Down
36 changes: 15 additions & 21 deletions src/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ extern "C" {

#include <exception>

/// TODO: DEBUG
#define ATFA_DEBUG
#ifdef ATFA_DEBUG
#undef ATFA_DEBUG

#include <iostream>
#include <algorithm>
#include <fstream>
#include <mat.h>
#ifdef ATFA_LOG_MATLAB
# include <iostream>
# include <algorithm>
# include <fstream>
# include <mat.h>
#endif

#include "Stream.h"
Expand All @@ -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(
Expand Down Expand Up @@ -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); \
Expand All @@ -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;
Expand Down
47 changes: 34 additions & 13 deletions src/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ extern "C" {
# include <dlfcn.h>
}

// TODO: DEBUG
#include <cstring>
#ifdef ATFA_LOG_MATLAB
# include <cstring>
#endif

#include <vector>
#include <stdexcept>
Expand Down Expand Up @@ -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();
Expand All @@ -190,14 +195,21 @@ 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.
*
* \see Scenario
*/
Stream(LEDIndicatorWidget *ledw = nullptr, const Scenario& s = Scenario())
: w_ptr(0), scene(s), adapf(new AdaptiveFilter<sample_t>()),
: ATFA_STREAM_INIT_WPTR
scene(s), adapf(new AdaptiveFilter<sample_t>()),
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()),
Expand All @@ -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
/**
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C" {
}

#include "utils.h"
#include "Stream.h" // TODO: deletar isso

#include "ATFA.h"

Expand Down

0 comments on commit 79d27ad

Please sign in to comment.