Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
818:5e9ff92ca05e | 822:54829c1e155e |
---|---|
31 #endif | 31 #endif |
32 | 32 |
33 class CoreAudioFileReader::D | 33 class CoreAudioFileReader::D |
34 { | 34 { |
35 public: | 35 public: |
36 D() : blockSize(1024) { } | 36 D() : blockSize(1024), valid(false) { } |
37 | 37 |
38 ExtAudioFileRef file; | 38 ExtAudioFileRef file; |
39 AudioBufferList buffer; | 39 AudioBufferList buffer; |
40 OSStatus err; | 40 OSStatus err; |
41 AudioStreamBasicDescription asbd; | 41 AudioStreamBasicDescription asbd; |
42 int blockSize; | 42 int blockSize; |
43 bool valid; | |
43 }; | 44 }; |
44 | 45 |
45 static QString | 46 static QString |
46 codestr(OSStatus err) | 47 codestr(OSStatus err) |
47 { | 48 { |
50 text[0] = (uerr >> 24) & 0xff; | 51 text[0] = (uerr >> 24) & 0xff; |
51 text[1] = (uerr >> 16) & 0xff; | 52 text[1] = (uerr >> 16) & 0xff; |
52 text[2] = (uerr >> 8) & 0xff; | 53 text[2] = (uerr >> 8) & 0xff; |
53 text[3] = (uerr) & 0xff; | 54 text[3] = (uerr) & 0xff; |
54 text[4] = '\0'; | 55 text[4] = '\0'; |
55 return QString("%1 (%2)").arg(err).arg(QString::fromAscii(text)); | 56 return QString("%1 (%2)").arg(err).arg(QString::fromLocal8Bit(text)); |
56 } | 57 } |
57 | 58 |
58 CoreAudioFileReader::CoreAudioFileReader(FileSource source, | 59 CoreAudioFileReader::CoreAudioFileReader(FileSource source, |
59 DecodeMode decodeMode, | 60 DecodeMode decodeMode, |
60 CacheMode mode, | 61 CacheMode mode, |
114 m_d->err = ExtAudioFileGetProperty | 115 m_d->err = ExtAudioFileGetProperty |
115 (m_d->file, kExtAudioFileProperty_FileDataFormat, &propsize, &m_d->asbd); | 116 (m_d->file, kExtAudioFileProperty_FileDataFormat, &propsize, &m_d->asbd); |
116 | 117 |
117 if (m_d->err) { | 118 if (m_d->err) { |
118 m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err); | 119 m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err); |
120 ExtAudioFileDispose(m_d->file); | |
119 return; | 121 return; |
120 } | 122 } |
121 | 123 |
122 m_channelCount = m_d->asbd.mChannelsPerFrame; | 124 m_channelCount = m_d->asbd.mChannelsPerFrame; |
123 m_fileRate = m_d->asbd.mSampleRate; | 125 m_fileRate = m_d->asbd.mSampleRate; |
138 m_d->err = ExtAudioFileSetProperty | 140 m_d->err = ExtAudioFileSetProperty |
139 (m_d->file, kExtAudioFileProperty_ClientDataFormat, propsize, &m_d->asbd); | 141 (m_d->file, kExtAudioFileProperty_ClientDataFormat, propsize, &m_d->asbd); |
140 | 142 |
141 if (m_d->err) { | 143 if (m_d->err) { |
142 m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err); | 144 m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err); |
145 ExtAudioFileDispose(m_d->file); | |
143 return; | 146 return; |
144 } | 147 } |
145 | 148 |
146 m_d->buffer.mNumberBuffers = 1; | 149 m_d->buffer.mNumberBuffers = 1; |
147 m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount; | 150 m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount; |
148 m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize; | 151 m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize; |
149 m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize]; | 152 m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize]; |
153 | |
154 m_d->valid = true; | |
150 | 155 |
151 initialiseDecodeCache(); | 156 initialiseDecodeCache(); |
152 | 157 |
153 if (m_reporter) { | 158 if (m_reporter) { |
154 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled())); | 159 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled())); |
179 | 184 |
180 finishDecodeCache(); | 185 finishDecodeCache(); |
181 endSerialised(); | 186 endSerialised(); |
182 | 187 |
183 m_completion = 100; | 188 m_completion = 100; |
184 | |
185 ExtAudioFileDispose(m_d->file); | |
186 } | 189 } |
187 | 190 |
188 | 191 |
189 CoreAudioFileReader::~CoreAudioFileReader() | 192 CoreAudioFileReader::~CoreAudioFileReader() |
190 { | 193 { |
191 std::cerr << "CoreAudioFileReader::~CoreAudioFileReader" << std::endl; | 194 std::cerr << "CoreAudioFileReader::~CoreAudioFileReader" << std::endl; |
192 delete[] m_d->buffer.mBuffers[0].mData; | 195 |
196 if (m_d->valid) { | |
197 ExtAudioFileDispose(m_d->file); | |
198 delete[] m_d->buffer.mBuffers[0].mData; | |
199 } | |
200 | |
193 delete m_d; | 201 delete m_d; |
194 } | 202 } |
195 | 203 |
196 void | 204 void |
197 CoreAudioFileReader::cancelled() | 205 CoreAudioFileReader::cancelled() |