Permalink
Browse files

debugging aids and ICM

  • Loading branch information...
1 parent 8a239a9 commit d6ef0addcbbb81ac1a28f64a556941df573cfa60 @hmmr committed Apr 17, 2012
View
@@ -13,6 +13,8 @@
#ifndef _AGH_MISC_H
#define _AGH_MISC_H
+#include <sys/stat.h>
+#include <fcntl.h>
#include <cstdlib>
#include <string>
#include <memory>
@@ -24,6 +26,8 @@
using namespace std;
+namespace agh {
+
#if __GNUC__ >= 3
// # define __pure __attribute__ ((pure))
// # define __const __attribute__ ((const))
@@ -51,12 +55,9 @@ using namespace std;
# define unlikely(x) (x)
#endif
-typedef std::valarray<TFloat> VAF;
-
-
-#define DEF_UNIQUE_CHARP(p) \
- char* p = NULL; \
+#define DEF_UNIQUE_CHARP(p) \
+ char* p = nullptr; \
unique_ptr<void,void(*)(void*)> p##_pp(p,free);
@@ -105,6 +106,23 @@ value_within( TFloat v, const TFloat& l, const TFloat& h)
+typedef std::valarray<TFloat> VAF;
+
+// debugging aids
+inline void
+vaf_dump( const VAF& v, const string& fname, size_t size = -1)
+{
+ if ( size == (size_t)-1 )
+ size = v.size();
+ int fd;
+ if ( (fd = open( fname.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1 ||
+ write( fd, &v[0], size * sizeof(TFloat)) == -1 )
+ printf( "so broken even vaf_dump failed\n");
+ close( fd);
+}
+
+} // namespace agh
+
#endif
// eof
View
@@ -11,9 +11,7 @@
* License: GPL
*/
-#include <sys/stat.h>
#include <unistd.h>
-#include <fcntl.h>
#include <limits.h>
#include <cassert>
#include <functional>
@@ -115,7 +113,7 @@ sigfile::CBinnedMC::
compute( const SMCParamSet& req_params,
bool force)
{
- hash_t req_signature = _using_F.artifacts( _using_sig_no).dirty_signature();
+ agh::hash_t req_signature = _using_F.artifacts( _using_sig_no).dirty_signature();
if ( have_data() && (*this) == req_params
&& _signature == req_signature )
return 0;
@@ -231,7 +229,6 @@ void
sigfile::CBinnedMC::
do_sssu_reduction()
{
- //size_t total_samples = pages() * CPageMetrics_base::pagesize() * samplerate();
valarray<TFloat>
due_filtered,
se_filtered;
@@ -240,19 +237,9 @@ do_sssu_reduction()
due_filtered = due_filter.apply( signal, true);
se_filtered = se_filter.apply( signal, true);
- int fd;
- if ( (fd = open( (fname_base()+".due").c_str(), O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1 ||
- write( fd, &due_filtered[0], 2000 * sizeof(TFloat)) == -1 )
- ;
- close( fd);
- if ( (fd = open( (fname_base()+".se").c_str(), O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1 ||
- write( fd, &se_filtered[0], 2000 * sizeof(TFloat)) == -1 )
- ;
- close( fd);
}
size_t integrate_samples = scope * samplerate();
- printf( ": scope %g, samplerate %zu\n", scope, samplerate());
for ( size_t p = 0; p < pages(); ++p ) {
auto range = slice (p * integrate_samples, integrate_samples, 1);
@@ -385,28 +372,28 @@ mc_smooth_update_artifacts( bool smooth_reset, size_t p)
if ( smooth_reset )
art_hf = art_lf = art_zero = 0;
- TFloat art_factor = value_within((ss[p] - su[p] - pib) / pib, -1000., 1000.); // Avoid overflow of art_HF
+ TFloat art_factor = agh::value_within((ss[p] - su[p] - pib) / pib, -1000., 1000.); // Avoid overflow of art_HF
if ( art_factor >= xpi_bplus ) // XpiBPlus >= 1
// todo: Bob controleren art_HF, art_LF en art_Zero: eerst afronden daarna *SmoothTime ?
art_hf += round( art_factor / xpi_bplus) * scope;
else
art_hf -= scope;
- ensure_within( art_hf, (TFloat)0., art_max_secs);
+ agh::ensure_within( art_hf, (TFloat)0., art_max_secs);
if ( art_factor <= xpi_bminus)
art_lf += round( art_factor / xpi_bminus) * scope;
else
art_lf -= scope;
- ensure_within( art_lf, 0., art_max_secs);
+ agh::ensure_within( art_lf, 0., art_max_secs);
if ( ss[p] <= pib / xpi_bzero )
art_zero += round( (pib / xpi_bzero) - ss[p]) * scope;
else
art_zero -= scope;
- ensure_within( art_zero, 0., min( 1., scope));
+ agh::ensure_within( art_zero, 0., min( 1., scope));
}
void
@@ -711,7 +698,7 @@ mc_smooth_detect_events_reset_jumps( size_t at, TDirection direction)
} else {
TFloat r = mc_jump [at] + (_suForw[kz] - _suBack[kz]) / 2,
s = mc_event[at] + (_ssForw[kz] + _ssBack[kz]) / 2;
- mc_event[at] = round( value_within(100 * mc_gain * r / s, (TFloat)-INT_MAX, (TFloat)INT_MAX));
+ mc_event[at] = round( agh::value_within(100 * mc_gain * r / s, (TFloat)-INT_MAX, (TFloat)INT_MAX));
// Clean MCJump from this temporary storage necessary for MCevent
mc_jump [at] = 0;
}
View
@@ -225,7 +225,7 @@ sigfile::CBinnedPower::compute( const SFFTParamSet& req_params,
bool force)
{
// check if we have it already
- hash_t req_signature = _using_F.artifacts( _using_sig_no).dirty_signature();
+ agh::hash_t req_signature = _using_F.artifacts( _using_sig_no).dirty_signature();
if ( have_data() && (*this) == req_params
&& _signature == req_signature )
return 0;
@@ -57,7 +57,7 @@ sigfile::SArtifacts::clear_artifact( size_t aa, size_t az)
}
-hash_t
+agh::hash_t
sigfile::SArtifacts::dirty_signature() const
{
string sig ("a");
@@ -91,7 +91,7 @@ struct SArtifacts {
void mark_artifact( size_t aa, size_t az);
void clear_artifact( size_t aa, size_t az);
- hash_t dirty_signature() const;
+ agh::hash_t dirty_signature() const;
};
@@ -77,8 +77,8 @@ aghui::SScoringFacility::SChannel::draw_page_static( cairo_t *cr,
// marquee, goes first, not to obscure waveforms
if ( draw_marquee // possibly undesired (such as when drawing for unfazer)
- && overlap( selection_start_time, selection_end_time,
- _p.cur_xvpage_start(), _p.cur_xvpage_end()) ) {
+ && agh::overlap( selection_start_time, selection_end_time,
+ _p.cur_xvpage_start(), _p.cur_xvpage_end()) ) {
double pre = _p.skirting_run_per1 * _p.vpagesize(),
ma = (selection_start_time - _p.cur_xvpage_start()) / _p.xvpagesize() * wd,
me = (selection_end_time - _p.cur_xvpage_start()) / _p.xvpagesize() * wd;
@@ -206,7 +206,7 @@ aghui::SScoringFacility::SChannel::draw_page_static( cairo_t *cr,
_p._p.CwB[SExpDesignUI::TColour::artifact].set_source_rgba( cr, // do some gradients perhaps?
.4);
for ( auto &A : Aa() ) {
- if ( overlap( (int)A.first, (int)A.second, cvpa, cvpe) ) {
+ if ( agh::overlap( (int)A.first, (int)A.second, cvpa, cvpe) ) {
int aa = (int)A.first - cvpa,
ae = (int)A.second - cvpa;
if ( aa < 0 ) aa = 0;
@@ -234,7 +234,7 @@ aghui::SScoringFacility::SChannel::draw_page_static( cairo_t *cr,
if ( not Aa.empty() ) {
int on_this_page = 0;
for ( auto &A : Aa ) {
- if ( overlap( (int)A.span.first, (int)A.span.second, cvpa, cvpe) ) {
+ if ( agh::overlap( (int)A.span.first, (int)A.span.second, cvpa, cvpe) ) {
int disp = pbot - ++on_this_page * 5;
cairo_pattern_t *cp = cairo_pattern_create_linear( 0., disp, 0., disp-30);
_p._p.CwB[SExpDesignUI::TColour::annotations].pattern_add_color_stop_rgba( cp, 0.);
@@ -162,8 +162,8 @@ daSFMontage_button_press_event_cb( GtkWidget *wid, GdkEventButton *event, gpoint
not (SF.over_annotations = Ch->in_annotations( cpos)) . empty();
gtk_widget_set_visible( (GtkWidget*)SF.mSFPageAnnotation, over_any);
gtk_widget_set_visible( (GtkWidget*)SF.iSFPageAnnotationSeparator, over_any);
- gtk_menu_popup( overlap( Ch->selection_start_time, Ch->selection_end_time,
- cpos, cpos) ? SF.mSFPageSelection : SF.mSFPage,
+ gtk_menu_popup( agh::overlap( Ch->selection_start_time, Ch->selection_end_time,
+ cpos, cpos) ? SF.mSFPageSelection : SF.mSFPage,
NULL, NULL, NULL, NULL, 3, event->time);
}
break;
@@ -81,8 +81,8 @@ aghui::SScoringFacility::SChannel::in_annotations( double time) const
ret;
size_t pos = time * crecording.F().samplerate(name);
for ( auto &A : annotations )
- if ( overlap( A.span.first, A.span.second,
- pos, pos) )
+ if ( agh::overlap( A.span.first, A.span.second,
+ pos, pos) )
ret.push_back( &A);
return ret;
}

0 comments on commit d6ef0ad

Please sign in to comment.