-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactor SampleBuffer
#6610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor SampleBuffer
#6610
Changes from 120 commits
Commits
Show all changes
170 commits
Select commit
Hold shift + click to select a range
49e8852
Add refactored SampleBuffer
sakertooth aeef0f8
Add Sample
sakertooth 51bd371
Add SampleLoader
sakertooth e01b1fc
Integrate changes into AudioSampleRecorder
sakertooth 7245b1a
Integrate changes into Oscillator
sakertooth d3ecea3
Integrate changes into SampleClip/SamplePlayHandle
sakertooth 253ce15
Integrate changes into Graph
sakertooth 6bf4483
Remove SampleBuffer include from SampleClipView
sakertooth 25bb7ab
Integrate changes into Patman
sakertooth aca875b
Reduce indirection to sample buffer from Sample
sakertooth 0017f66
Integrate changes into AudioFileProcessor
sakertooth 53728ce
Remove old SampleBuffer
sakertooth 12fe2b9
Include memory header in TripleOscillator
sakertooth 2b37874
Include memory header in Oscillator
sakertooth 6a53a10
Use atomic_load within SampleClip::sample
sakertooth 3688073
Include memory header in EnvelopeAndLfoParameters
sakertooth d16b77e
Use std::atomic_load for most calls to Oscillator::userWaveSample
sakertooth dbf3214
Revert accidental change on SamplePlayHandle L.111
sakertooth d7f9f59
Check if audio file is empty before loading
sakertooth 622405e
Add asserts to Sample
sakertooth cb42f0a
Add cassert include within Sample
sakertooth 9583fcf
Adjust assert expressions in Sample
sakertooth 1d45233
Remove use of shared ownership for Sample
sakertooth 8c834aa
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth 48b545b
Use ArrayVector in Sample
sakertooth 2b6166f
Enforce std::atomic_load for users of std::shared_ptr<const SampleBuf…
sakertooth 6f79621
Use requestChangesGuard in ClipView::remove
sakertooth d68bd6f
Revert only formatting changes
sakertooth b1516ea
Update ClipView::remove comment
sakertooth 5ac9159
Revert "Remove use of shared ownership for Sample"
sakertooth 98c73b3
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth d5bf069
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth f5615b4
Fix heap-use-after-free in Track::loadSettings
sakertooth a5a01cf
Remove m_buffer asserts
sakertooth 1f932d3
Refactor play functionality (again)
sakertooth e890aac
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth 8d18010
Merge branch 'master' into refactor-samplebuffer
sakertooth 7025194
Change copyright
sakertooth 700b7c7
Cast processingSampleRate to float
sakertooth 5fa3dab
Update include/SampleLoader.h
sakertooth db77259
Update include/SampleLoader.h
sakertooth d4756de
Format SampleLoader.h
sakertooth f0ff0f9
Remove SampleBuffer.h include in SampleRecordHandle.h
sakertooth 44c5bb5
Update src/core/Oscillator.cpp
sakertooth ee19205
Use typeInfo<float> for float equality comparison
sakertooth 42086bb
Use std::min in Sample::visualize
sakertooth d6e6c1c
Move in result to m_data
sakertooth 1e0c75c
Use if block in playSampleRange
sakertooth 6900a2b
Pass in unique_ptr to SampleClip::setSampleBuffer
sakertooth 4470454
Return const QString& from SampleBuffer::audioFile
sakertooth b324577
Do not pass in unique_ptr by r-value reference
sakertooth 8e41e4c
Use isEmpty() within SampleClipView::updateSample
sakertooth 7d87637
Remove use of atomic_store and atomic_load
sakertooth 0600ced
Remove ArrayVector comment
sakertooth 99e628a
Use array specialization for unique_ptr when managing DrumSynth data
sakertooth c5f7ccb
Don't manually delete Clip if it has a Track
sakertooth 73da2e1
Clean up generateAntiAliasUserWaveTable function
sakertooth d41d02a
Set user wave, even when value is empty
sakertooth 7c8804b
Remove whitespace in EnvelopeAndLfoParameters.cpp L#121
sakertooth 8689a68
Fix error in c5f7ccba492dd867524156afa652c4eff99f9b40
sakertooth 900e52c
Convert std::shared_ptr<Sample> to Sample
sakertooth 1769ed5
Fix segfault when closing LMMS
sakertooth dcedcca
Construct buffer through SampleLoader in FileBrowser's previewFileIte…
sakertooth fb6c7b5
Move guard out of removeClip and deleteClips
sakertooth 2792fcb
Simplify the switch in play function for loopMode
sakertooth 8036289
Merge branch 'master' into refactor-samplebuffer
sakertooth 46170b5
Add SampleDecoder
sakertooth f08c94a
Add LMMS_HAVE_OGGVORBIS comment
sakertooth 432fafb
Fix unused variable error
sakertooth 47af4f7
Include unordered_map
sakertooth 5af5961
Simplify SampleDecoder
sakertooth 6301022
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth 0e03a38
Attempt to fix Mac builds
sakertooth 6b0b131
Attempt to fix Mac builds take 2
sakertooth afefc5b
Add vector include to SampleDecoder
sakertooth 42e337b
Add TODO comment about shared ownership with clips
sakertooth b4ab016
Adjust TODO comment
sakertooth 215f476
Remove Sample::playbackSize
sakertooth bccc685
Fix issues involving length of Sample's
sakertooth 33783bf
Simplify if condition in src/gui/FileBrowser.cpp
sakertooth 6c98654
Simplify if condition in src/core/SampleBuffer.cpp
sakertooth 12464bc
Update style in include/Oscillator.h
sakertooth dcc5265
Format src/core/SampleDecoder.cpp
sakertooth c2a9dee
Set the sample rate to be that of the AudioEngine by default
sakertooth 9046fc5
Set single-argument constructors in Sample and SampleBuffer to be exp…
sakertooth b617441
Do not make a copy when reading result from the decoder
sakertooth 2025c98
Add constructor to pass in vector of sampleFrame's directly
sakertooth 503561a
Do a pass by value and move in SampleBuffer.cpp
sakertooth 6793a74
Pass vector by value in SampleBuffer.h
sakertooth 4372eef
Make Sample(std::shared_ptr) constructor explicit
sakertooth 37d05d0
Properly draw sample waveform when reversed
sakertooth 3580999
Collect sample not found errors when loading project
sakertooth 65d7803
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth df980ab
Use std::make_unique<SampleBuffer> in SampleLoader
sakertooth 037e007
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth bcce57b
Fix loop modes
sakertooth ea91765
Limit sample duration to [start, end] and not the entire buffer
sakertooth d0c6f35
Use structured binding to access buffer
sakertooth fef9f8f
Check if GUI exists before displaying error
sakertooth 971e832
Make Base64 constructor pass in the string instead
sakertooth aa760dc
Remove use of QByteArray::fromBase64Encoding
sakertooth 2957647
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth cf0d3a6
Inline simple functions in SampleBuffer
sakertooth be86cc3
Dynamically include supported audio file types
sakertooth 686dc3c
Remove redundant inline specifier
sakertooth 4ab1ebe
Translate file types
sakertooth 0cb43f3
Cache calls to SampleDecoder::supportedAudioTypes
sakertooth 6baecfa
Fix translations in SampleLoader (again)
sakertooth c863923
Store static local variable for supported audio types instead of in t…
sakertooth 10c23c3
Clamp frame index depending on loop mode
sakertooth d5c6c63
Inline member functions of PlaybackState
sakertooth b0ace22
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth 1cb0bef
Do not collect errors in SampleLoader when loading projects
sakertooth 74533d2
Default construct shared pointers to SampleBuffer
sakertooth 4db9a17
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth 7678c41
Simplify and optimize Sample::visulaize()
DanielKauss 0151ee1
Remove redundant gui:: prefix
sakertooth 9fbfc08
Merge remote-tracking branch 'DanielKauss/refactor-samplebuffer' into…
sakertooth a215574
Rearrange Sample::visualize after optimizations by DanielKauss
sakertooth 0dbbf1b
Apply amplification when visualizing sample waveforms
sakertooth 6a45528
Set default min and max values to 1 and -1
sakertooth 43cdfb2
Treat waveform as mono signal when visualizing
sakertooth e68fde3
Ensure visualization works when framesPerPixel < 1
sakertooth dd997f1
Simplify Sample::visualize a bit more
sakertooth e2a7b67
Fix CPU lag in Sample by using atomics (with relaxed ordering)
sakertooth 77a5fe0
Merge remote-tracking branch 'upstream/master' into refactor-samplebu…
sakertooth e85f339
Fix errors from merge
sakertooth 8ebd3a2
Fix broken LFO controller functionality
sakertooth a008316
Remove TODO
sakertooth d2daa2d
Update EnvelopeAndLfoView.cpp
sakertooth 5f5dee5
Update src/gui/clips/SampleClipView.cpp
sakertooth 27f4438
Update plugins/SlicerT/SlicerT.cpp
sakertooth 0f5c27a
Update plugins/SlicerT/SlicerT.cpp
sakertooth 807da3b
Store shortest relative path in SampleBuffer
sakertooth c971d1b
Tie up a few loose ends
sakertooth 46e5cca
Use sample_rate_t when storing sample rate in SampleBuffer
sakertooth c7ce788
Add missing named requirement functions and aliases
sakertooth 0a38244
Use sampledata attribute when loading from Base64 in AFP
sakertooth 5b51686
Remove initializer for m_userWave in the constructor
sakertooth e7da94d
Do not use trailing return syntax when return is void
sakertooth 9054a9f
Move decoder functionality into unnamed namespace
sakertooth 70ec50d
Remove redundant gui:: prefix
sakertooth 1bfb4bb
Use PathUtil::toAbsolute to simplify code in SampleLoader::openAudioFile
sakertooth 97cdfdb
Fix translations in SampleLoader::openAudioFile
sakertooth 1d098d3
Fix formatting for ternary operator
sakertooth 6cca49c
Remove redundant inlines
sakertooth 429e889
Resolve UB when decoding from Base64 data in SampleBuffer
sakertooth 9ac9c09
Fix up SampleClip constructors
sakertooth 8f6d986
Add AudioResampler, a wrapper class around libsamplerate
sakertooth c6e7417
Move buffer when moving and simplify assignment functions in Sample
sakertooth b84b383
Move Sample::visualize out of Sample and into the GUI namespace
sakertooth 6bb3e01
Initialize supportedAudioTypes in static lambda
sakertooth e50ac67
Return shared pointer from SampleLoader
sakertooth 0217c28
Create and use static empty SampleBuffer by default
sakertooth d7bcf2f
Fix header guard in SampleWaveform.h
sakertooth a735c03
Remove use of src_clone
sakertooth 09e336b
Include memory header in SampleBuffer.h
sakertooth f444281
Remove mutex and shared_mutex includes in Sample.h
sakertooth 2b553f2
Attempt to fix string operand error within AudioResampler
sakertooth 2c58bb6
Include string header in AudioResampler.cpp
sakertooth 9ffba98
Add LMMS_EXPORT for SampleWaveform class declaration
sakertooth 5b9a847
Add LMMS_EXPORT for AudioResampler class declaration
sakertooth a45802f
Enforce returning std::shared_ptr<const SampleBuffer>
sakertooth 8cdb1e2
Restrict the size of the memcpy to the destination size, not the sour…
sakertooth b6480a2
Do not make resample const
sakertooth d56083d
Initialize data.end_of_input
sakertooth bf4b9c7
Add trailing new lines
sakertooth c12e7de
Simplify AudioResampler interface
sakertooth c81d838
Fix header guard prefix to LMMS_GUI instead of LMMS
sakertooth 5a45282
Remove Sample::resampleSampleRange
sakertooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sakertooth marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * Sample.h - State for container-class SampleBuffer | ||
| * | ||
| * Copyright (c) 2023 saker <[email protected]> | ||
| * | ||
| * 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_H | ||
| #define LMMS_SAMPLE_H | ||
|
|
||
| #include <cmath> | ||
| #include <memory> | ||
|
|
||
| #include "Note.h" | ||
| #include "SampleBuffer.h" | ||
| #include "lmms_export.h" | ||
|
|
||
| #ifdef __MINGW32__ | ||
| #include <mingw.mutex.h> | ||
| #include <mingw.shared_mutex.h> | ||
| #else | ||
| #include <mutex> | ||
| #include <shared_mutex> | ||
| #endif | ||
|
|
||
| class QPainter; | ||
| class QRect; | ||
|
|
||
| namespace lmms { | ||
messmerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class LMMS_EXPORT Sample | ||
| { | ||
| public: | ||
| // 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 | ||
| static constexpr auto s_interpolationMargins = std::array<int, 5>{64, 64, 64, 4, 4}; | ||
|
|
||
| enum class Loop | ||
| { | ||
| Off, | ||
| On, | ||
| PingPong | ||
| }; | ||
|
|
||
| class LMMS_EXPORT PlaybackState | ||
| { | ||
| public: | ||
| PlaybackState(bool varyingPitch = false, int interpolationMode = SRC_LINEAR) | ||
| : m_varyingPitch(varyingPitch) | ||
| , m_interpolationMode(interpolationMode) | ||
| { | ||
| auto error = 0; | ||
| m_resampleState = src_new(m_interpolationMode, DEFAULT_CHANNELS, &error); | ||
| if (error != 0) | ||
| { | ||
| throw std::runtime_error{"Error creating resample state: " + std::string{src_strerror(error)}}; | ||
| } | ||
| } | ||
|
|
||
| ~PlaybackState() noexcept { src_delete(m_resampleState); } | ||
sakertooth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| auto frameIndex() const -> f_cnt_t { return m_frameIndex; } | ||
| auto varyingPitch() const -> bool { return m_varyingPitch; } | ||
| auto backwards() const -> bool { return m_backwards; } | ||
| auto interpolationMode() const -> int { return m_interpolationMode; } | ||
|
|
||
| auto setFrameIndex(f_cnt_t frameIndex) -> void { m_frameIndex = frameIndex; } | ||
sakertooth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auto setVaryingPitch(bool varyingPitch) -> void { m_varyingPitch = varyingPitch; } | ||
| auto setBackwards(bool backwards) -> void { m_backwards = backwards; } | ||
|
|
||
| private: | ||
| f_cnt_t m_frameIndex = 0; | ||
| bool m_varyingPitch = false; | ||
| bool m_backwards = false; | ||
| SRC_STATE* m_resampleState = nullptr; | ||
| int m_interpolationMode = SRC_LINEAR; | ||
| friend class Sample; | ||
| }; | ||
|
|
||
| Sample() = default; | ||
| explicit Sample(const QString& audioFile); | ||
| Sample(const QByteArray& base64, int sampleRate = Engine::audioEngine()->processingSampleRate()); | ||
| Sample(const sampleFrame* data, int numFrames, int sampleRate = Engine::audioEngine()->processingSampleRate()); | ||
| explicit Sample(std::shared_ptr<const SampleBuffer> buffer); | ||
| Sample(const Sample& other); | ||
| Sample(Sample&& other) noexcept; | ||
|
|
||
| Sample& operator=(Sample other) noexcept; | ||
| friend auto swap(Sample& first, Sample& second) -> void; | ||
|
|
||
| auto play(sampleFrame* dst, PlaybackState* state, int numFrames, float desiredFrequency = DefaultBaseFreq, | ||
| Loop loopMode = Loop::Off) const -> bool; | ||
| auto visualize(QPainter& p, const QRect& dr, int fromFrame = 0, int toFrame = 0) const -> void; | ||
sakertooth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| auto sampleDuration() const -> std::chrono::milliseconds; | ||
| auto sampleFile() const -> const QString&; | ||
| auto sampleRate() const -> int; | ||
| auto sampleSize() const -> int; | ||
|
|
||
| auto toBase64() const -> QString; | ||
|
|
||
| auto data() -> const sampleFrame*; | ||
| auto buffer() const -> std::shared_ptr<const SampleBuffer>; | ||
| auto startFrame() const -> int; | ||
| auto endFrame() const -> int; | ||
| auto loopStartFrame() const -> int; | ||
| auto loopEndFrame() const -> int; | ||
| auto amplification() const -> float; | ||
| auto frequency() const -> float; | ||
| auto reversed() const -> bool; | ||
|
|
||
| auto setStartFrame(int startFrame) -> void; | ||
| auto setEndFrame(int endFrame) -> void; | ||
| auto setLoopStartFrame(int loopStartFrame) -> void; | ||
| auto setLoopEndFrame(int loopEndFrame) -> void; | ||
| auto setAllPointFrames(int startFrame, int endFrame, int loopStartFrame, int loopEndFrame) -> void; | ||
| auto setAmplification(float amplification) -> void; | ||
| auto setFrequency(float frequency) -> void; | ||
| auto setReversed(bool reversed) -> void; | ||
|
|
||
| private: | ||
| auto playSampleRange(PlaybackState* state, sampleFrame* dst, size_t numFrames) const -> void; | ||
| auto resampleSampleRange(SRC_STATE* state, sampleFrame* src, sampleFrame* dst, size_t numInputFrames, | ||
| size_t numOutputFrames, double ratio) const -> SRC_DATA; | ||
| auto amplifySampleRange(sampleFrame* src, int numFrames) const -> void; | ||
| auto copyBufferForward(sampleFrame* dst, int initialPosition, int advanceAmount) const -> void; | ||
| auto copyBufferBackward(sampleFrame* dst, int initialPosition, int advanceAmount) const -> void; | ||
|
|
||
| private: | ||
| std::shared_ptr<const SampleBuffer> m_buffer = std::make_shared<SampleBuffer>(); | ||
| int m_startFrame = 0; | ||
| int m_endFrame = 0; | ||
| int m_loopStartFrame = 0; | ||
| int m_loopEndFrame = 0; | ||
| float m_amplification = 1.0f; | ||
| float m_frequency = DefaultBaseFreq; | ||
| bool m_reversed = false; | ||
| mutable std::shared_mutex m_mutex; | ||
| }; | ||
| } // namespace lmms | ||
| #endif | ||
sakertooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.