svcore  1.9
FFTFileCacheReader.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-2009 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 _FFT_FILE_CACHE_READER_H_
17 #define _FFT_FILE_CACHE_READER_H_
18 
19 #include "data/fileio/MatrixFile.h"
20 #include "FFTCacheReader.h"
21 #include "FFTCacheStorageType.h"
22 
23 class FFTFileCacheWriter;
24 
26 {
27 public:
30 
31  int getWidth() const;
32  int getHeight() const;
33 
34  float getMagnitudeAt(int x, int y) const;
35  float getNormalizedMagnitudeAt(int x, int y) const;
36  float getMaximumMagnitudeAt(int x) const;
37  float getPhaseAt(int x, int y) const;
38 
39  void getValuesAt(int x, int y, float &real, float &imag) const;
40  void getMagnitudesAt(int x, float *values, int minbin, int count, int step) const;
41 
42  bool haveSetColumnAt(int x) const;
43 
44  static int getCacheSize(int width, int height,
46 
48 
49 protected:
50  mutable char *m_readbuf;
51  mutable int m_readbufCol;
52  mutable int m_readbufWidth;
53  mutable bool m_readbufGood;
54 
55  float getFromReadBufStandard(int x, int y) const {
56  float v;
57  if (m_readbuf &&
58  (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) {
59  v = ((float *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y];
60  return v;
61  } else {
62  populateReadBuf(x);
63  v = getFromReadBufStandard(x, y);
64  return v;
65  }
66  }
67 
68  float getFromReadBufCompactUnsigned(int x, int y) const {
69  float v;
70  if (m_readbuf &&
71  (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) {
72  v = ((uint16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y];
73  return v;
74  } else {
75  populateReadBuf(x);
77  return v;
78  }
79  }
80 
81  float getFromReadBufCompactSigned(int x, int y) const {
82  float v;
83  if (m_readbuf &&
84  (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) {
85  v = ((int16_t *)m_readbuf)[(x - m_readbufCol) * m_mfc->getHeight() + y];
86  return v;
87  } else {
88  populateReadBuf(x);
90  return v;
91  }
92  }
93 
94  void populateReadBuf(int x) const;
95 
96  float getNormalizationFactor(int col) const {
97  int h = m_mfc->getHeight();
98  if (h < m_factorSize) return 0;
100  return getFromReadBufStandard(col, h - 1);
101  } else {
102  union {
103  float f;
104  uint16_t u[2];
105  } factor;
106  if (!m_readbuf ||
107  !(m_readbufCol == col ||
108  (m_readbufWidth > 1 && m_readbufCol+1 == col))) {
109  populateReadBuf(col);
110  }
111  int ix = (col - m_readbufCol) * m_mfc->getHeight() + h;
112  factor.u[0] = ((uint16_t *)m_readbuf)[ix - 2];
113  factor.u[1] = ((uint16_t *)m_readbuf)[ix - 1];
114  return factor.f;
115  }
116  }
117 
121 };
122 
123 #endif
float getNormalizationFactor(int col) const
void getMagnitudesAt(int x, float *values, int minbin, int count, int step) const
float getNormalizedMagnitudeAt(int x, int y) const
float getPhaseAt(int x, int y) const
float getMagnitudeAt(int x, int y) const
void getValuesAt(int x, int y, float &real, float &imag) const
FFTFileCacheReader(FFTFileCacheWriter *)
float getMaximumMagnitudeAt(int x) const
float getFromReadBufCompactSigned(int x, int y) const
int getHeight() const
Definition: MatrixFile.h:68
void populateReadBuf(int x) const
static int getCacheSize(int width, int height, FFTCache::StorageType type)
bool haveSetColumnAt(int x) const
FFTCache::StorageType m_storageType
FFTCache::StorageType getStorageType() const
float getFromReadBufCompactUnsigned(int x, int y) const
float getFromReadBufStandard(int x, int y) const