void WavFileReader::getInterleavedFrames(size_t start, size_t count, SampleBlock &results) const { if (count == 0) return; results.clear(); results.reserve(count * m_fileInfo.channels); QMutexLocker locker(&m_mutex); if (!m_file || !m_channelCount) { return; } if ((long)start >= m_fileInfo.frames) { // SVDEBUG << "WavFileReader::getInterleavedFrames: " << start // << " > " << m_fileInfo.frames << endl; return; } if (long(start + count) > m_fileInfo.frames) { count = m_fileInfo.frames - start; } sf_count_t readCount = 0; if (start != m_lastStart || count != m_lastCount) { if (sf_seek(m_file, start, SEEK_SET) < 0) { // std::cerr << "sf_seek failed" << std::endl; return; } if (count * m_fileInfo.channels > m_bufsiz) { // std::cerr << "WavFileReader: Reallocating buffer for " << count // << " frames, " << m_fileInfo.channels << " channels: " // << m_bufsiz << " floats" << std::endl; m_bufsiz = count * m_fileInfo.channels; delete[] m_buffer; m_buffer = new float[m_bufsiz]; } if ((readCount = sf_readf_float(m_file, m_buffer, count)) < 0) { // std::cerr << "sf_readf_float failed" << std::endl; return; } m_lastStart = start; m_lastCount = readCount; } for (size_t i = 0; i < count * m_fileInfo.channels; ++i) { if (i >= m_bufsiz) { std::cerr << "INTERNAL ERROR: WavFileReader::getInterleavedFrames: " << i << " >= " << m_bufsiz << std::endl; } results.push_back(m_buffer[i]); } return; }