Remove old SampleBuffer
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
namespace lmms
|
||||
{
|
||||
|
||||
class SampleBuffer2;
|
||||
class SampleBuffer;
|
||||
|
||||
|
||||
class AudioSampleRecorder : public AudioDevice
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
~AudioSampleRecorder() override;
|
||||
|
||||
f_cnt_t framesRecorded() const;
|
||||
void createSampleBuffer(SampleBuffer2** sampleBuffer);
|
||||
void createSampleBuffer(SampleBuffer** sampleBuffer);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -167,7 +167,7 @@ private:
|
||||
sample_t * m_lfoShapeData;
|
||||
sample_t m_random;
|
||||
bool m_bad_lfoShapeData;
|
||||
SampleBuffer m_userWave;
|
||||
std::shared_ptr<const SampleBuffer> m_userWave;
|
||||
|
||||
enum class LfoShape
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ protected:
|
||||
sample_t (*m_sampleFunction)( const float );
|
||||
|
||||
private:
|
||||
std::shared_ptr<const SampleBuffer2> m_userDefSampleBuffer;
|
||||
std::shared_ptr<const SampleBuffer> m_userDefSampleBuffer;
|
||||
|
||||
protected slots:
|
||||
void updatePhase();
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "lmmsconfig.h"
|
||||
#include "AudioEngine.h"
|
||||
#include "OscillatorConstants.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
@@ -91,14 +91,14 @@ public:
|
||||
|
||||
static void waveTableInit();
|
||||
static void destroyFFTPlans();
|
||||
static std::unique_ptr<OscillatorConstants::waveform_t> generateAntiAliasUserWaveTable(const SampleBuffer2 *sampleBuffer);
|
||||
static std::unique_ptr<OscillatorConstants::waveform_t> generateAntiAliasUserWaveTable(const SampleBuffer *sampleBuffer);
|
||||
|
||||
inline void setUseWaveTable(bool n)
|
||||
{
|
||||
m_useWaveTable = n;
|
||||
}
|
||||
|
||||
inline void setUserWave(std::shared_ptr<const SampleBuffer2> _wave)
|
||||
inline void setUserWave(std::shared_ptr<const SampleBuffer> _wave)
|
||||
{
|
||||
m_userWave = _wave;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
return 1.0f - fast_rand() * 2.0f / FAST_RAND_MAX;
|
||||
}
|
||||
|
||||
static inline sample_t userWaveSample(const SampleBuffer2* buffer, const float sample)
|
||||
static inline sample_t userWaveSample(const SampleBuffer* buffer, const float sample)
|
||||
{
|
||||
if (buffer == nullptr || buffer->size() == 0) { return 0; }
|
||||
const auto frames = buffer->size();
|
||||
@@ -256,7 +256,7 @@ private:
|
||||
Oscillator * m_subOsc;
|
||||
float m_phaseOffset;
|
||||
float m_phase;
|
||||
std::shared_ptr<const SampleBuffer2> m_userWave;
|
||||
std::shared_ptr<const SampleBuffer> m_userWave;
|
||||
std::shared_ptr<const OscillatorConstants::waveform_t> m_userAntiAliasWaveTable;
|
||||
bool m_useWaveTable;
|
||||
// There are many update*() variants; the modulator flag is stored as a member variable to avoid
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Sample.h - State for container-class SampleBuffer2
|
||||
* Sample.h - State for container-class SampleBuffer
|
||||
*
|
||||
* Copyright (c) 2023 saker <sakertooth@gmail.com>
|
||||
*
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Note.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "lmms_export.h"
|
||||
|
||||
#ifdef __MINGW32__
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
Sample(const QString& audioFile);
|
||||
Sample(const QByteArray& base64, int sampleRate = Engine::audioEngine()->processingSampleRate());
|
||||
Sample(const sampleFrame* data, int numFrames, int sampleRate = Engine::audioEngine()->processingSampleRate());
|
||||
Sample(std::shared_ptr<const SampleBuffer2> buffer);
|
||||
Sample(std::shared_ptr<const SampleBuffer> buffer);
|
||||
Sample(const Sample& other);
|
||||
Sample(Sample&& other) noexcept;
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
|
||||
auto toBase64() const -> QString;
|
||||
|
||||
auto buffer() const -> std::shared_ptr<const SampleBuffer2>;
|
||||
auto buffer() const -> std::shared_ptr<const SampleBuffer>;
|
||||
auto startFrame() const -> int;
|
||||
auto endFrame() const -> int;
|
||||
auto loopStartFrame() const -> int;
|
||||
@@ -144,7 +144,7 @@ private:
|
||||
auto amplifySampleRange(sampleFrame* src, int numFrames) const -> void;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const SampleBuffer2> m_buffer = std::make_shared<SampleBuffer2>();
|
||||
std::shared_ptr<const SampleBuffer> m_buffer = std::make_shared<SampleBuffer>();
|
||||
int m_startFrame = 0;
|
||||
int m_endFrame = 0;
|
||||
int m_loopStartFrame = 0;
|
||||
|
||||
@@ -25,333 +25,58 @@
|
||||
#ifndef LMMS_SAMPLE_BUFFER_H
|
||||
#define LMMS_SAMPLE_BUFFER_H
|
||||
|
||||
#include <memory>
|
||||
#include <QReadWriteLock>
|
||||
#include <QObject>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <optional>
|
||||
#include <samplerate.h>
|
||||
#include <vector>
|
||||
|
||||
#include "lmms_export.h"
|
||||
#include "interpolation.h"
|
||||
#include "AudioEngine.h"
|
||||
#include "Engine.h"
|
||||
#include "lmms_basics.h"
|
||||
#include "lmms_math.h"
|
||||
#include "shared_object.h"
|
||||
#include "OscillatorConstants.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "lmms_export.h"
|
||||
|
||||
|
||||
class QPainter;
|
||||
class QRect;
|
||||
|
||||
namespace lmms
|
||||
namespace lmms {
|
||||
class LMMS_EXPORT SampleBuffer
|
||||
{
|
||||
|
||||
// values for buffer margins, used for various libsamplerate interpolation modes
|
||||
// the array positions correspond to the converter_type parameter values in libsamplerate
|
||||
// if there appears problems with playback on some interpolation mode, then the value for that mode
|
||||
// may need to be higher - conversely, to optimize, some may work with lower values
|
||||
const f_cnt_t MARGIN[] = { 64, 64, 64, 4, 4 };
|
||||
|
||||
class LMMS_EXPORT SampleBuffer : public QObject, public sharedObject
|
||||
{
|
||||
Q_OBJECT
|
||||
MM_OPERATORS
|
||||
public:
|
||||
enum class LoopMode {
|
||||
Off = 0,
|
||||
On,
|
||||
PingPong
|
||||
};
|
||||
class LMMS_EXPORT handleState
|
||||
{
|
||||
MM_OPERATORS
|
||||
public:
|
||||
handleState(bool varyingPitch = false, int interpolationMode = SRC_LINEAR);
|
||||
virtual ~handleState();
|
||||
using value_type = sampleFrame;
|
||||
using reference = sampleFrame&;
|
||||
using const_iterator = std::vector<sampleFrame>::const_iterator;
|
||||
using const_reverse_iterator = std::vector<sampleFrame>::const_reverse_iterator;
|
||||
using difference_type = std::vector<sampleFrame>::difference_type;
|
||||
using size_type = std::vector<sampleFrame>::size_type;
|
||||
|
||||
const f_cnt_t frameIndex() const
|
||||
{
|
||||
return m_frameIndex;
|
||||
}
|
||||
SampleBuffer() = default;
|
||||
SampleBuffer(const QString& audioFile);
|
||||
SampleBuffer(const QByteArray& base64Data, int sampleRate);
|
||||
SampleBuffer(
|
||||
const sampleFrame* data, int numFrames, int sampleRate = Engine::audioEngine()->processingSampleRate());
|
||||
|
||||
void setFrameIndex(f_cnt_t index)
|
||||
{
|
||||
m_frameIndex = index;
|
||||
}
|
||||
friend void swap(SampleBuffer& first, SampleBuffer& second) noexcept;
|
||||
auto toBase64() const -> QString;
|
||||
|
||||
bool isBackwards() const
|
||||
{
|
||||
return m_isBackwards;
|
||||
}
|
||||
auto audioFile() const -> QString;
|
||||
auto sampleRate() const -> sample_rate_t;
|
||||
|
||||
void setBackwards(bool backwards)
|
||||
{
|
||||
m_isBackwards = backwards;
|
||||
}
|
||||
auto begin() const -> const_iterator;
|
||||
auto end() const -> const_iterator;
|
||||
auto rbegin() const -> const_reverse_iterator;
|
||||
auto rend() const -> const_reverse_iterator;
|
||||
|
||||
int interpolationMode() const
|
||||
{
|
||||
return m_interpolationMode;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
f_cnt_t m_frameIndex;
|
||||
const bool m_varyingPitch;
|
||||
bool m_isBackwards;
|
||||
SRC_STATE * m_resamplingData;
|
||||
int m_interpolationMode;
|
||||
|
||||
friend class SampleBuffer;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
SampleBuffer();
|
||||
// constructor which either loads sample _audio_file or decodes
|
||||
// base64-data out of string
|
||||
SampleBuffer(const QString & audioFile, bool isBase64Data = false);
|
||||
SampleBuffer(const sampleFrame * data, const f_cnt_t frames);
|
||||
explicit SampleBuffer(const f_cnt_t frames);
|
||||
SampleBuffer(const SampleBuffer & orig);
|
||||
|
||||
friend void swap(SampleBuffer & first, SampleBuffer & second) noexcept;
|
||||
SampleBuffer& operator= (const SampleBuffer that);
|
||||
|
||||
~SampleBuffer() override;
|
||||
|
||||
bool play(
|
||||
sampleFrame * ab,
|
||||
handleState * state,
|
||||
const fpp_t frames,
|
||||
const float freq,
|
||||
const LoopMode loopMode = LoopMode::Off
|
||||
);
|
||||
|
||||
void visualize(
|
||||
QPainter & p,
|
||||
const QRect & dr,
|
||||
const QRect & clip,
|
||||
f_cnt_t fromFrame = 0,
|
||||
f_cnt_t toFrame = 0
|
||||
);
|
||||
inline void visualize(
|
||||
QPainter & p,
|
||||
const QRect & dr,
|
||||
f_cnt_t fromFrame = 0,
|
||||
f_cnt_t toFrame = 0
|
||||
)
|
||||
{
|
||||
visualize(p, dr, dr, fromFrame, toFrame);
|
||||
}
|
||||
|
||||
inline const QString & audioFile() const
|
||||
{
|
||||
return m_audioFile;
|
||||
}
|
||||
|
||||
inline f_cnt_t startFrame() const
|
||||
{
|
||||
return m_startFrame;
|
||||
}
|
||||
|
||||
inline f_cnt_t endFrame() const
|
||||
{
|
||||
return m_endFrame;
|
||||
}
|
||||
|
||||
inline f_cnt_t loopStartFrame() const
|
||||
{
|
||||
return m_loopStartFrame;
|
||||
}
|
||||
|
||||
inline f_cnt_t loopEndFrame() const
|
||||
{
|
||||
return m_loopEndFrame;
|
||||
}
|
||||
|
||||
void setLoopStartFrame(f_cnt_t start)
|
||||
{
|
||||
m_loopStartFrame = start;
|
||||
}
|
||||
|
||||
void setLoopEndFrame(f_cnt_t end)
|
||||
{
|
||||
m_loopEndFrame = end;
|
||||
}
|
||||
|
||||
void setAllPointFrames(
|
||||
f_cnt_t start,
|
||||
f_cnt_t end,
|
||||
f_cnt_t loopStart,
|
||||
f_cnt_t loopEnd
|
||||
)
|
||||
{
|
||||
m_startFrame = start;
|
||||
m_endFrame = end;
|
||||
m_loopStartFrame = loopStart;
|
||||
m_loopEndFrame = loopEnd;
|
||||
}
|
||||
|
||||
inline f_cnt_t frames() const
|
||||
{
|
||||
return m_frames;
|
||||
}
|
||||
|
||||
inline float amplification() const
|
||||
{
|
||||
return m_amplification;
|
||||
}
|
||||
|
||||
inline bool reversed() const
|
||||
{
|
||||
return m_reversed;
|
||||
}
|
||||
|
||||
inline float frequency() const
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
|
||||
sample_rate_t sampleRate() const
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
int sampleLength() const
|
||||
{
|
||||
return double(m_endFrame - m_startFrame) / m_sampleRate * 1000;
|
||||
}
|
||||
|
||||
inline void setFrequency(float freq)
|
||||
{
|
||||
m_frequency = freq;
|
||||
}
|
||||
|
||||
inline void setSampleRate(sample_rate_t rate)
|
||||
{
|
||||
m_sampleRate = rate;
|
||||
}
|
||||
|
||||
inline const sampleFrame * data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
QString openAudioFile() const;
|
||||
QString openAndSetAudioFile();
|
||||
QString openAndSetWaveformFile();
|
||||
|
||||
QString & toBase64(QString & dst) const;
|
||||
|
||||
|
||||
// protect calls from the GUI to this function with dataReadLock() and
|
||||
// dataUnlock()
|
||||
SampleBuffer * resample(const sample_rate_t srcSR, const sample_rate_t dstSR);
|
||||
|
||||
void normalizeSampleRate(const sample_rate_t srcSR, bool keepSettings = false);
|
||||
|
||||
// protect calls from the GUI to this function with dataReadLock() and
|
||||
// dataUnlock(), out of loops for efficiency
|
||||
inline sample_t userWaveSample(const float sample) const
|
||||
{
|
||||
f_cnt_t frames = m_frames;
|
||||
sampleFrame * data = m_data;
|
||||
const float frame = sample * frames;
|
||||
f_cnt_t f1 = static_cast<f_cnt_t>(frame) % frames;
|
||||
if (f1 < 0)
|
||||
{
|
||||
f1 += frames;
|
||||
}
|
||||
return linearInterpolate(data[f1][0], data[(f1 + 1) % frames][0], fraction(frame));
|
||||
}
|
||||
|
||||
void dataReadLock()
|
||||
{
|
||||
m_varLock.lockForRead();
|
||||
}
|
||||
|
||||
void dataUnlock()
|
||||
{
|
||||
m_varLock.unlock();
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<OscillatorConstants::waveform_t> m_userAntiAliasWaveTable;
|
||||
|
||||
|
||||
public slots:
|
||||
void setAudioFile(const QString & audioFile);
|
||||
void loadFromBase64(const QString & data);
|
||||
void setStartFrame(const lmms::f_cnt_t s);
|
||||
void setEndFrame(const lmms::f_cnt_t e);
|
||||
void setAmplification(float a);
|
||||
void setReversed(bool on);
|
||||
void sampleRateChanged();
|
||||
auto data() const -> const sampleFrame*;
|
||||
auto size() const -> size_type;
|
||||
bool empty() const;
|
||||
|
||||
private:
|
||||
static sample_rate_t audioEngineSampleRate();
|
||||
void decodeSampleSF(const QString& fileName);
|
||||
void decodeSampleDS(const QString& fileName);
|
||||
|
||||
void update(bool keepSettings = false);
|
||||
|
||||
void convertIntToFloat(int_sample_t * & ibuf, f_cnt_t frames, int channels);
|
||||
void directFloatWrite(sample_t * & fbuf, f_cnt_t frames, int channels);
|
||||
|
||||
f_cnt_t decodeSampleSF(
|
||||
QString fileName,
|
||||
sample_t * & buf,
|
||||
ch_cnt_t & channels,
|
||||
sample_rate_t & samplerate
|
||||
);
|
||||
#ifdef LMMS_HAVE_OGGVORBIS
|
||||
f_cnt_t decodeSampleOGGVorbis(
|
||||
QString fileName,
|
||||
int_sample_t * & buf,
|
||||
ch_cnt_t & channels,
|
||||
sample_rate_t & samplerate
|
||||
);
|
||||
#endif
|
||||
f_cnt_t decodeSampleDS(
|
||||
QString fileName,
|
||||
int_sample_t * & buf,
|
||||
ch_cnt_t & channels,
|
||||
sample_rate_t & samplerate
|
||||
);
|
||||
|
||||
QString m_audioFile;
|
||||
sampleFrame * m_origData;
|
||||
f_cnt_t m_origFrames;
|
||||
sampleFrame * m_data;
|
||||
mutable QReadWriteLock m_varLock;
|
||||
f_cnt_t m_frames;
|
||||
f_cnt_t m_startFrame;
|
||||
f_cnt_t m_endFrame;
|
||||
f_cnt_t m_loopStartFrame;
|
||||
f_cnt_t m_loopEndFrame;
|
||||
float m_amplification;
|
||||
bool m_reversed;
|
||||
float m_frequency;
|
||||
sample_rate_t m_sampleRate;
|
||||
|
||||
sampleFrame * getSampleFragment(
|
||||
f_cnt_t index,
|
||||
f_cnt_t frames,
|
||||
LoopMode loopMode,
|
||||
sampleFrame * * tmp,
|
||||
bool * backwards,
|
||||
f_cnt_t loopStart,
|
||||
f_cnt_t loopEnd,
|
||||
f_cnt_t end
|
||||
) const;
|
||||
|
||||
f_cnt_t getLoopedIndex(f_cnt_t index, f_cnt_t startf, f_cnt_t endf) const;
|
||||
f_cnt_t getPingPongIndex(f_cnt_t index, f_cnt_t startf, f_cnt_t endf) const;
|
||||
|
||||
|
||||
signals:
|
||||
void sampleUpdated();
|
||||
|
||||
} ;
|
||||
private:
|
||||
std::vector<sampleFrame> m_data;
|
||||
std::optional<QString> m_audioFile;
|
||||
int m_sampleRate = 0;
|
||||
};
|
||||
|
||||
} // namespace lmms
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* SampleBuffer2.h - container-class SampleBuffer2
|
||||
*
|
||||
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of LMMS - https://lmms.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LMMS_SAMPLE_BUFFER2_H
|
||||
#define LMMS_SAMPLE_BUFFER2_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <optional>
|
||||
#include <samplerate.h>
|
||||
#include <vector>
|
||||
|
||||
#include "AudioEngine.h"
|
||||
#include "Engine.h"
|
||||
#include "lmms_basics.h"
|
||||
#include "lmms_export.h"
|
||||
|
||||
namespace lmms {
|
||||
class LMMS_EXPORT SampleBuffer2
|
||||
{
|
||||
public:
|
||||
using value_type = sampleFrame;
|
||||
using reference = sampleFrame&;
|
||||
using const_iterator = std::vector<sampleFrame>::const_iterator;
|
||||
using const_reverse_iterator = std::vector<sampleFrame>::const_reverse_iterator;
|
||||
using difference_type = std::vector<sampleFrame>::difference_type;
|
||||
using size_type = std::vector<sampleFrame>::size_type;
|
||||
|
||||
SampleBuffer2() = default;
|
||||
SampleBuffer2(const QString& audioFile);
|
||||
SampleBuffer2(const QByteArray& base64Data, int sampleRate);
|
||||
SampleBuffer2(
|
||||
const sampleFrame* data, int numFrames, int sampleRate = Engine::audioEngine()->processingSampleRate());
|
||||
|
||||
friend void swap(SampleBuffer2& first, SampleBuffer2& second) noexcept;
|
||||
auto toBase64() const -> QString;
|
||||
|
||||
auto audioFile() const -> QString;
|
||||
auto sampleRate() const -> sample_rate_t;
|
||||
|
||||
auto begin() const -> const_iterator;
|
||||
auto end() const -> const_iterator;
|
||||
auto rbegin() const -> const_reverse_iterator;
|
||||
auto rend() const -> const_reverse_iterator;
|
||||
|
||||
auto data() const -> const sampleFrame*;
|
||||
auto size() const -> size_type;
|
||||
bool empty() const;
|
||||
|
||||
private:
|
||||
void decodeSampleSF(const QString& fileName);
|
||||
void decodeSampleDS(const QString& fileName);
|
||||
|
||||
private:
|
||||
std::vector<sampleFrame> m_data;
|
||||
std::optional<QString> m_audioFile;
|
||||
int m_sampleRate = 0;
|
||||
};
|
||||
|
||||
} // namespace lmms
|
||||
|
||||
#endif // LMMS_SAMPLE_BUFFER2_H
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
void setIsPlaying(bool isPlaying);
|
||||
|
||||
public slots:
|
||||
void setSampleBuffer(SampleBuffer2* sb);
|
||||
void setSampleBuffer(SampleBuffer* sb);
|
||||
void setSampleFile( const QString & _sf );
|
||||
void updateLength();
|
||||
void toggleRecord();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "lmms_export.h"
|
||||
|
||||
namespace lmms::gui {
|
||||
@@ -37,8 +37,8 @@ class LMMS_EXPORT SampleLoader
|
||||
public:
|
||||
static QString openAudioFile(const QString& previousFile = "");
|
||||
static QString openWaveformFile(const QString& previousFile = "");
|
||||
static std::unique_ptr<SampleBuffer2> createBufferFromFile(const QString& filePath);
|
||||
static std::unique_ptr<SampleBuffer2> createBufferFromBase64(const QString& base64, int sampleRate = Engine::audioEngine()->processingSampleRate());
|
||||
static std::unique_ptr<SampleBuffer> createBufferFromFile(const QString& filePath);
|
||||
static std::unique_ptr<SampleBuffer> createBufferFromBase64(const QString& base64, int sampleRate = Engine::audioEngine()->processingSampleRate());
|
||||
private:
|
||||
static void displayError(const QString& message);
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <QPair>
|
||||
|
||||
#include "PlayHandle.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "TimePos.h"
|
||||
|
||||
namespace lmms
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
bool isFromTrack( const Track * _track ) const override;
|
||||
|
||||
f_cnt_t framesRecorded() const;
|
||||
void createSampleBuffer(SampleBuffer2** _sample_buf);
|
||||
void createSampleBuffer(SampleBuffer** _sample_buf);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -97,8 +97,6 @@ signals:
|
||||
void sampleUpdated();
|
||||
|
||||
private:
|
||||
using handleState = SampleBuffer::handleState;
|
||||
|
||||
std::shared_ptr<Sample> m_sample;
|
||||
|
||||
FloatModel m_ampModel;
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "Knob.h"
|
||||
#include "NotePlayHandle.h"
|
||||
#include "PathUtil.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "Sample.h"
|
||||
#include "Song.h"
|
||||
|
||||
#include "PatchesDialog.h"
|
||||
@@ -437,7 +437,7 @@ void GigInstrument::play( sampleFrame * _working_buffer )
|
||||
if (sample.region->PitchTrack == true) { freq_factor *= sample.freqFactor; }
|
||||
|
||||
// We need a bit of margin so we don't get glitching
|
||||
samples = frames / freq_factor + MARGIN[m_interpolation];
|
||||
samples = frames / freq_factor + Sample::s_interpolationMargins[m_interpolation];
|
||||
}
|
||||
|
||||
// Load this note's data
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "Instrument.h"
|
||||
#include "InstrumentView.h"
|
||||
#include "Sample.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "AutomatableModel.h"
|
||||
#include "MemoryManager.h"
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ OscillatorObject::OscillatorObject( Model * _parent, int _idx ) :
|
||||
tr( "Modulation type %1" ).arg( _idx+1 ) ),
|
||||
m_useWaveTableModel(true),
|
||||
|
||||
m_sampleBuffer( new SampleBuffer2 ),
|
||||
m_sampleBuffer( new SampleBuffer ),
|
||||
m_volumeLeft( 0.0f ),
|
||||
m_volumeRight( 0.0f ),
|
||||
m_detuningLeft( 0.0f ),
|
||||
@@ -146,7 +146,7 @@ void OscillatorObject::oscUserDefWaveDblClick()
|
||||
QString af = gui::SampleLoader::openWaveformFile();
|
||||
auto buffer = gui::SampleLoader::createBufferFromFile(af);
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&m_sampleBuffer, std::shared_ptr<const SampleBuffer2>(std::move(buffer)));
|
||||
std::atomic_store(&m_sampleBuffer, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
|
||||
if( af != "" )
|
||||
{
|
||||
@@ -293,7 +293,7 @@ void TripleOscillator::loadSettings( const QDomElement & _this )
|
||||
|
||||
auto buffer = gui::SampleLoader::createBufferFromFile(_this.attribute("userwavefile" + is));
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&m_osc[i]->m_sampleBuffer, std::shared_ptr<const SampleBuffer2>(std::move(buffer)));
|
||||
std::atomic_store(&m_osc[i]->m_sampleBuffer, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "Instrument.h"
|
||||
#include "InstrumentView.h"
|
||||
#include "AutomatableModel.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
@@ -69,7 +69,7 @@ private:
|
||||
IntModel m_waveShapeModel;
|
||||
IntModel m_modulationAlgoModel;
|
||||
BoolModel m_useWaveTableModel;
|
||||
std::shared_ptr<const SampleBuffer2> m_sampleBuffer;
|
||||
std::shared_ptr<const SampleBuffer> m_sampleBuffer;
|
||||
|
||||
float m_volumeLeft;
|
||||
float m_volumeRight;
|
||||
|
||||
@@ -67,7 +67,6 @@ set(LMMS_SRCS
|
||||
core/RingBuffer.cpp
|
||||
core/Sample.cpp
|
||||
core/SampleBuffer.cpp
|
||||
core/SampleBuffer2.cpp
|
||||
core/SampleClip.cpp
|
||||
core/SamplePlayHandle.cpp
|
||||
core/SampleRecordHandle.cpp
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "AudioEngine.h"
|
||||
#include "Engine.h"
|
||||
#include "Oscillator.h"
|
||||
|
||||
#include "SampleLoader.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
@@ -221,7 +221,7 @@ inline sample_t EnvelopeAndLfoParameters::lfoShapeSample( fpp_t _frame_offset )
|
||||
shape_sample = Oscillator::sawSample( phase );
|
||||
break;
|
||||
case LfoShape::UserDefinedWave:
|
||||
shape_sample = m_userWave.userWaveSample( phase );
|
||||
shape_sample = Oscillator::userWaveSample(m_userWave.get(), phase);
|
||||
break;
|
||||
case LfoShape::RandomWave:
|
||||
if( frame == 0 )
|
||||
@@ -354,7 +354,7 @@ void EnvelopeAndLfoParameters::saveSettings( QDomDocument & _doc,
|
||||
m_lfoAmountModel.saveSettings( _doc, _parent, "lamt" );
|
||||
m_x100Model.saveSettings( _doc, _parent, "x100" );
|
||||
m_controlEnvAmountModel.saveSettings( _doc, _parent, "ctlenvamt" );
|
||||
_parent.setAttribute( "userwavefile", m_userWave.audioFile() );
|
||||
_parent.setAttribute("userwavefile", m_userWave->audioFile());
|
||||
}
|
||||
|
||||
|
||||
@@ -386,8 +386,9 @@ void EnvelopeAndLfoParameters::loadSettings( const QDomElement & _this )
|
||||
m_sustainModel.setValue( 1.0 - m_sustainModel.value() );
|
||||
}
|
||||
|
||||
m_userWave.setAudioFile( _this.attribute( "userwavefile" ) );
|
||||
|
||||
auto buffer = gui::SampleLoader::createBufferFromFile(_this.attribute("userwavefile"));
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&m_userWave, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
updateSampleVars();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ LfoController::LfoController( Model * _parent ) :
|
||||
m_phaseOffset( 0 ),
|
||||
m_currentPhase( 0 ),
|
||||
m_sampleFunction( &Oscillator::sinSample ),
|
||||
m_userDefSampleBuffer(std::make_shared<SampleBuffer2>())
|
||||
m_userDefSampleBuffer(std::make_shared<SampleBuffer>())
|
||||
{
|
||||
setSampleExact( true );
|
||||
connect( &m_waveModel, SIGNAL(dataChanged()),
|
||||
@@ -214,7 +214,7 @@ void LfoController::loadSettings( const QDomElement & _this )
|
||||
|
||||
auto buffer = gui::SampleLoader::createBufferFromFile(_this.attribute("userwavefile"));
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&m_userDefSampleBuffer, std::shared_ptr<const SampleBuffer2>(std::move(buffer)));
|
||||
std::atomic_store(&m_userDefSampleBuffer, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
|
||||
updateSampleFunction();
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ void Oscillator::generateFromFFT(int bands, sample_t* table)
|
||||
normalize(s_sampleBuffer.data(), table, OscillatorConstants::WAVETABLE_LENGTH, 2*OscillatorConstants::WAVETABLE_LENGTH + 1);
|
||||
}
|
||||
|
||||
std::unique_ptr<OscillatorConstants::waveform_t> Oscillator::generateAntiAliasUserWaveTable(const SampleBuffer2* sampleBuffer)
|
||||
std::unique_ptr<OscillatorConstants::waveform_t> Oscillator::generateAntiAliasUserWaveTable(const SampleBuffer* sampleBuffer)
|
||||
{
|
||||
auto userAntiAliasWaveTable = std::make_unique<OscillatorConstants::waveform_t>();
|
||||
for (int i = 0; i < OscillatorConstants::WAVE_TABLES_PER_WAVEFORM_COUNT; ++i)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Sample.cpp - State for container-class SampleBuffer2
|
||||
* Sample.cpp - State for container-class SampleBuffer
|
||||
*
|
||||
* Copyright (c) 2023 saker <sakertooth@gmail.com>
|
||||
*
|
||||
@@ -30,7 +30,7 @@
|
||||
namespace lmms {
|
||||
|
||||
Sample::Sample(const QString& audioFile)
|
||||
: m_buffer(std::make_shared<SampleBuffer2>(audioFile))
|
||||
: m_buffer(std::make_shared<SampleBuffer>(audioFile))
|
||||
, m_startFrame(0)
|
||||
, m_endFrame(m_buffer->size())
|
||||
, m_loopStartFrame(0)
|
||||
@@ -39,7 +39,7 @@ Sample::Sample(const QString& audioFile)
|
||||
}
|
||||
|
||||
Sample::Sample(const QByteArray& base64, int sampleRate)
|
||||
: m_buffer(std::make_shared<SampleBuffer2>(base64, sampleRate))
|
||||
: m_buffer(std::make_shared<SampleBuffer>(base64, sampleRate))
|
||||
, m_startFrame(0)
|
||||
, m_endFrame(m_buffer->size())
|
||||
, m_loopStartFrame(0)
|
||||
@@ -48,7 +48,7 @@ Sample::Sample(const QByteArray& base64, int sampleRate)
|
||||
}
|
||||
|
||||
Sample::Sample(const sampleFrame* data, int numFrames, int sampleRate)
|
||||
: m_buffer(std::make_shared<SampleBuffer2>(data, numFrames, sampleRate))
|
||||
: m_buffer(std::make_shared<SampleBuffer>(data, numFrames, sampleRate))
|
||||
, m_startFrame(0)
|
||||
, m_endFrame(m_buffer->size())
|
||||
, m_loopStartFrame(0)
|
||||
@@ -56,7 +56,7 @@ Sample::Sample(const sampleFrame* data, int numFrames, int sampleRate)
|
||||
{
|
||||
}
|
||||
|
||||
Sample::Sample(std::shared_ptr<const SampleBuffer2> buffer)
|
||||
Sample::Sample(std::shared_ptr<const SampleBuffer> buffer)
|
||||
: m_buffer(buffer)
|
||||
, m_startFrame(0)
|
||||
, m_endFrame(m_buffer->size())
|
||||
@@ -265,7 +265,7 @@ auto Sample::playbackSize() const -> int
|
||||
: 0;
|
||||
}
|
||||
|
||||
auto Sample::buffer() const -> std::shared_ptr<const SampleBuffer2>
|
||||
auto Sample::buffer() const -> std::shared_ptr<const SampleBuffer>
|
||||
{
|
||||
const auto lock = std::shared_lock{m_mutex};
|
||||
return m_buffer;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* SampleBuffer2.cpp - container-class SampleBuffer2
|
||||
*
|
||||
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of LMMS - https://lmms.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "SampleBuffer2.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QIODevice>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <samplerate.h>
|
||||
#include <shared_mutex>
|
||||
#include <sndfile.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "AudioEngine.h"
|
||||
#include "DrumSynth.h"
|
||||
#include "Engine.h"
|
||||
#include "PathUtil.h"
|
||||
|
||||
namespace lmms {
|
||||
|
||||
SampleBuffer2::SampleBuffer2(const sampleFrame* data, int numFrames, int sampleRate)
|
||||
: m_data(data, data + numFrames)
|
||||
, m_sampleRate(sampleRate)
|
||||
{
|
||||
}
|
||||
|
||||
SampleBuffer2::SampleBuffer2(const QString& audioFile)
|
||||
{
|
||||
if (audioFile.isEmpty()) { throw std::runtime_error{"Failure loading audio file: Audio file path is empty."}; }
|
||||
|
||||
auto resolvedFileName = PathUtil::toAbsolute(PathUtil::toShortestRelative(audioFile));
|
||||
QFileInfo{resolvedFileName}.suffix() == "ds" ? decodeSampleDS(resolvedFileName) : decodeSampleSF(resolvedFileName);
|
||||
}
|
||||
|
||||
SampleBuffer2::SampleBuffer2(const QByteArray& base64Data, int sampleRate)
|
||||
: m_data(reinterpret_cast<const sampleFrame*>(base64Data.data()),
|
||||
reinterpret_cast<const sampleFrame*>(base64Data.data()) + base64Data.size() / sizeof(sampleFrame))
|
||||
, m_sampleRate(sampleRate)
|
||||
{
|
||||
}
|
||||
|
||||
void swap(SampleBuffer2& first, SampleBuffer2& second) noexcept
|
||||
{
|
||||
using std::swap;
|
||||
swap(first.m_data, second.m_data);
|
||||
swap(first.m_audioFile, second.m_audioFile);
|
||||
swap(first.m_sampleRate, second.m_sampleRate);
|
||||
}
|
||||
|
||||
void SampleBuffer2::decodeSampleSF(const QString& audioFile)
|
||||
{
|
||||
SNDFILE* sndFile = nullptr;
|
||||
auto sfInfo = SF_INFO{};
|
||||
|
||||
// Use QFile to handle unicode file names on Windows
|
||||
auto file = QFile{audioFile};
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
throw std::runtime_error{
|
||||
"Failed to open sample " + audioFile.toStdString() + ": " + file.errorString().toStdString()};
|
||||
}
|
||||
|
||||
sndFile = sf_open_fd(file.handle(), SFM_READ, &sfInfo, false);
|
||||
if (sf_error(sndFile) != 0)
|
||||
{
|
||||
throw std::runtime_error{"Failure opening audio handle: " + std::string{sf_strerror(sndFile)}};
|
||||
}
|
||||
|
||||
auto buf = std::vector<sample_t>(sfInfo.channels * sfInfo.frames);
|
||||
sf_read_float(sndFile, buf.data(), buf.size());
|
||||
|
||||
sf_close(sndFile);
|
||||
file.close();
|
||||
|
||||
auto result = std::vector<sampleFrame>(sfInfo.frames);
|
||||
for (int i = 0; i < static_cast<int>(result.size()); ++i)
|
||||
{
|
||||
if (sfInfo.channels == 1)
|
||||
{
|
||||
// Upmix from mono to stereo
|
||||
result[i] = {buf[i], buf[i]};
|
||||
}
|
||||
else if (sfInfo.channels > 1)
|
||||
{
|
||||
// TODO: Add support for higher number of channels (i.e., 5.1 channel systems)
|
||||
// The current behavior assumes stereo in all cases excluding mono.
|
||||
// This may not be the expected behavior, given some audio files with a higher number of channels.
|
||||
result[i] = {buf[i * sfInfo.channels], buf[i * sfInfo.channels + 1]};
|
||||
}
|
||||
}
|
||||
|
||||
m_data = result;
|
||||
m_audioFile = audioFile;
|
||||
m_sampleRate = sfInfo.samplerate;
|
||||
}
|
||||
|
||||
void SampleBuffer2::decodeSampleDS(const QString& audioFile)
|
||||
{
|
||||
auto data = std::unique_ptr<int_sample_t>{};
|
||||
int_sample_t* dataPtr = nullptr;
|
||||
|
||||
auto ds = DrumSynth{};
|
||||
const auto engineRate = Engine::audioEngine()->processingSampleRate();
|
||||
const auto frames = ds.GetDSFileSamples(audioFile, dataPtr, DEFAULT_CHANNELS, engineRate);
|
||||
data.reset(dataPtr);
|
||||
|
||||
auto result = std::vector<sampleFrame>(frames);
|
||||
if (frames > 0 && data != nullptr)
|
||||
{
|
||||
src_short_to_float_array(data.get(), &result[0][0], frames * DEFAULT_CHANNELS);
|
||||
}
|
||||
else { throw std::runtime_error{"Decoding failure: failed to decode DrumSynth file."}; }
|
||||
|
||||
m_data = result;
|
||||
m_audioFile = audioFile;
|
||||
m_sampleRate = engineRate;
|
||||
}
|
||||
|
||||
QString SampleBuffer2::toBase64() const
|
||||
{
|
||||
// TODO: Replace with non-Qt equivalent
|
||||
const auto data = reinterpret_cast<const char*>(m_data.data());
|
||||
const auto size = static_cast<int>(m_data.size() * sizeof(sampleFrame));
|
||||
const auto byteArray = QByteArray{data, size};
|
||||
return byteArray.toBase64();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::audioFile() const -> QString
|
||||
{
|
||||
return m_audioFile.value_or("");
|
||||
}
|
||||
|
||||
auto SampleBuffer2::sampleRate() const -> sample_rate_t
|
||||
{
|
||||
return m_sampleRate;
|
||||
}
|
||||
|
||||
auto SampleBuffer2::begin() const -> const_iterator
|
||||
{
|
||||
return m_data.begin();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::end() const -> const_iterator
|
||||
{
|
||||
return m_data.end();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::rbegin() const -> const_reverse_iterator
|
||||
{
|
||||
return m_data.rbegin();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::rend() const -> const_reverse_iterator
|
||||
{
|
||||
return m_data.rend();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::data() const -> const sampleFrame*
|
||||
{
|
||||
return m_data.data();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::size() const -> size_type
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
auto SampleBuffer2::empty() const -> bool
|
||||
{
|
||||
return m_data.empty();
|
||||
}
|
||||
|
||||
} // namespace lmms
|
||||
@@ -125,10 +125,10 @@ QString SampleClip::sampleFile() const
|
||||
|
||||
|
||||
|
||||
void SampleClip::setSampleBuffer( SampleBuffer2* sb )
|
||||
void SampleClip::setSampleBuffer( SampleBuffer* sb )
|
||||
{
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
auto buffer = std::shared_ptr<const SampleBuffer2>(sb);
|
||||
auto buffer = std::shared_ptr<const SampleBuffer>(sb);
|
||||
std::atomic_store(&m_sample, std::make_shared<Sample>(buffer));
|
||||
updateLength();
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ SampleRecordHandle::~SampleRecordHandle()
|
||||
{
|
||||
if( !m_buffers.empty() )
|
||||
{
|
||||
SampleBuffer2* sb;
|
||||
SampleBuffer* sb;
|
||||
createSampleBuffer( &sb );
|
||||
m_clip->setSampleBuffer(sb);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ f_cnt_t SampleRecordHandle::framesRecorded() const
|
||||
|
||||
|
||||
|
||||
void SampleRecordHandle::createSampleBuffer(SampleBuffer2** sampleBuf)
|
||||
void SampleRecordHandle::createSampleBuffer(SampleBuffer** sampleBuf)
|
||||
{
|
||||
const f_cnt_t frames = framesRecorded();
|
||||
// create buffer to store all recorded buffers in
|
||||
@@ -130,7 +130,7 @@ void SampleRecordHandle::createSampleBuffer(SampleBuffer2** sampleBuf)
|
||||
data_ptr += ( *it ).second;
|
||||
}
|
||||
// create according sample-buffer out of big buffer
|
||||
*sampleBuf = new SampleBuffer2(data, frames, Engine::audioEngine()->inputSampleRate());
|
||||
*sampleBuf = new SampleBuffer(data, frames, Engine::audioEngine()->inputSampleRate());
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
#include "AudioSampleRecorder.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ f_cnt_t AudioSampleRecorder::framesRecorded() const
|
||||
|
||||
|
||||
|
||||
void AudioSampleRecorder::createSampleBuffer(SampleBuffer2** sampleBuf)
|
||||
void AudioSampleRecorder::createSampleBuffer(SampleBuffer** sampleBuf)
|
||||
{
|
||||
const f_cnt_t frames = framesRecorded();
|
||||
// create buffer to store all recorded buffers in
|
||||
@@ -90,7 +90,7 @@ void AudioSampleRecorder::createSampleBuffer(SampleBuffer2** sampleBuf)
|
||||
data_ptr += ( *it ).second;
|
||||
}
|
||||
// create according sample-buffer out of big buffer
|
||||
*sampleBuf = new SampleBuffer2(data, frames, sampleRate());
|
||||
*sampleBuf = new SampleBuffer(data, frames, sampleRate());
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ void LfoControllerDialog::askUserDefWave()
|
||||
|
||||
auto buffer = SampleLoader::createBufferFromFile(fileName);
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&sampleBuffer, std::shared_ptr<const SampleBuffer2>(std::move(buffer)));
|
||||
std::atomic_store(&sampleBuffer, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
|
||||
if( fileName.isEmpty() == false )
|
||||
{
|
||||
|
||||
@@ -86,29 +86,29 @@ QString SampleLoader::openWaveformFile(const QString& previousFile)
|
||||
previousFile.isEmpty() ? ConfigManager::inst()->factorySamplesDir() + "waveforms/10saw.flac" : previousFile);
|
||||
}
|
||||
|
||||
std::unique_ptr<SampleBuffer2> SampleLoader::createBufferFromFile(const QString& filePath)
|
||||
std::unique_ptr<SampleBuffer> SampleLoader::createBufferFromFile(const QString& filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::make_unique<SampleBuffer2>(filePath);
|
||||
return std::make_unique<SampleBuffer>(filePath);
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
displayError(QString::fromStdString(error.what()));
|
||||
return std::make_unique<SampleBuffer2>();
|
||||
return std::make_unique<SampleBuffer>();
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SampleBuffer2> SampleLoader::createBufferFromBase64(const QString& base64, int sampleRate)
|
||||
std::unique_ptr<SampleBuffer> SampleLoader::createBufferFromBase64(const QString& base64, int sampleRate)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::make_unique<SampleBuffer2>(base64.toUtf8().toBase64(), sampleRate);
|
||||
return std::make_unique<SampleBuffer>(base64.toUtf8().toBase64(), sampleRate);
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
displayError(QString::fromStdString(error.what()));
|
||||
return std::make_unique<SampleBuffer2>();
|
||||
return std::make_unique<SampleBuffer>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "EnvelopeAndLfoView.h"
|
||||
#include "EnvelopeAndLfoParameters.h"
|
||||
#include "SampleLoader.h"
|
||||
#include "embed.h"
|
||||
#include "Engine.h"
|
||||
#include "gui_templates.h"
|
||||
@@ -322,8 +323,9 @@ void EnvelopeAndLfoView::dropEvent( QDropEvent * _de )
|
||||
QString value = StringPairDrag::decodeValue( _de );
|
||||
if( type == "samplefile" )
|
||||
{
|
||||
m_params->m_userWave.setAudioFile(
|
||||
StringPairDrag::decodeValue( _de ) );
|
||||
auto buffer = SampleLoader::createBufferFromFile(StringPairDrag::decodeValue(_de));
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&m_params->m_userWave, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
m_userLfoBtn->model()->setValue( true );
|
||||
m_params->m_lfoWaveModel.setValue(static_cast<int>(EnvelopeAndLfoParameters::LfoShape::UserDefinedWave));
|
||||
_de->accept();
|
||||
@@ -332,9 +334,12 @@ void EnvelopeAndLfoView::dropEvent( QDropEvent * _de )
|
||||
else if( type == QString( "clip_%1" ).arg( static_cast<int>(Track::Type::Sample) ) )
|
||||
{
|
||||
DataFile dataFile( value.toUtf8() );
|
||||
m_params->m_userWave.setAudioFile( dataFile.content().
|
||||
auto file = dataFile.content().
|
||||
firstChildElement().firstChildElement().
|
||||
firstChildElement().attribute( "src" ) );
|
||||
firstChildElement().attribute("src");
|
||||
auto buffer = SampleLoader::createBufferFromFile(file);
|
||||
// TODO C++20: Deprecated, use std::atomic<std::shared_ptr> instead
|
||||
std::atomic_store(&m_params->m_userWave, std::shared_ptr<const SampleBuffer>(std::move(buffer)));
|
||||
m_userLfoBtn->model()->setValue( true );
|
||||
m_params->m_lfoWaveModel.setValue(static_cast<int>(EnvelopeAndLfoParameters::LfoShape::UserDefinedWave));
|
||||
_de->accept();
|
||||
@@ -446,8 +451,6 @@ void EnvelopeAndLfoView::paintEvent( QPaintEvent * )
|
||||
osc_frames *= 100.0f;
|
||||
}
|
||||
|
||||
// userWaveSample() may be used, called out of loop for efficiency
|
||||
m_params->m_userWave.dataReadLock();
|
||||
float old_y = 0;
|
||||
for( int x = 0; x <= LFO_GRAPH_W; ++x )
|
||||
{
|
||||
@@ -483,8 +486,7 @@ void EnvelopeAndLfoView::paintEvent( QPaintEvent * )
|
||||
val = m_randomGraph;
|
||||
break;
|
||||
case EnvelopeAndLfoParameters::LfoShape::UserDefinedWave:
|
||||
val = m_params->m_userWave.
|
||||
userWaveSample( phase );
|
||||
val = Oscillator::userWaveSample(m_params->m_userWave.get(), phase);
|
||||
break;
|
||||
}
|
||||
if( static_cast<f_cnt_t>( cur_sample ) <=
|
||||
@@ -499,7 +501,6 @@ void EnvelopeAndLfoView::paintEvent( QPaintEvent * )
|
||||
graph_y_base + cur_y ) );
|
||||
old_y = cur_y;
|
||||
}
|
||||
m_params->m_userWave.dataUnlock();
|
||||
|
||||
p.setPen( QColor( 201, 201, 225 ) );
|
||||
int ms_per_osc = static_cast<int>( SECS_PER_LFO_OSCILLATION *
|
||||
@@ -520,7 +521,7 @@ void EnvelopeAndLfoView::lfoUserWaveChanged()
|
||||
if( static_cast<EnvelopeAndLfoParameters::LfoShape>(m_params->m_lfoWaveModel.value()) ==
|
||||
EnvelopeAndLfoParameters::LfoShape::UserDefinedWave )
|
||||
{
|
||||
if( m_params->m_userWave.frames() <= 1 )
|
||||
if (m_params->m_userWave->size() <= 1)
|
||||
{
|
||||
TextFloat::displayMessage( tr( "Hint" ),
|
||||
tr( "Drag and drop a sample into this window." ),
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "Graph.h"
|
||||
#include "SampleLoader.h"
|
||||
#include "StringPairDrag.h"
|
||||
#include "SampleBuffer2.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "Oscillator.h"
|
||||
|
||||
namespace lmms
|
||||
|
||||
Reference in New Issue
Block a user