本文整理汇总了C++中AudioBuffer::reallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioBuffer::reallocate方法的具体用法?C++ AudioBuffer::reallocate怎么用?C++ AudioBuffer::reallocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioBuffer
的用法示例。
在下文中一共展示了AudioBuffer::reallocate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
/*!
Protected method, called from AudioBuffer::loadWav(QString, QObject*).
Loads a .wav file from a preopened \a wavFile. If \a parent is given, it is
set as the parent of the constructed buffer.
Returns a new buffer if successful, NULL otherwise.
*/
AudioBuffer *AudioBuffer::loadWav(QFile &wavFile, QObject *parent)
{
if (!wavFile.isOpen()) {
// The file is not open!
DEBUG_INFO("The given file must be opened before calling this method!");
return NULL;
}
SWavHeader header;
wavFile.read(header.chunkID, 4);
if (header.chunkID[0] != 'R' || header.chunkID[1] != 'I' ||
header.chunkID[2] != 'F' || header.chunkID[3] != 'F') {
// Incorrect header
return NULL;
}
wavFile.read((char*)&header.chunkSize, 4);
wavFile.read((char*)&header.format, 4);
if (header.format[0] != 'W' || header.format[1] != 'A' ||
header.format[2] != 'V' || header.format[3] != 'E') {
// Incorrect header
return NULL;
}
wavFile.read((char*)&header.subchunk1id, 4);
if (header.subchunk1id[0] != 'f' || header.subchunk1id[1] != 'm' ||
header.subchunk1id[2] != 't' || header.subchunk1id[3] != ' ') {
// Incorrect header
return NULL;
}
wavFile.read((char*)&header.subchunk1size, 4);
wavFile.read((char*)&header.audioFormat, 2);
wavFile.read((char*)&header.nofChannels, 2);
wavFile.read((char*)&header.sampleRate, 4);
wavFile.read((char*)&header.byteRate, 4);
wavFile.read((char*)&header.blockAlign, 2);
wavFile.read((char*)&header.bitsPerSample, 2);
while (1) {
if (wavFile.read((char*)&header.subchunk2id, 4) != 4)
return NULL;
if (wavFile.read((char*)&header.subchunk2size, 4) != 4)
return NULL;
if (header.subchunk2id[0] == 'd' && header.subchunk2id[1] == 'a' &&
header.subchunk2id[2] == 't' && header.subchunk2id[3] == 'a') {
// Found the data chunk.
break;
}
// This was not the data-chunk. Skip it.
if (header.subchunk2size < 1) {
// Error in file!
return NULL;
}
char *unused = new char[header.subchunk2size];
wavFile.read(unused, header.subchunk2size);
delete [] unused;
}
// The data follows.
if (header.subchunk2size < 1)
return NULL;
// Construct the buffer.
AudioBuffer *buffer = new AudioBuffer(parent);
buffer->m_nofChannels = header.nofChannels;
buffer->m_bitsPerSample = header.bitsPerSample;
buffer->m_samplesPerSec = header.sampleRate;
buffer->m_signedData = 0; // Where to look for this?
buffer->reallocate(header.subchunk2size);
wavFile.read((char*)buffer->m_data, header.subchunk2size);
// Select a good sampling function.
if (!setSampleFunction(*buffer)) {
// Failed to resolve the sample function!
delete buffer;
return NULL;
}
return buffer;
}