annotate data/model/ReadOnlyWaveFileModel.h @ 1520:954d0cf29ca7 import-audio-data

Switch the normalisation option in WritableWaveFileModel from normalising on read to normalising on write, so that the saved file is already normalised and therefore can be read again without having to remember to normalise it
author Chris Cannam
date Wed, 12 Sep 2018 13:56:56 +0100
parents b7042aaecebe
children d93e34684da7
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@1122 16 #ifndef READ_ONLY_WAVE_FILE_MODEL_H
Chris@1122 17 #define READ_ONLY_WAVE_FILE_MODEL_H
Chris@1122 18
Chris@1122 19 #include "WaveFileModel.h"
Chris@147 20
Chris@150 21 #include "base/Thread.h"
Chris@147 22 #include <QMutex>
Chris@147 23 #include <QTimer>
Chris@147 24
Chris@317 25 #include "data/fileio/FileSource.h"
Chris@316 26
Chris@147 27 #include "RangeSummarisableTimeValueModel.h"
Chris@147 28 #include "PowerOfSqrtTwoZoomConstraint.h"
Chris@147 29
Chris@147 30 #include <stdlib.h>
Chris@147 31
Chris@147 32 class AudioFileReader;
Chris@147 33
Chris@1122 34 class ReadOnlyWaveFileModel : public WaveFileModel
Chris@147 35 {
Chris@147 36 Q_OBJECT
Chris@147 37
Chris@147 38 public:
Chris@1514 39 /**
Chris@1514 40 * Construct a WaveFileModel from a source path and optional
Chris@1514 41 * resampling target rate
Chris@1514 42 */
Chris@1122 43 ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate = 0);
Chris@1514 44
Chris@1514 45 /**
Chris@1514 46 * Construct a WaveFileModel from a source path using an existing
Chris@1514 47 * AudioFileReader. The model does not take ownership of the
Chris@1514 48 * AudioFileReader, which remains managed by the caller and must
Chris@1514 49 * outlive the model.
Chris@1514 50 */
Chris@1122 51 ReadOnlyWaveFileModel(FileSource source, AudioFileReader *reader);
Chris@1514 52
Chris@1122 53 ~ReadOnlyWaveFileModel();
Chris@147 54
Chris@147 55 bool isOK() const;
Chris@147 56 bool isReady(int *) const;
Chris@147 57
Chris@179 58 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
Chris@179 59
Chris@1038 60 sv_frame_t getFrameCount() const;
Chris@929 61 int getChannelCount() const;
Chris@1040 62 sv_samplerate_t getSampleRate() const;
Chris@1040 63 sv_samplerate_t getNativeRate() const;
Chris@147 64
Chris@333 65 QString getTitle() const;
Chris@333 66 QString getMaker() const;
Chris@345 67 QString getLocation() const;
Chris@333 68
Chris@1010 69 QString getLocalFilename() const;
Chris@1010 70
Chris@147 71 float getValueMinimum() const { return -1.0f; }
Chris@147 72 float getValueMaximum() const { return 1.0f; }
Chris@147 73
Chris@1038 74 virtual sv_frame_t getStartFrame() const { return m_startFrame; }
Chris@1038 75 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
Chris@147 76
Chris@1038 77 void setStartFrame(sv_frame_t startFrame) { m_startFrame = startFrame; }
Chris@147 78
Chris@1326 79 virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const;
Chris@147 80
Chris@1326 81 virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const;
Chris@363 82
Chris@929 83 virtual int getSummaryBlockSize(int desired) const;
Chris@377 84
Chris@1038 85 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
Chris@300 86 RangeBlock &ranges,
Chris@929 87 int &blockSize) const;
Chris@300 88
Chris@1038 89 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
Chris@147 90
Chris@345 91 QString getTypeName() const { return tr("Wave File"); }
Chris@345 92
Chris@163 93 virtual void toXml(QTextStream &out,
Chris@163 94 QString indent = "",
Chris@163 95 QString extraAttributes = "") const;
Chris@163 96
Chris@147 97 protected slots:
Chris@147 98 void fillTimerTimedOut();
Chris@147 99 void cacheFilled();
Chris@147 100
Chris@147 101 protected:
Chris@147 102 void initialize();
Chris@147 103
Chris@147 104 class RangeCacheFillThread : public Thread
Chris@147 105 {
Chris@147 106 public:
Chris@1122 107 RangeCacheFillThread(ReadOnlyWaveFileModel &model) :
Chris@1406 108 m_model(model), m_fillExtent(0),
Chris@175 109 m_frameCount(model.getFrameCount()) { }
Chris@147 110
Chris@1406 111 sv_frame_t getFillExtent() const { return m_fillExtent; }
Chris@147 112 virtual void run();
Chris@147 113
Chris@147 114 protected:
Chris@1122 115 ReadOnlyWaveFileModel &m_model;
Chris@1406 116 sv_frame_t m_fillExtent;
Chris@1038 117 sv_frame_t m_frameCount;
Chris@147 118 };
Chris@147 119
Chris@147 120 void fillCache();
Chris@316 121
Chris@317 122 FileSource m_source;
Chris@147 123 QString m_path;
Chris@147 124 AudioFileReader *m_reader;
Chris@175 125 bool m_myReader;
Chris@147 126
Chris@1038 127 sv_frame_t m_startFrame;
Chris@300 128
Chris@147 129 RangeBlock m_cache[2]; // interleaved at two base resolutions
Chris@147 130 mutable QMutex m_mutex;
Chris@147 131 RangeCacheFillThread *m_fillThread;
Chris@147 132 QTimer *m_updateTimer;
Chris@1038 133 sv_frame_t m_lastFillExtent;
Chris@147 134 bool m_exiting;
Chris@179 135 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
Chris@377 136
Chris@1326 137 mutable floatvec_t m_directRead;
Chris@1038 138 mutable sv_frame_t m_lastDirectReadStart;
Chris@1038 139 mutable sv_frame_t m_lastDirectReadCount;
Chris@377 140 mutable QMutex m_directReadMutex;
Chris@147 141 };
Chris@147 142
Chris@147 143 #endif