ColumnOp.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2016 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef COLUMN_OP_H
17 #define COLUMN_OP_H
18 
19 #include "BaseTypes.h"
20 
21 #include <vector>
22 
38 enum class ColumnNormalization {
39  None,
40  Max1,
41  Sum1,
42  Range01,
43  Hybrid
44 };
45 
50 class ColumnOp
51 {
52 public:
56  typedef floatvec_t Column;
57 
61  static Column applyGain(const Column &in, double gain) {
62  if (gain == 1.0) return in;
63  Column out;
64  out.reserve(in.size());
65  for (auto v: in) out.push_back(float(v * gain));
66  return out;
67  }
68 
72  static Column applyShift(const Column &in, float offset) {
73  if (offset == 0.f) return in;
74  Column out;
75  out.reserve(in.size());
76  for (auto v: in) out.push_back(v + offset);
77  return out;
78  }
79 
83  static Column fftScale(const Column &in, int fftSize);
84 
88  static bool isPeak(const Column &in, int ix) {
89  if (!in_range_for(in, ix)) {
90  return false;
91  }
92  if (ix == 0) {
93  return in[0] >= in[1];
94  }
95  if (!in_range_for(in, ix+1)) {
96  return in[ix] > in[ix-1];
97  }
98  if (in[ix] < in[ix+1]) {
99  return false;
100  }
101  if (in[ix] <= in[ix-1]) {
102  return false;
103  }
104  return true;
105  }
106 
111  static Column peakPick(const Column &in);
112 
121  static Column normalize(const Column &in, ColumnNormalization n);
122 
132  static Column distribute(const Column &in,
133  int h,
134  const std::vector<double> &binfory,
135  int minbin,
136  bool interpolate);
137 
138 };
139 
140 #endif
141 
ColumnNormalization
Display normalization types for columns in e.g.
Definition: ColumnOp.h:38
Class containing static functions for simple operations on data columns, for use by display layers...
Definition: ColumnOp.h:50
static Column applyGain(const Column &in, double gain)
Scale the given column using the given gain multiplier.
Definition: ColumnOp.h:61
static Column applyShift(const Column &in, float offset)
Shift the values in the given column by the given offset.
Definition: ColumnOp.h:72
std::vector< float, breakfastquay::StlAllocator< float > > floatvec_t
Definition: BaseTypes.h:53
floatvec_t Column
Column type.
Definition: ColumnOp.h:56
bool in_range_for(const C &container, T i)
Check whether an integer index is in range for a container, avoiding overflows and signed/unsigned co...
Definition: BaseTypes.h:37
static bool isPeak(const Column &in, int ix)
Determine whether an index points to a local peak.
Definition: ColumnOp.h:88