diff data/fileio/CoreAudioFileReader.cpp @ 822:54829c1e155e tonioni

Merge from the default branch
author Chris Cannam
date Fri, 12 Jul 2013 13:10:28 +0100
parents 2079abf4f0c1 51cf0c35e9b0
children 2d53205f70cd
line wrap: on
line diff
--- a/data/fileio/CoreAudioFileReader.cpp	Thu Jun 20 13:47:35 2013 +0100
+++ b/data/fileio/CoreAudioFileReader.cpp	Fri Jul 12 13:10:28 2013 +0100
@@ -33,13 +33,14 @@
 class CoreAudioFileReader::D
 {
 public:
-    D() : blockSize(1024) { }
+    D() : blockSize(1024), valid(false) { }
 
     ExtAudioFileRef file;
     AudioBufferList buffer;
     OSStatus err;
     AudioStreamBasicDescription asbd;
     int blockSize;
+    bool valid;
 };
 
 static QString
@@ -52,7 +53,7 @@
     text[2] = (uerr >> 8) & 0xff;
     text[3] = (uerr) & 0xff;
     text[4] = '\0';
-    return QString("%1 (%2)").arg(err).arg(QString::fromAscii(text));
+    return QString("%1 (%2)").arg(err).arg(QString::fromLocal8Bit(text));
 }
 
 CoreAudioFileReader::CoreAudioFileReader(FileSource source,
@@ -116,6 +117,7 @@
     
     if (m_d->err) {
         m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err);
+        ExtAudioFileDispose(m_d->file);
         return;
     }
 	
@@ -140,6 +142,7 @@
     
     if (m_d->err) {
         m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err);
+        ExtAudioFileDispose(m_d->file);
         return;
     }
 
@@ -148,6 +151,8 @@
     m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize;
     m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize];
 
+    m_d->valid = true;
+
     initialiseDecodeCache();
 
     if (m_reporter) {
@@ -181,15 +186,18 @@
     endSerialised();
 
     m_completion = 100;
-
-    ExtAudioFileDispose(m_d->file);
 }
 
 
 CoreAudioFileReader::~CoreAudioFileReader()
 {
     std::cerr << "CoreAudioFileReader::~CoreAudioFileReader" << std::endl;
-    delete[] m_d->buffer.mBuffers[0].mData;
+
+    if (m_d->valid) {
+        ExtAudioFileDispose(m_d->file);
+        delete[] m_d->buffer.mBuffers[0].mData;
+    }
+
     delete m_d;
 }