diff 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
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Thu May 10 12:48:26 2007 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Thu May 24 16:20:22 2007 +0000
@@ -22,6 +22,7 @@
 
 #include <iostream>
 #include <QDir>
+#include <QMutexLocker>
 
 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode) :
     m_cacheMode(cacheMode),
@@ -36,6 +37,8 @@
 
 CodedAudioFileReader::~CodedAudioFileReader()
 {
+    QMutexLocker locker(&m_cacheMutex);
+
     if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr);
     if (m_cacheFileReader) delete m_cacheFileReader;
     if (m_cacheWriteBuffer) delete[] m_cacheWriteBuffer;
@@ -50,6 +53,8 @@
 void
 CodedAudioFileReader::initialiseDecodeCache()
 {
+    QMutexLocker locker(&m_cacheMutex);
+
     if (m_cacheMode == CacheInTemporaryFile) {
 
         m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount];
@@ -88,6 +93,8 @@
 void
 CodedAudioFileReader::addSampleToDecodeCache(float sample)
 {
+    QMutexLocker locker(&m_cacheMutex);
+
     if (!m_initialised) return;
 
     switch (m_cacheMode) {
@@ -117,6 +124,8 @@
 void
 CodedAudioFileReader::finishDecodeCache()
 {
+    QMutexLocker locker(&m_cacheMutex);
+
     Profiler profiler("CodedAudioFileReader::finishDecodeCache", true);
 
     if (!m_initialised) {
@@ -164,6 +173,9 @@
 CodedAudioFileReader::getInterleavedFrames(size_t start, size_t count,
                                            SampleBlock &frames) const
 {
+    //!!! we want to ensure this doesn't require a lock -- at the
+    // moment it does need one, but it doesn't have one...
+
     if (!m_initialised) return;
 
     switch (m_cacheMode) {