comparison data/model/WaveFileModel.cpp @ 297:c022976d18e8

* Merge from sv-match-alignment branch (excluding alignment-specific document). - add aggregate wave model (not yet complete enough to be added as a true model in a layer, but there's potential) - add play solo mode - add alignment model -- unused in plain SV - fix two plugin leaks - add m3u playlist support (opens all files at once, potentially hazardous) - fix retrieval of pre-encoded URLs - add ability to resample audio files on import, so as to match rates with other files previously loaded; add preference for same - add preliminary support in transform code for range and rate of transform input - reorganise preferences dialog, move dark-background option to preferences, add option for temporary directory location
author Chris Cannam
date Fri, 28 Sep 2007 13:56:38 +0000
parents 8c5762634f42
children 5877d68815c7
comparison
equal deleted inserted replaced
296:2b6c99b607f1 297:c022976d18e8
36 using std::endl; 36 using std::endl;
37 37
38 PowerOfSqrtTwoZoomConstraint 38 PowerOfSqrtTwoZoomConstraint
39 WaveFileModel::m_zoomConstraint; 39 WaveFileModel::m_zoomConstraint;
40 40
41 WaveFileModel::WaveFileModel(QString path) : 41 WaveFileModel::WaveFileModel(QString path, size_t targetRate) :
42 m_path(path), 42 m_path(path),
43 m_myReader(true), 43 m_myReader(true),
44 m_fillThread(0), 44 m_fillThread(0),
45 m_updateTimer(0), 45 m_updateTimer(0),
46 m_lastFillExtent(0), 46 m_lastFillExtent(0),
47 m_exiting(false) 47 m_exiting(false)
48 { 48 {
49 m_reader = AudioFileReaderFactory::createReader(path); 49 m_reader = AudioFileReaderFactory::createReader(path, targetRate);
50 if (m_reader) std::cerr << "WaveFileModel::WaveFileModel: reader rate: " << m_reader->getSampleRate() << std::endl;
50 if (m_reader) setObjectName(m_reader->getTitle()); 51 if (m_reader) setObjectName(m_reader->getTitle());
51 if (objectName() == "") setObjectName(QFileInfo(path).fileName()); 52 if (objectName() == "") setObjectName(QFileInfo(path).fileName());
52 if (isOK()) fillCache(); 53 if (isOK()) fillCache();
53 } 54 }
54 55
55 WaveFileModel::WaveFileModel(QString path, QString originalLocation) : 56 WaveFileModel::WaveFileModel(QString path, QString originalLocation, size_t targetRate) :
56 m_path(originalLocation), 57 m_path(originalLocation),
57 m_myReader(true), 58 m_myReader(true),
58 m_fillThread(0), 59 m_fillThread(0),
59 m_updateTimer(0), 60 m_updateTimer(0),
60 m_lastFillExtent(0), 61 m_lastFillExtent(0),
61 m_exiting(false) 62 m_exiting(false)
62 { 63 {
63 m_reader = AudioFileReaderFactory::createReader(path); 64 m_reader = AudioFileReaderFactory::createReader(path, targetRate);
65 if (m_reader) std::cerr << "WaveFileModel::WaveFileModel: reader rate: " << m_reader->getSampleRate() << std::endl;
64 if (m_reader) setObjectName(m_reader->getTitle()); 66 if (m_reader) setObjectName(m_reader->getTitle());
65 if (objectName() == "") setObjectName(QFileInfo(originalLocation).fileName()); 67 if (objectName() == "") setObjectName(QFileInfo(originalLocation).fileName());
66 if (isOK()) fillCache(); 68 if (isOK()) fillCache();
67 } 69 }
68 70
149 if (!m_reader) return 0; 151 if (!m_reader) return 0;
150 return m_reader->getSampleRate(); 152 return m_reader->getSampleRate();
151 } 153 }
152 154
153 size_t 155 size_t
156 WaveFileModel::getNativeRate() const
157 {
158 if (!m_reader) return 0;
159 size_t rate = m_reader->getNativeRate();
160 if (rate == 0) rate = getSampleRate();
161 return rate;
162 }
163
164 size_t
154 WaveFileModel::getValues(int channel, size_t start, size_t end, 165 WaveFileModel::getValues(int channel, size_t start, size_t end,
155 float *buffer) const 166 float *buffer) const
156 { 167 {
157 // Always read these directly from the file. 168 // Always read these directly from the file.
158 // This is used for e.g. audio playback. 169 // This is used for e.g. audio playback.