Mercurial > hg > svcore
comparison data/fileio/CodedAudioFileReader.cpp @ 263:71dfc6ab3b54
* Threaded mp3/ogg file reading. Not activated yet, as it doesn't work
in context (SV needs to know the duration of its main model at the outset)
author | Chris Cannam |
---|---|
date | Thu, 24 May 2007 16:20:22 +0000 |
parents | 900ac6667eab |
children | e08f486e8d8c |
comparison
equal
deleted
inserted
replaced
262:524bcd89743b | 263:71dfc6ab3b54 |
---|---|
20 #include "base/Exceptions.h" | 20 #include "base/Exceptions.h" |
21 #include "base/Profiler.h" | 21 #include "base/Profiler.h" |
22 | 22 |
23 #include <iostream> | 23 #include <iostream> |
24 #include <QDir> | 24 #include <QDir> |
25 #include <QMutexLocker> | |
25 | 26 |
26 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode) : | 27 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode) : |
27 m_cacheMode(cacheMode), | 28 m_cacheMode(cacheMode), |
28 m_initialised(false), | 29 m_initialised(false), |
29 m_cacheFileWritePtr(0), | 30 m_cacheFileWritePtr(0), |
34 { | 35 { |
35 } | 36 } |
36 | 37 |
37 CodedAudioFileReader::~CodedAudioFileReader() | 38 CodedAudioFileReader::~CodedAudioFileReader() |
38 { | 39 { |
40 QMutexLocker locker(&m_cacheMutex); | |
41 | |
39 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr); | 42 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr); |
40 if (m_cacheFileReader) delete m_cacheFileReader; | 43 if (m_cacheFileReader) delete m_cacheFileReader; |
41 if (m_cacheWriteBuffer) delete[] m_cacheWriteBuffer; | 44 if (m_cacheWriteBuffer) delete[] m_cacheWriteBuffer; |
42 | 45 |
43 if (m_cacheFileName != "") { | 46 if (m_cacheFileName != "") { |
48 } | 51 } |
49 | 52 |
50 void | 53 void |
51 CodedAudioFileReader::initialiseDecodeCache() | 54 CodedAudioFileReader::initialiseDecodeCache() |
52 { | 55 { |
56 QMutexLocker locker(&m_cacheMutex); | |
57 | |
53 if (m_cacheMode == CacheInTemporaryFile) { | 58 if (m_cacheMode == CacheInTemporaryFile) { |
54 | 59 |
55 m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount]; | 60 m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount]; |
56 m_cacheWriteBufferIndex = 0; | 61 m_cacheWriteBufferIndex = 0; |
57 | 62 |
86 } | 91 } |
87 | 92 |
88 void | 93 void |
89 CodedAudioFileReader::addSampleToDecodeCache(float sample) | 94 CodedAudioFileReader::addSampleToDecodeCache(float sample) |
90 { | 95 { |
96 QMutexLocker locker(&m_cacheMutex); | |
97 | |
91 if (!m_initialised) return; | 98 if (!m_initialised) return; |
92 | 99 |
93 switch (m_cacheMode) { | 100 switch (m_cacheMode) { |
94 | 101 |
95 case CacheInTemporaryFile: | 102 case CacheInTemporaryFile: |
115 } | 122 } |
116 | 123 |
117 void | 124 void |
118 CodedAudioFileReader::finishDecodeCache() | 125 CodedAudioFileReader::finishDecodeCache() |
119 { | 126 { |
127 QMutexLocker locker(&m_cacheMutex); | |
128 | |
120 Profiler profiler("CodedAudioFileReader::finishDecodeCache", true); | 129 Profiler profiler("CodedAudioFileReader::finishDecodeCache", true); |
121 | 130 |
122 if (!m_initialised) { | 131 if (!m_initialised) { |
123 std::cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << std::endl; | 132 std::cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << std::endl; |
124 return; | 133 return; |
162 | 171 |
163 void | 172 void |
164 CodedAudioFileReader::getInterleavedFrames(size_t start, size_t count, | 173 CodedAudioFileReader::getInterleavedFrames(size_t start, size_t count, |
165 SampleBlock &frames) const | 174 SampleBlock &frames) const |
166 { | 175 { |
176 //!!! we want to ensure this doesn't require a lock -- at the | |
177 // moment it does need one, but it doesn't have one... | |
178 | |
167 if (!m_initialised) return; | 179 if (!m_initialised) return; |
168 | 180 |
169 switch (m_cacheMode) { | 181 switch (m_cacheMode) { |
170 | 182 |
171 case CacheInTemporaryFile: | 183 case CacheInTemporaryFile: |