Audacity 3.2.0
MockSampleBlock.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 MockSampleBlock.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "MockSampleBlock.h"
12
13namespace
14{
15std::vector<char>
16copyToVector(constSamplePtr src, size_t numsamples, sampleFormat srcformat)
17{
18 const auto numChars = numsamples * SAMPLE_SIZE(srcformat);
19 std::vector<char> data(numChars);
20 std::copy(src, src + numChars, data.begin());
21 return data;
22}
23} // namespace
24
26 long long id, constSamplePtr src, size_t numsamples, sampleFormat srcformat)
27 : id { id }
28 , srcFormat { srcformat }
29 , data { copyToVector(src, numsamples, srcformat) }
30{
31}
32
34{
35}
36
38{
39 return id;
40}
41
43{
44 return srcFormat;
45}
46
48{
49 return data.size() / SAMPLE_SIZE(srcFormat);
50}
51
53 float* dest, size_t frameoffset, size_t numframes)
54{
55 return true;
56}
57
59 float* dest, size_t frameoffset, size_t numframes)
60{
61 return true;
62}
63
65{
66 return data.size();
67}
68
70{
71}
72
74 samplePtr dest, sampleFormat destformat, size_t sampleoffset,
75 size_t numsamples)
76{
77 const auto charOffset = sampleoffset * SAMPLE_SIZE(srcFormat);
78 const auto numChars = numsamples * SAMPLE_SIZE(destformat);
80 data.data() + charOffset, data.data() + charOffset + numChars, dest);
81 return numsamples;
82}
83
85{
86 return { 0, 0, 0 };
87}
88
90{
91 return { 0, 0, 0 };
92}
93
95{
96 std::vector<float> floatData { reinterpret_cast<const float*>(data.data()),
97 reinterpret_cast<const float*>(
98 data.data() + data.size()) };
99 return std::make_shared<std::vector<float>>(floatData);
100}
std::shared_ptr< std::vector< float > > BlockSampleView
long long SampleBlockID
Definition: CloudSyncDTO.h:26
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
char * samplePtr
Definition: SampleFormat.h:57
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:52
const char * constSamplePtr
Definition: SampleFormat.h:58
int id
MockSampleBlock(long long id, constSamplePtr src, size_t numsamples, sampleFormat srcformat)
SampleBlockID GetBlockID() const override
const long long id
bool GetSummary64k(float *dest, size_t frameoffset, size_t numframes) override
Non-throwing, should fill with zeroes on failure.
MinMaxRMS DoGetMinMaxRMS() const override
sampleFormat GetSampleFormat() const override
void CloseLock() noexcept override
void SaveXML(XMLWriter &) override
bool GetSummary256(float *dest, size_t frameoffset, size_t numframes) override
Non-throwing, should fill with zeroes on failure.
size_t GetSampleCount() const override
size_t DoGetSamples(samplePtr dest, sampleFormat destformat, size_t sampleoffset, size_t numsamples) override
const sampleFormat srcFormat
const std::vector< char > data
BlockSampleView GetFloatSampleView(bool mayThrow) override
size_t GetSpaceUsage() const override
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
std::vector< char > copyToVector(constSamplePtr src, size_t numsamples, sampleFormat srcformat)
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40