annotate base/ColumnOp.h @ 1373:7a38b2cbb6c1

Catch exception from initialise
author Chris Cannam
date Mon, 06 Feb 2017 09:18:44 +0000
parents dd190086db73
children 9ef1cc26024c
rev   line source
Chris@1187 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1187 2
Chris@1187 3 /*
Chris@1187 4 Sonic Visualiser
Chris@1187 5 An audio file viewer and annotation editor.
Chris@1187 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1188 7 This file copyright 2006-2016 Chris Cannam and QMUL.
Chris@1187 8
Chris@1187 9 This program is free software; you can redistribute it and/or
Chris@1187 10 modify it under the terms of the GNU General Public License as
Chris@1187 11 published by the Free Software Foundation; either version 2 of the
Chris@1187 12 License, or (at your option) any later version. See the file
Chris@1187 13 COPYING included with this distribution for more information.
Chris@1187 14 */
Chris@1187 15
Chris@1187 16 #ifndef COLUMN_OP_H
Chris@1187 17 #define COLUMN_OP_H
Chris@1187 18
Chris@1187 19 #include "BaseTypes.h"
Chris@1187 20
Chris@1265 21 #include <vector>
Chris@1187 22
Chris@1190 23 /**
Chris@1193 24 * Display normalization types for columns in e.g. grid plots.
Chris@1193 25 *
Chris@1193 26 * Max1 means to normalize to max value = 1.0.
Chris@1193 27 * Sum1 means to normalize to sum of values = 1.0.
Chris@1193 28 *
Chris@1193 29 * Hybrid means normalize to max = 1.0 and then multiply by
Chris@1193 30 * log10 of the max value, to retain some difference between
Chris@1193 31 * levels of neighbouring columns.
Chris@1193 32 *
Chris@1193 33 * Area normalization is handled separately.
Chris@1193 34 */
Chris@1193 35 enum class ColumnNormalization {
Chris@1193 36 None,
Chris@1193 37 Max1,
Chris@1193 38 Sum1,
Chris@1193 39 Hybrid
Chris@1193 40 };
Chris@1193 41
Chris@1193 42 /**
Chris@1190 43 * Class containing static functions for simple operations on data
Chris@1190 44 * columns, for use by display layers.
Chris@1190 45 */
Chris@1187 46 class ColumnOp
Chris@1187 47 {
Chris@1187 48 public:
Chris@1190 49 /**
Chris@1190 50 * Column type.
Chris@1190 51 */
Chris@1187 52 typedef std::vector<float> Column;
Chris@1187 53
Chris@1190 54 /**
Chris@1195 55 * Scale the given column using the given gain multiplier.
Chris@1195 56 */
Chris@1197 57 static Column applyGain(const Column &in, double gain) {
Chris@1266 58 if (gain == 1.0) return in;
Chris@1195 59 Column out;
Chris@1195 60 out.reserve(in.size());
Chris@1266 61 for (auto v: in) out.push_back(float(v * gain));
Chris@1195 62 return out;
Chris@1195 63 }
Chris@1195 64
Chris@1195 65 /**
Chris@1265 66 * Scale an FFT output downward by half the FFT size.
Chris@1190 67 */
Chris@1266 68 static Column fftScale(const Column &in, int fftSize);
Chris@1187 69
Chris@1190 70 /**
Chris@1190 71 * Determine whether an index points to a local peak.
Chris@1190 72 */
Chris@1187 73 static bool isPeak(const Column &in, int ix) {
Chris@1265 74 if (!in_range_for(in, ix)) {
Chris@1265 75 return false;
Chris@1265 76 }
Chris@1265 77 if (ix == 0) {
Chris@1265 78 return in[0] >= in[1];
Chris@1265 79 }
Chris@1265 80 if (!in_range_for(in, ix+1)) {
Chris@1265 81 return in[ix] > in[ix-1];
Chris@1265 82 }
Chris@1265 83 if (in[ix] < in[ix+1]) {
Chris@1265 84 return false;
Chris@1265 85 }
Chris@1265 86 if (in[ix] <= in[ix-1]) {
Chris@1265 87 return false;
Chris@1265 88 }
Chris@1187 89 return true;
Chris@1187 90 }
Chris@1187 91
Chris@1190 92 /**
Chris@1190 93 * Return a column containing only the local peak values (all
Chris@1190 94 * others zero).
Chris@1190 95 */
Chris@1266 96 static Column peakPick(const Column &in);
Chris@1187 97
Chris@1190 98 /**
Chris@1190 99 * Return a column normalized from the input column according to
Chris@1190 100 * the given normalization scheme.
Chris@1266 101 *
Chris@1266 102 * Note that the sum or max (as appropriate) used for
Chris@1266 103 * normalisation will be calculated from the absolute values of
Chris@1266 104 * the column elements, should any of them be negative.
Chris@1190 105 */
Chris@1266 106 static Column normalize(const Column &in, ColumnNormalization n);
Chris@1266 107
Chris@1190 108 /**
Chris@1190 109 * Distribute the given column into a target vector of a different
Chris@1190 110 * size, optionally using linear interpolation. The binfory vector
Chris@1190 111 * contains a mapping from y coordinate (i.e. index into the
Chris@1265 112 * target vector) to bin (i.e. index into the source column). The
Chris@1265 113 * source column ("in") may be a partial column; it's assumed to
Chris@1265 114 * contain enough bins to span the destination range, starting
Chris@1265 115 * with the bin of index minbin.
Chris@1190 116 */
Chris@1187 117 static Column distribute(const Column &in,
Chris@1187 118 int h,
Chris@1187 119 const std::vector<double> &binfory,
Chris@1187 120 int minbin,
Chris@1266 121 bool interpolate);
Chris@1187 122
Chris@1187 123 };
Chris@1187 124
Chris@1187 125 #endif
Chris@1187 126