File: MockSampleBlock.cpp

package info (click to toggle)
audacity 3.7.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,800 kB
  • sloc: cpp: 366,277; ansic: 198,323; lisp: 7,761; sh: 3,414; python: 1,501; xml: 1,385; perl: 854; makefile: 125
file content (100 lines) | stat: -rw-r--r-- 2,346 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*  SPDX-License-Identifier: GPL-2.0-or-later */
/*!********************************************************************

  Audacity: A Digital Audio Editor

  MockSampleBlock.cpp

  Matthieu Hodgkinson

**********************************************************************/
#include "MockSampleBlock.h"

namespace
{
std::vector<char>
copyToVector(constSamplePtr src, size_t numsamples, sampleFormat srcformat)
{
   const auto numChars = numsamples * SAMPLE_SIZE(srcformat);
   std::vector<char> data(numChars);
   std::copy(src, src + numChars, data.begin());
   return data;
}
} // namespace

MockSampleBlock::MockSampleBlock(
   long long id, constSamplePtr src, size_t numsamples, sampleFormat srcformat)
    : id { id }
    , srcFormat { srcformat }
    , data { copyToVector(src, numsamples, srcformat) }
{
}

void MockSampleBlock::CloseLock() noexcept
{
}

SampleBlockID MockSampleBlock::GetBlockID() const
{
   return id;
}

sampleFormat MockSampleBlock::GetSampleFormat() const
{
   return srcFormat;
}

size_t MockSampleBlock::GetSampleCount() const
{
   return data.size() / SAMPLE_SIZE(srcFormat);
}

bool MockSampleBlock::GetSummary256(
   float* dest, size_t frameoffset, size_t numframes)
{
   return true;
}

bool MockSampleBlock::GetSummary64k(
   float* dest, size_t frameoffset, size_t numframes)
{
   return true;
}

size_t MockSampleBlock::GetSpaceUsage() const
{
   return data.size();
}

void MockSampleBlock::SaveXML(XMLWriter&)
{
}

size_t MockSampleBlock::DoGetSamples(
   samplePtr dest, sampleFormat destformat, size_t sampleoffset,
   size_t numsamples)
{
   const auto charOffset = sampleoffset * SAMPLE_SIZE(srcFormat);
   const auto numChars = numsamples * SAMPLE_SIZE(destformat);
   std::copy(
      data.data() + charOffset, data.data() + charOffset + numChars, dest);
   return numsamples;
}

MinMaxRMS MockSampleBlock::DoGetMinMaxRMS(size_t start, size_t len)
{
   return { 0, 0, 0 };
}

MinMaxRMS MockSampleBlock::DoGetMinMaxRMS() const
{
   return { 0, 0, 0 };
}

BlockSampleView MockSampleBlock::GetFloatSampleView(bool mayThrow)
{
   std::vector<float> floatData { reinterpret_cast<const float*>(data.data()),
                                  reinterpret_cast<const float*>(
                                     data.data() + data.size()) };
   return std::make_shared<std::vector<float>>(floatData);
}