LMMS
Loading...
Searching...
No Matches
SampleBuffer.h
Go to the documentation of this file.
1/*
2 * SampleBuffer.h - container-class SampleBuffer
3 *
4 * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_SAMPLE_BUFFER_H
26#define LMMS_SAMPLE_BUFFER_H
27
28#include <QString>
29#include <memory>
30#include <vector>
31
32#include "AudioEngine.h"
33#include "Engine.h"
34#include "LmmsTypes.h"
35#include "lmms_export.h"
36
37namespace lmms {
38class LMMS_EXPORT SampleBuffer
39{
40public:
44 using iterator = std::vector<SampleFrame>::iterator;
45 using const_iterator = std::vector<SampleFrame>::const_iterator;
46 using difference_type = std::vector<SampleFrame>::difference_type;
47 using size_type = std::vector<SampleFrame>::size_type;
48 using reverse_iterator = std::vector<SampleFrame>::reverse_iterator;
49 using const_reverse_iterator = std::vector<SampleFrame>::const_reverse_iterator;
50
51 SampleBuffer() = default;
52 SampleBuffer(std::vector<SampleFrame> data, int sampleRate, const QString& audioFile = "");
54 const SampleFrame* data, size_t numFrames, int sampleRate = Engine::audioEngine()->outputSampleRate());
55
56 friend void swap(SampleBuffer& first, SampleBuffer& second) noexcept;
57 auto toBase64() const -> QString;
58
59 auto audioFile() const -> const QString& { return m_audioFile; }
61
62 auto begin() -> iterator { return m_data.begin(); }
63 auto end() -> iterator { return m_data.end(); }
64
65 auto begin() const -> const_iterator { return m_data.begin(); }
66 auto end() const -> const_iterator { return m_data.end(); }
67
68 auto cbegin() const -> const_iterator { return m_data.cbegin(); }
69 auto cend() const -> const_iterator { return m_data.cend(); }
70
71 auto rbegin() -> reverse_iterator { return m_data.rbegin(); }
72 auto rend() -> reverse_iterator { return m_data.rend(); }
73
74 auto rbegin() const -> const_reverse_iterator { return m_data.rbegin(); }
75 auto rend() const -> const_reverse_iterator { return m_data.rend(); }
76
77 auto crbegin() const -> const_reverse_iterator { return m_data.crbegin(); }
78 auto crend() const -> const_reverse_iterator { return m_data.crend(); }
79
80 auto data() const -> const SampleFrame* { return m_data.data(); }
81 auto size() const -> size_type { return m_data.size(); }
82 auto empty() const -> bool { return m_data.empty(); }
83
84 static auto emptyBuffer() -> std::shared_ptr<const SampleBuffer>;
85
86 static std::shared_ptr<const SampleBuffer> fromFile(const QString& path);
87 static std::shared_ptr<const SampleBuffer> fromBase64(
88 const QString& str, int sampleRate = Engine::audioEngine()->outputSampleRate());
89
90private:
91 std::vector<SampleFrame> m_data;
92 QString m_audioFile;
94};
95
96} // namespace lmms
97
98#endif // LMMS_SAMPLE_BUFFER_H
static AudioEngine * audioEngine()
Definition Engine.h:59
std::vector< SampleFrame >::size_type size_type
Definition SampleBuffer.h:47
SampleFrame value_type
Definition SampleBuffer.h:41
auto rend() const -> const_reverse_iterator
Definition SampleBuffer.h:75
std::vector< SampleFrame > m_data
Definition SampleBuffer.h:91
SampleFrame & reference
Definition SampleBuffer.h:42
auto end() const -> const_iterator
Definition SampleBuffer.h:66
sample_rate_t m_sampleRate
Definition SampleBuffer.h:93
auto data() const -> const SampleFrame *
Definition SampleBuffer.h:80
QString m_audioFile
Definition SampleBuffer.h:92
auto begin() const -> const_iterator
Definition SampleBuffer.h:65
auto rbegin() -> reverse_iterator
Definition SampleBuffer.h:71
std::vector< SampleFrame >::const_iterator const_iterator
Definition SampleBuffer.h:45
std::vector< SampleFrame >::const_reverse_iterator const_reverse_iterator
Definition SampleBuffer.h:49
auto cbegin() const -> const_iterator
Definition SampleBuffer.h:68
std::vector< SampleFrame >::iterator iterator
Definition SampleBuffer.h:44
std::vector< SampleFrame >::difference_type difference_type
Definition SampleBuffer.h:46
const SampleFrame & const_reference
Definition SampleBuffer.h:43
auto rbegin() const -> const_reverse_iterator
Definition SampleBuffer.h:74
auto size() const -> size_type
Definition SampleBuffer.h:81
auto begin() -> iterator
Definition SampleBuffer.h:62
auto crbegin() const -> const_reverse_iterator
Definition SampleBuffer.h:77
auto cend() const -> const_iterator
Definition SampleBuffer.h:69
friend void swap(SampleBuffer &first, SampleBuffer &second) noexcept
Definition SampleBuffer.cpp:50
auto rend() -> reverse_iterator
Definition SampleBuffer.h:72
auto audioFile() const -> const QString &
Definition SampleBuffer.h:59
auto empty() const -> bool
Definition SampleBuffer.h:82
auto end() -> iterator
Definition SampleBuffer.h:63
SampleBuffer()=default
auto toBase64() const -> QString
Definition SampleBuffer.cpp:58
std::vector< SampleFrame >::reverse_iterator reverse_iterator
Definition SampleBuffer.h:48
auto sampleRate() const -> sample_rate_t
Definition SampleBuffer.h:60
auto crend() const -> const_reverse_iterator
Definition SampleBuffer.h:78
Definition SampleFrame.h:41
Definition AudioAlsa.cpp:35
std::uint32_t sample_rate_t
Definition LmmsTypes.h:42
#define const
Definition zconf.h:137