comparison data/fileio/MP3FileReader.cpp @ 265:e08f486e8d8c

* Enable threaded decoding for Ogg and MP3 files. Needs some work on reducing updates to the overview widget
author Chris Cannam
date Wed, 06 Jun 2007 16:24:55 +0000
parents 260032c26c4f
children 822bd7fd526c
comparison
equal deleted inserted replaced
264:260032c26c4f 265:e08f486e8d8c
40 m_fileSize = 0; 40 m_fileSize = 0;
41 m_bitrateNum = 0; 41 m_bitrateNum = 0;
42 m_bitrateDenom = 0; 42 m_bitrateDenom = 0;
43 m_frameCount = 0; 43 m_frameCount = 0;
44 m_cancelled = false; 44 m_cancelled = false;
45 m_completion = 0;
45 m_done = false; 46 m_done = false;
46 m_progress = 0; 47 m_progress = 0;
47 48
48 struct stat stat; 49 struct stat stat;
49 if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { 50 if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) {
125 } 126 }
126 127
127 MP3FileReader::~MP3FileReader() 128 MP3FileReader::~MP3FileReader()
128 { 129 {
129 if (m_decodeThread) { 130 if (m_decodeThread) {
131 m_cancelled = true;
130 m_decodeThread->wait(); 132 m_decodeThread->wait();
131 delete m_decodeThread; 133 delete m_decodeThread;
132 } 134 }
133 } 135 }
134 136
143 m_reader->m_filebuffer = 0; 145 m_reader->m_filebuffer = 0;
144 146
145 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); 147 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache();
146 148
147 m_reader->m_done = true; 149 m_reader->m_done = true;
150 m_reader->m_completion = 100;
148 } 151 }
149 152
150 bool 153 bool
151 MP3FileReader::decode(void *mm, size_t sz) 154 MP3FileReader::decode(void *mm, size_t sz)
152 { 155 {
208 if (m_bitrateDenom > 0) { 211 if (m_bitrateDenom > 0) {
209 double bitrate = m_bitrateNum / m_bitrateDenom; 212 double bitrate = m_bitrateNum / m_bitrateDenom;
210 double duration = double(m_fileSize * 8) / bitrate; 213 double duration = double(m_fileSize * 8) / bitrate;
211 double elapsed = double(m_frameCount) / m_sampleRate; 214 double elapsed = double(m_frameCount) / m_sampleRate;
212 double percent = ((elapsed * 100.0) / duration); 215 double percent = ((elapsed * 100.0) / duration);
216 int progress = int(percent);
217 if (progress < 1) progress = 1;
218 if (progress > 99) progress = 99;
219 m_completion = progress;
213 if (m_progress) { 220 if (m_progress) {
214 int progress = int(percent);
215 if (progress < 1) progress = 1;
216 if (progress > 99) progress = 99;
217 if (progress > m_progress->value()) { 221 if (progress > m_progress->value()) {
218 m_progress->setValue(progress); 222 m_progress->setValue(progress);
219 m_progress->show(); 223 m_progress->show();
220 m_progress->raise(); 224 m_progress->raise();
221 qApp->processEvents(); 225 qApp->processEvents();