Mercurial > hg > svcore
changeset 1349:330bcc92507d 3.0-integration
Take a different approach to using libsndfile -- the _fd function doesn't work for me in this build, so use the wchar api
author | Chris Cannam |
---|---|
date | Fri, 06 Jan 2017 20:51:47 +0000 |
parents | b3cb0edc25cd |
children | 1bc6f70cb4c7 |
files | data/fileio/MP3FileReader.cpp data/fileio/WavFileReader.cpp data/fileio/WavFileReader.h |
diffstat | 3 files changed, 31 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp Fri Jan 06 16:40:11 2017 +0000 +++ b/data/fileio/MP3FileReader.cpp Fri Jan 06 20:51:47 2017 +0000 @@ -36,11 +36,6 @@ #include <QTextCodec> -#ifdef _MSC_VER -#include <io.h> -#define open _open -#endif - using std::string; static sv_frame_t DEFAULT_DECODER_DELAY = 529;
--- a/data/fileio/WavFileReader.cpp Fri Jan 06 16:40:11 2017 +0000 +++ b/data/fileio/WavFileReader.cpp Fri Jan 06 20:51:47 2017 +0000 @@ -26,10 +26,9 @@ using namespace std; WavFileReader::WavFileReader(FileSource source, bool fileUpdating) : - m_sndfile(0), + m_file(0), m_source(source), m_path(source.getLocalFilename()), - m_qfile(m_path), m_seekable(false), m_lastStart(0), m_lastCount(0), @@ -42,23 +41,23 @@ m_fileInfo.format = 0; m_fileInfo.frames = 0; - if (!m_qfile.open(QIODevice::ReadOnly)) { +#ifdef Q_OS_WIN + m_file = sf_wchar_open((LPCWSTR)m_path.utf16(), SFM_READ, &m_fileInfo); +#else + m_file = sf_open(m_path.toLocal8Bit(), SFM_READ, &m_fileInfo); +#endif + + if (!m_file || (!fileUpdating && m_fileInfo.channels <= 0)) { SVDEBUG << "WavFileReader::initialize: Failed to open file at \"" - << m_path << "\"" << endl; - m_error = QString("Failed to open audio file '%1'").arg(m_path); - return; - } - - m_sndfile = sf_open_fd(m_qfile.handle(), SFM_READ, &m_fileInfo, false); + << m_path << "\" (" + << sf_strerror(m_file) << ")" << endl; - if (!m_sndfile || (!fileUpdating && m_fileInfo.channels <= 0)) { - SVDEBUG << "WavFileReader::initialize: Failed to open file at \"" - << m_path << "\" (" << sf_strerror(m_sndfile) << ")" << endl; - if (m_sndfile) { + if (m_file) { m_error = QString("Couldn't load audio file '%1':\n%2") - .arg(m_path).arg(sf_strerror(m_sndfile)); + .arg(m_path).arg(sf_strerror(m_file)); } else { - m_error = QString("Failed to open audio file '%1'").arg(m_path); + m_error = QString("Failed to open audio file '%1'") + .arg(m_path); } return; } @@ -95,7 +94,7 @@ WavFileReader::~WavFileReader() { - if (m_sndfile) sf_close(m_sndfile); + if (m_file) sf_close(m_file); } void @@ -105,12 +104,16 @@ sv_frame_t prevCount = m_fileInfo.frames; - if (m_sndfile) { - sf_close(m_sndfile); - m_sndfile = sf_open_fd(m_qfile.handle(), SFM_READ, &m_fileInfo, false); - if (!m_sndfile || m_fileInfo.channels <= 0) { - SVCERR << "WavFileReader::updateFrameCount: Failed to reopen file at \"" << m_path << "\" (" - << sf_strerror(m_sndfile) << ")" << endl; + if (m_file) { + sf_close(m_file); +#ifdef Q_OS_WIN + m_file = sf_wchar_open((LPCWSTR)m_path.utf16(), SFM_READ, &m_fileInfo); +#else + m_file = sf_open(m_path.toLocal8Bit(), SFM_READ, &m_fileInfo); +#endif + if (!m_file || m_fileInfo.channels <= 0) { + SVDEBUG << "WavFileReader::updateFrameCount: Failed to open file at \"" << m_path << "\" (" + << sf_strerror(m_file) << ")" << endl; } } @@ -146,7 +149,7 @@ Profiler profiler("WavFileReader::getInterleavedFrames"); - if (!m_sndfile || !m_channelCount) { + if (!m_file || !m_channelCount) { return {}; } @@ -177,7 +180,7 @@ lastRead.miss(); } - if (sf_seek(m_sndfile, start, SEEK_SET) < 0) { + if (sf_seek(m_file, start, SEEK_SET) < 0) { return {}; } @@ -189,7 +192,7 @@ m_lastCount = count; sf_count_t readCount = 0; - if ((readCount = sf_readf_float(m_sndfile, data.data(), count)) < 0) { + if ((readCount = sf_readf_float(m_file, data.data(), count)) < 0) { return {}; }
--- a/data/fileio/WavFileReader.h Fri Jan 06 16:40:11 2017 +0000 +++ b/data/fileio/WavFileReader.h Fri Jan 06 20:51:47 2017 +0000 @@ -18,9 +18,10 @@ #include "AudioFileReader.h" +#define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 + #include <sndfile.h> #include <QMutex> -#include <QFile> #include <set> @@ -67,12 +68,11 @@ protected: SF_INFO m_fileInfo; - SNDFILE *m_sndfile; + SNDFILE *m_file; FileSource m_source; QString m_path; QString m_error; - QFile m_qfile; bool m_seekable;