Mercurial > hg > svcore
changeset 1326:54af1e21705c 3.0-integration
Update to use bqvec allocator for float vectors
line wrap: on
line diff
--- a/base/BaseTypes.h Tue Dec 13 12:03:48 2016 +0000 +++ b/base/BaseTypes.h Tue Dec 13 15:23:21 2016 +0000 @@ -16,6 +16,10 @@ #define BASE_TYPES_H #include <cstdint> +#include <complex> +#include <vector> + +#include <bqvec/Allocators.h> /** Frame index, the unit of our time axis. This is signed because the axis conceptually extends below zero: zero represents the start of @@ -46,5 +50,10 @@ */ typedef double sv_samplerate_t; +typedef std::vector<float, breakfastquay::StlAllocator<float>> floatvec_t; + +typedef std::vector<std::complex<float>, + breakfastquay::StlAllocator<std::complex<float>>> complexvec_t; + #endif
--- a/data/fileio/AudioFileReader.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/AudioFileReader.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -17,17 +17,17 @@ using std::vector; -vector<vector<float>> +vector<floatvec_t> AudioFileReader::getDeInterleavedFrames(sv_frame_t start, sv_frame_t count) const { - vector<float> interleaved = getInterleavedFrames(start, count); + floatvec_t interleaved = getInterleavedFrames(start, count); int channels = getChannelCount(); if (channels == 1) return { interleaved }; sv_frame_t rc = interleaved.size() / channels; - vector<vector<float>> frames(channels, vector<float>(rc, 0.f)); + vector<floatvec_t> frames(channels, floatvec_t(rc, 0.f)); for (int c = 0; c < channels; ++c) { for (sv_frame_t i = 0; i < rc; ++i) {
--- a/data/fileio/AudioFileReader.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/AudioFileReader.h Tue Dec 13 15:23:21 2016 +0000 @@ -117,8 +117,8 @@ * thread-safe -- that is, safe to call from multiple threads with * different arguments on the same object at the same time. */ - virtual std::vector<float> getInterleavedFrames(sv_frame_t start, - sv_frame_t count) const = 0; + virtual floatvec_t getInterleavedFrames(sv_frame_t start, + sv_frame_t count) const = 0; /** * Return de-interleaved samples for count frames from index @@ -127,8 +127,8 @@ * will contain getChannelCount() sample blocks of count samples * each (or fewer if end of file is reached). */ - virtual std::vector<std::vector<float> > getDeInterleavedFrames(sv_frame_t start, - sv_frame_t count) const; + virtual std::vector<floatvec_t> getDeInterleavedFrames(sv_frame_t start, + sv_frame_t count) const; // only subclasses that do not know exactly how long the audio // file is until it's been completely decoded should implement this
--- a/data/fileio/CodedAudioFileReader.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/CodedAudioFileReader.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -289,7 +289,7 @@ } void -CodedAudioFileReader::addSamplesToDecodeCache(const vector<float> &samples) +CodedAudioFileReader::addSamplesToDecodeCache(const floatvec_t &samples) { QMutexLocker locker(&m_cacheMutex); @@ -526,7 +526,7 @@ } } -vector<float> +floatvec_t CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const { // Lock is only required in CacheInMemory mode (the cache file @@ -538,7 +538,7 @@ return {}; } - vector<float> frames; + floatvec_t frames; switch (m_cacheMode) { @@ -564,7 +564,7 @@ sv_frame_t n = sv_frame_t(m_data.size()); if (ix0 > n) ix0 = n; if (ix1 > n) ix1 = n; - frames = vector<float>(m_data.begin() + ix0, m_data.begin() + ix1); + frames = floatvec_t(m_data.begin() + ix0, m_data.begin() + ix1); m_dataLock.unlock(); break; }
--- a/data/fileio/CodedAudioFileReader.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/CodedAudioFileReader.h Tue Dec 13 15:23:21 2016 +0000 @@ -46,7 +46,7 @@ DecodeThreaded // decode in a background thread after construction }; - virtual std::vector<float> getInterleavedFrames(sv_frame_t start, sv_frame_t count) const; + virtual floatvec_t getInterleavedFrames(sv_frame_t start, sv_frame_t count) const; virtual sv_samplerate_t getNativeRate() const { return m_fileRate; } @@ -71,7 +71,7 @@ // may throw InsufficientDiscSpace: void addSamplesToDecodeCache(float **samples, sv_frame_t nframes); void addSamplesToDecodeCache(float *samplesInterleaved, sv_frame_t nframes); - void addSamplesToDecodeCache(const std::vector<float> &interleaved); + void addSamplesToDecodeCache(const floatvec_t &interleaved); // may throw InsufficientDiscSpace: void finishDecodeCache(); @@ -95,7 +95,7 @@ protected: QMutex m_cacheMutex; CacheMode m_cacheMode; - std::vector<float> m_data; + floatvec_t m_data; mutable QMutex m_dataLock; bool m_initialised; Serialiser *m_serialiser;
--- a/data/fileio/DecodingWavFileReader.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/DecodingWavFileReader.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -71,7 +71,7 @@ sv_frame_t blockSize = 16384; sv_frame_t total = m_original->getFrameCount(); - vector<float> block; + floatvec_t block; for (sv_frame_t i = 0; i < total; i += blockSize) { @@ -128,7 +128,7 @@ sv_frame_t blockSize = 16384; sv_frame_t total = m_reader->m_original->getFrameCount(); - vector<float> block; + floatvec_t block; for (sv_frame_t i = 0; i < total; i += blockSize) { @@ -151,7 +151,7 @@ } void -DecodingWavFileReader::addBlock(const vector<float> &frames) +DecodingWavFileReader::addBlock(const floatvec_t &frames) { addSamplesToDecodeCache(frames);
--- a/data/fileio/DecodingWavFileReader.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/DecodingWavFileReader.h Tue Dec 13 15:23:21 2016 +0000 @@ -64,7 +64,7 @@ WavFileReader *m_original; ProgressReporter *m_reporter; - void addBlock(const std::vector<float> &frames); + void addBlock(const floatvec_t &frames); class DecodeThread : public Thread {
--- a/data/fileio/WavFileReader.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/WavFileReader.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -129,7 +129,7 @@ m_updating = false; } -vector<float> +floatvec_t WavFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const { static HitCount lastRead("WavFileReader: last read"); @@ -175,7 +175,7 @@ return {}; } - vector<float> data; + floatvec_t data; sv_frame_t n = count * m_fileInfo.channels; data.resize(n);
--- a/data/fileio/WavFileReader.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/WavFileReader.h Tue Dec 13 15:23:21 2016 +0000 @@ -50,7 +50,7 @@ * Must be safe to call from multiple threads with different * arguments on the same object at the same time. */ - virtual std::vector<float> getInterleavedFrames(sv_frame_t start, sv_frame_t count) const; + virtual floatvec_t getInterleavedFrames(sv_frame_t start, sv_frame_t count) const; static void getSupportedExtensions(std::set<QString> &extensions); static bool supportsExtension(QString ext); @@ -75,7 +75,7 @@ bool m_seekable; mutable QMutex m_mutex; - mutable std::vector<float> m_buffer; + mutable floatvec_t m_buffer; mutable sv_frame_t m_lastStart; mutable sv_frame_t m_lastCount;
--- a/data/fileio/WavFileWriter.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/WavFileWriter.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -141,10 +141,10 @@ for (sv_frame_t f = f0; f < f1; f += bs) { sv_frame_t n = min(bs, f1 - f); - vector<float> interleaved(n * m_channels, 0.f); + floatvec_t interleaved(n * m_channels, 0.f); for (int c = 0; c < int(m_channels); ++c) { - vector<float> chanbuf = source->getData(c, f, n); + auto chanbuf = source->getData(c, f, n); for (int i = 0; in_range_for(chanbuf, i); ++i) { interleaved[i * m_channels + c] = chanbuf[i]; }
--- a/data/fileio/test/AudioFileReaderTest.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/fileio/test/AudioFileReaderTest.h Tue Dec 13 15:23:21 2016 +0000 @@ -272,7 +272,7 @@ // more, though, so we can (a) check that we only get the // expected number back (if this is not mp3/aac) or (b) take // into account silence at beginning and end (if it is). - vector<float> test = reader->getInterleavedFrames(0, refFrames + 5000); + floatvec_t test = reader->getInterleavedFrames(0, refFrames + 5000); sv_frame_t read = test.size() / channels; bool perceptual = (extension == "mp3" ||
--- a/data/model/AggregateWaveModel.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/AggregateWaveModel.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -94,7 +94,7 @@ return m_components.begin()->model->getSampleRate(); } -vector<float> +floatvec_t AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const { int ch0 = channel, ch1 = channel; @@ -103,8 +103,7 @@ ch1 = getChannelCount()-1; } - vector<float> result(count, 0.f); - + floatvec_t result(count, 0.f); sv_frame_t longest = 0; for (int c = ch0; c <= ch1; ++c) { @@ -123,13 +122,13 @@ return result; } -vector<vector<float>> +vector<floatvec_t> AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const { sv_frame_t min = count; - vector<vector<float>> result; + vector<floatvec_t> result; for (int c = fromchannel; c <= tochannel; ++c) { auto here = getData(c, start, count);
--- a/data/model/AggregateWaveModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/AggregateWaveModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -59,9 +59,9 @@ virtual sv_frame_t getStartFrame() const { return 0; } virtual sv_frame_t getEndFrame() const { return getFrameCount(); } - virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const; + virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const; - virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; + virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; virtual int getSummaryBlockSize(int desired) const;
--- a/data/model/DenseTimeValueModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/DenseTimeValueModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _DENSE_TIME_VALUE_MODEL_H_ -#define _DENSE_TIME_VALUE_MODEL_H_ +#ifndef SV_DENSE_TIME_VALUE_MODEL_H +#define SV_DENSE_TIME_VALUE_MODEL_H #include <QObject> @@ -64,7 +64,8 @@ * If the channel is given as -1, mix all available channels and * return the result. */ - virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const = 0; + virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) + const = 0; /** * Get the specified set of samples from given contiguous range of @@ -72,12 +73,18 @@ * format. Returned vector may have fewer samples than requested, * if the end of file was reached. */ - virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const = 0; + virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, + int tochannel, + sv_frame_t start, + sv_frame_t count) + const = 0; virtual bool canPlay() const { return true; } virtual QString getDefaultPlayClipId() const { return ""; } - virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const; + virtual QString toDelimitedDataStringSubset(QString delimiter, + sv_frame_t f0, sv_frame_t f1) + const; QString getTypeName() const { return tr("Dense Time-Value"); } };
--- a/data/model/FFTModel.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/FFTModel.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -188,7 +188,7 @@ return true; } -vector<float> +FFTModel::fvec FFTModel::getSourceSamples(int column) const { // m_fftSize may be greater than m_windowSize, but not the reverse @@ -204,7 +204,7 @@ return data; } else { vector<float> pad(off, 0.f); - vector<float> padded; + fvec padded; padded.reserve(m_fftSize); padded.insert(padded.end(), pad.begin(), pad.end()); padded.insert(padded.end(), data.begin(), data.end()); @@ -213,7 +213,7 @@ } } -vector<float> +FFTModel::fvec FFTModel::getSourceData(pair<sv_frame_t, sv_frame_t> range) const { // cerr << "getSourceData(" << range.first << "," << range.second @@ -235,11 +235,9 @@ sv_frame_t discard = range.first - m_savedData.range.first; - vector<float> acc(m_savedData.data.begin() + discard, - m_savedData.data.end()); + fvec acc(m_savedData.data.begin() + discard, m_savedData.data.end()); - vector<float> rest = - getSourceDataUncached({ m_savedData.range.second, range.second }); + fvec rest = getSourceDataUncached({ m_savedData.range.second, range.second }); acc.insert(acc.end(), rest.begin(), rest.end()); @@ -256,7 +254,7 @@ } } -vector<float> +FFTModel::fvec FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const { decltype(range.first) pfx = 0; @@ -298,7 +296,7 @@ return data; } -vector<complex<float>> +FFTModel::cvec FFTModel::getFFTColumn(int n) const { // The small cache (i.e. the m_cached deque) is for cases where @@ -321,7 +319,7 @@ m_windower.cut(samples.data()); breakfastquay::v_fftshift(samples.data(), m_fftSize); - vector<complex<float>> col(m_fftSize/2 + 1); + cvec col(m_fftSize/2 + 1); m_fft.forwardInterleaved(samples.data(), reinterpret_cast<float *>(col.data()));
--- a/data/model/FFTModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/FFTModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -22,6 +22,7 @@ #include "base/Window.h" #include <bqfft/FFT.h> +#include <bqvec/Allocators.h> #include <set> #include <vector> @@ -167,20 +168,24 @@ return { startFrame, endFrame }; } - std::vector<std::complex<float> > getFFTColumn(int column) const; - std::vector<float> getSourceSamples(int column) const; - std::vector<float> getSourceData(std::pair<sv_frame_t, sv_frame_t>) const; - std::vector<float> getSourceDataUncached(std::pair<sv_frame_t, sv_frame_t>) const; + typedef std::vector<float, breakfastquay::StlAllocator<float>> fvec; + typedef std::vector<std::complex<float>, + breakfastquay::StlAllocator<std::complex<float>>> cvec; + + cvec getFFTColumn(int column) const; + fvec getSourceSamples(int column) const; + fvec getSourceData(std::pair<sv_frame_t, sv_frame_t>) const; + fvec getSourceDataUncached(std::pair<sv_frame_t, sv_frame_t>) const; struct SavedSourceData { std::pair<sv_frame_t, sv_frame_t> range; - std::vector<float> data; + fvec data; }; mutable SavedSourceData m_savedData; struct SavedColumn { int n; - std::vector<std::complex<float> > col; + cvec col; }; mutable std::deque<SavedColumn> m_cached; size_t m_cacheSize;
--- a/data/model/RangeSummarisableTimeValueModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/RangeSummarisableTimeValueModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H_ -#define _RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H_ +#ifndef SV_RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H +#define SV_RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H #include <QObject>
--- a/data/model/ReadOnlyWaveFileModel.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/ReadOnlyWaveFileModel.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -202,7 +202,7 @@ return ""; } -vector<float> +floatvec_t ReadOnlyWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count) const { // Read directly from the file. This is used for e.g. audio @@ -236,12 +236,12 @@ } } - vector<float> interleaved = m_reader->getInterleavedFrames(start, count); + floatvec_t interleaved = m_reader->getInterleavedFrames(start, count); if (channels == 1) return interleaved; sv_frame_t obtained = interleaved.size() / channels; - vector<float> result(obtained, 0.f); + floatvec_t result(obtained, 0.f); if (channel != -1) { // get a single channel @@ -260,7 +260,7 @@ return result; } -vector<vector<float>> +vector<floatvec_t> ReadOnlyWaveFileModel::getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const { @@ -304,11 +304,11 @@ } } - vector<float> interleaved = m_reader->getInterleavedFrames(start, count); + floatvec_t interleaved = m_reader->getInterleavedFrames(start, count); if (channels == 1) return { interleaved }; sv_frame_t obtained = interleaved.size() / channels; - vector<vector<float>> result(reqchannels, vector<float>(obtained, 0.f)); + vector<floatvec_t> result(reqchannels, floatvec_t(obtained, 0.f)); for (int c = fromchannel; c <= tochannel; ++c) { int destc = c - fromchannel; @@ -588,7 +588,7 @@ sv_frame_t frame = 0; const sv_frame_t readBlockSize = 32768; - vector<float> block; + floatvec_t block; if (!m_model.isOK()) return;
--- a/data/model/ReadOnlyWaveFileModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/ReadOnlyWaveFileModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -64,9 +64,9 @@ void setStartFrame(sv_frame_t startFrame) { m_startFrame = startFrame; } - virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const; + virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const; - virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; + virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; virtual int getSummaryBlockSize(int desired) const; @@ -122,7 +122,7 @@ bool m_exiting; static PowerOfSqrtTwoZoomConstraint m_zoomConstraint; - mutable std::vector<float> m_directRead; + mutable floatvec_t m_directRead; mutable sv_frame_t m_lastDirectReadStart; mutable sv_frame_t m_lastDirectReadCount; mutable QMutex m_directReadMutex;
--- a/data/model/WritableWaveFileModel.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/WritableWaveFileModel.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -188,14 +188,14 @@ return m_frameCount; } -vector<float> +floatvec_t WritableWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count) const { if (!m_model || m_model->getChannelCount() == 0) return {}; return m_model->getData(channel, start, count); } -vector<vector<float>> +vector<floatvec_t> WritableWaveFileModel::getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const {
--- a/data/model/WritableWaveFileModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/WritableWaveFileModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -110,9 +110,9 @@ void setStartFrame(sv_frame_t startFrame); - virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const; + virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const; - virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; + virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; virtual int getSummaryBlockSize(int desired) const;
--- a/data/model/test/MockWaveModel.cpp Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/test/MockWaveModel.cpp Tue Dec 13 15:23:21 2016 +0000 @@ -26,14 +26,14 @@ } } -vector<float> +floatvec_t MockWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const { sv_frame_t i = 0; // cerr << "MockWaveModel::getData(" << channel << "," << start << "," << count << "): "; - vector<float> data; + floatvec_t data; while (i < count) { sv_frame_t idx = start + i; @@ -48,11 +48,11 @@ return data; } -vector<vector<float>> +vector<floatvec_t> MockWaveModel::getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const { - vector<vector<float>> data(tochannel - fromchannel + 1); + vector<floatvec_t> data(tochannel - fromchannel + 1); for (int c = fromchannel; c <= tochannel; ++c) { data.push_back(getData(c, start, count));
--- a/data/model/test/MockWaveModel.h Tue Dec 13 12:03:48 2016 +0000 +++ b/data/model/test/MockWaveModel.h Tue Dec 13 15:23:21 2016 +0000 @@ -41,8 +41,8 @@ virtual float getValueMaximum() const { return 1.f; } virtual int getChannelCount() const { return int(m_data.size()); } - virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const; - virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; + virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const; + virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; virtual bool canPlay() const { return true; } virtual QString getDefaultPlayClipId() const { return ""; }