svcore  1.9
WaveFileModel.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 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 _WAVE_FILE_MODEL_H_
17 #define _WAVE_FILE_MODEL_H_
18 
19 #include "base/Thread.h"
20 #include <QMutex>
21 #include <QTimer>
22 
23 #include "data/fileio/FileSource.h"
24 
27 
28 #include <stdlib.h>
29 
30 class AudioFileReader;
31 
33 {
34  Q_OBJECT
35 
36 public:
37  WaveFileModel(FileSource source, int targetRate = 0);
38  WaveFileModel(FileSource source, AudioFileReader *reader);
40 
41  bool isOK() const;
42  bool isReady(int *) const;
43 
45 
46  int getFrameCount() const;
47  int getChannelCount() const;
48  int getSampleRate() const;
49  int getNativeRate() const;
50 
51  QString getTitle() const;
52  QString getMaker() const;
53  QString getLocation() const;
54 
55  virtual Model *clone() const;
56 
57  float getValueMinimum() const { return -1.0f; }
58  float getValueMaximum() const { return 1.0f; }
59 
60  virtual int getStartFrame() const { return m_startFrame; }
61  virtual int getEndFrame() const { return m_startFrame + getFrameCount(); }
62 
63  void setStartFrame(int startFrame) { m_startFrame = startFrame; }
64 
65  virtual int getData(int channel, int start, int count,
66  float *buffer) const;
67 
68  virtual int getData(int channel, int start, int count,
69  double *buffer) const;
70 
71  virtual int getData(int fromchannel, int tochannel,
72  int start, int count,
73  float **buffers) const;
74 
75  virtual int getSummaryBlockSize(int desired) const;
76 
77  virtual void getSummaries(int channel, int start, int count,
78  RangeBlock &ranges,
79  int &blockSize) const;
80 
81  virtual Range getSummary(int channel, int start, int count) const;
82 
83  QString getTypeName() const { return tr("Wave File"); }
84 
85  virtual void toXml(QTextStream &out,
86  QString indent = "",
87  QString extraAttributes = "") const;
88 
89 protected slots:
90  void fillTimerTimedOut();
91  void cacheFilled();
92 
93 protected:
94  void initialize();
95 
97  {
98  public:
100  m_model(model), m_fillExtent(0),
101  m_frameCount(model.getFrameCount()) { }
102 
103  int getFillExtent() const { return m_fillExtent; }
104  virtual void run();
105 
106  protected:
110  };
111 
112  void fillCache();
113 
115  QString m_path;
118 
120 
121  RangeBlock m_cache[2]; // interleaved at two base resolutions
122  mutable QMutex m_mutex;
124  QTimer *m_updateTimer;
126  bool m_exiting;
128 
132  mutable QMutex m_directReadMutex;
133 };
134 
135 #endif
FileSource m_source
AudioFileReader * m_reader
virtual int getEndFrame() const
Return the last audio frame spanned by the model.
Definition: WaveFileModel.h:61
int getSampleRate() const
Return the frame rate in frames per second.
int getNativeRate() const
Return the frame rate of the underlying material, if the model itself has already been resampled.
std::vector< float > SampleBlock
WaveFileModel(FileSource source, int targetRate=0)
const ZoomConstraint * getZoomConstraint() const
If this model imposes a zoom constraint, i.e.
Definition: WaveFileModel.h:44
RangeCacheFillThread * m_fillThread
QString getTypeName() const
Return the type of the model.
Definition: WaveFileModel.h:83
int m_lastDirectReadCount
int getFrameCount() const
RangeBlock m_cache[2]
SampleBlock m_directRead
void initialize()
QMutex m_directReadMutex
virtual Model * clone() const
Return a copy of this model.
bool isReady(int *) const
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
RangeCacheFillThread(WaveFileModel &model)
Definition: WaveFileModel.h:99
virtual int getData(int channel, int start, int count, float *buffer) const
Get the specified set of samples from the given channel of the model in single-precision floating-poi...
static PowerOfSqrtTwoZoomConstraint m_zoomConstraint
virtual int getStartFrame() const
Return the first audio frame spanned by the model.
Definition: WaveFileModel.h:60
virtual void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
QString getMaker() const
Return the "artist" or "maker" of the model, if known.
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:35
virtual void getSummaries(int channel, int start, int count, RangeBlock &ranges, int &blockSize) const
Return ranges from the given start frame, corresponding to the given number of underlying sample fram...
FileSource is a class used to refer to the contents of a file that may be either local or at a remote...
Definition: FileSource.h:59
int getChannelCount() const
Return the number of distinct channels for this model.
Base class for models containing dense two-dimensional data (value against time) that may be meaningf...
QString getTitle() const
Return the "work title" of the model, if known.
float getValueMaximum() const
Return the minimum possible value found in this model type.
Definition: WaveFileModel.h:58
Definition: Thread.h:24
QTimer * m_updateTimer
virtual Range getSummary(int channel, int start, int count) const
Return the range from the given start frame, corresponding to the given number of underlying sample f...
ZoomConstraint is a simple interface that describes a limitation on the available zoom sizes for a vi...
void fillTimerTimedOut()
void setStartFrame(int startFrame)
Definition: WaveFileModel.h:63
int m_lastDirectReadStart
float getValueMinimum() const
Return the minimum possible value found in this model type.
Definition: WaveFileModel.h:57
bool isOK() const
Return true if the model was constructed successfully.
QString getLocation() const
Return the location of the data in this model (e.g.
virtual int getSummaryBlockSize(int desired) const