annotate data/model/WaveFileModel.h @ 1025:88b54a185a0a

Use double instead of float for frequencies in Pitch, just for confidence
author Chris Cannam
date Mon, 08 Dec 2014 15:37:12 +0000
parents 36f79bc5c3d7
children cc27f35aa75c
rev   line source
Chris@147 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@147 2
Chris@147 3 /*
Chris@147 4 Sonic Visualiser
Chris@147 5 An audio file viewer and annotation editor.
Chris@147 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@147 8
Chris@147 9 This program is free software; you can redistribute it and/or
Chris@147 10 modify it under the terms of the GNU General Public License as
Chris@147 11 published by the Free Software Foundation; either version 2 of the
Chris@147 12 License, or (at your option) any later version. See the file
Chris@147 13 COPYING included with this distribution for more information.
Chris@147 14 */
Chris@147 15
Chris@147 16 #ifndef _WAVE_FILE_MODEL_H_
Chris@147 17 #define _WAVE_FILE_MODEL_H_
Chris@147 18
Chris@150 19 #include "base/Thread.h"
Chris@147 20 #include <QMutex>
Chris@147 21 #include <QTimer>
Chris@147 22
Chris@317 23 #include "data/fileio/FileSource.h"
Chris@316 24
Chris@147 25 #include "RangeSummarisableTimeValueModel.h"
Chris@147 26 #include "PowerOfSqrtTwoZoomConstraint.h"
Chris@147 27
Chris@147 28 #include <stdlib.h>
Chris@147 29
Chris@147 30 class AudioFileReader;
Chris@147 31
Chris@179 32 class WaveFileModel : public RangeSummarisableTimeValueModel
Chris@147 33 {
Chris@147 34 Q_OBJECT
Chris@147 35
Chris@147 36 public:
Chris@929 37 WaveFileModel(FileSource source, int targetRate = 0);
Chris@317 38 WaveFileModel(FileSource source, AudioFileReader *reader);
Chris@147 39 ~WaveFileModel();
Chris@147 40
Chris@147 41 bool isOK() const;
Chris@147 42 bool isReady(int *) const;
Chris@147 43
Chris@179 44 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
Chris@179 45
Chris@929 46 int getFrameCount() const;
Chris@929 47 int getChannelCount() const;
Chris@929 48 int getSampleRate() const;
Chris@929 49 int getNativeRate() const;
Chris@147 50
Chris@333 51 QString getTitle() const;
Chris@333 52 QString getMaker() const;
Chris@345 53 QString getLocation() const;
Chris@333 54
Chris@1010 55 QString getLocalFilename() const;
Chris@1010 56
Chris@147 57 virtual Model *clone() const;
Chris@147 58
Chris@147 59 float getValueMinimum() const { return -1.0f; }
Chris@147 60 float getValueMaximum() const { return 1.0f; }
Chris@147 61
Chris@929 62 virtual int getStartFrame() const { return m_startFrame; }
Chris@929 63 virtual int getEndFrame() const { return m_startFrame + getFrameCount(); }
Chris@147 64
Chris@929 65 void setStartFrame(int startFrame) { m_startFrame = startFrame; }
Chris@147 66
Chris@929 67 virtual int getData(int channel, int start, int count,
Chris@948 68 float *buffer) const;
Chris@147 69
Chris@929 70 virtual int getData(int channel, int start, int count,
Chris@948 71 double *buffer) const;
Chris@147 72
Chris@929 73 virtual int getData(int fromchannel, int tochannel,
Chris@948 74 int start, int count,
Chris@948 75 float **buffers) const;
Chris@363 76
Chris@929 77 virtual int getSummaryBlockSize(int desired) const;
Chris@377 78
Chris@929 79 virtual void getSummaries(int channel, int start, int count,
Chris@300 80 RangeBlock &ranges,
Chris@929 81 int &blockSize) const;
Chris@300 82
Chris@929 83 virtual Range getSummary(int channel, int start, int count) const;
Chris@147 84
Chris@345 85 QString getTypeName() const { return tr("Wave File"); }
Chris@345 86
Chris@163 87 virtual void toXml(QTextStream &out,
Chris@163 88 QString indent = "",
Chris@163 89 QString extraAttributes = "") const;
Chris@163 90
Chris@147 91 protected slots:
Chris@147 92 void fillTimerTimedOut();
Chris@147 93 void cacheFilled();
Chris@147 94
Chris@147 95 protected:
Chris@147 96 void initialize();
Chris@147 97
Chris@147 98 class RangeCacheFillThread : public Thread
Chris@147 99 {
Chris@147 100 public:
Chris@147 101 RangeCacheFillThread(WaveFileModel &model) :
Chris@175 102 m_model(model), m_fillExtent(0),
Chris@175 103 m_frameCount(model.getFrameCount()) { }
Chris@147 104
Chris@929 105 int getFillExtent() const { return m_fillExtent; }
Chris@147 106 virtual void run();
Chris@147 107
Chris@147 108 protected:
Chris@147 109 WaveFileModel &m_model;
Chris@929 110 int m_fillExtent;
Chris@929 111 int m_frameCount;
Chris@147 112 };
Chris@147 113
Chris@147 114 void fillCache();
Chris@316 115
Chris@317 116 FileSource m_source;
Chris@147 117 QString m_path;
Chris@147 118 AudioFileReader *m_reader;
Chris@175 119 bool m_myReader;
Chris@147 120
Chris@929 121 int m_startFrame;
Chris@300 122
Chris@147 123 RangeBlock m_cache[2]; // interleaved at two base resolutions
Chris@147 124 mutable QMutex m_mutex;
Chris@147 125 RangeCacheFillThread *m_fillThread;
Chris@147 126 QTimer *m_updateTimer;
Chris@929 127 int m_lastFillExtent;
Chris@147 128 bool m_exiting;
Chris@179 129 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
Chris@377 130
Chris@377 131 mutable SampleBlock m_directRead;
Chris@929 132 mutable int m_lastDirectReadStart;
Chris@929 133 mutable int m_lastDirectReadCount;
Chris@377 134 mutable QMutex m_directReadMutex;
Chris@147 135 };
Chris@147 136
Chris@147 137 #endif