Audacity 3.2.0
FloatVectorClip.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 FloatVectorClip.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11
12#include "FloatVectorClip.h"
13#include <cmath>
14
16 int sampleRate, const std::vector<std::vector<float>>& audio)
17 : mSampleRate { sampleRate }
18 , mAudio { audio }
19{
20}
21
22namespace
23{
24std::vector<std::vector<float>>
25Duplicate(const std::vector<float>& audio, size_t numChannels)
26{
27 std::vector<std::vector<float>> duplicate;
28 for (auto i = 0u; i < numChannels; ++i)
29 duplicate.push_back(audio);
30 return duplicate;
31}
32} // namespace
33
35 int sampleRate, const std::vector<float>& audio, size_t numChannels)
37{
38}
39
41 size_t iChannel, sampleCount start, size_t len, bool mayThrow) const
42{
43 std::vector<BlockSampleView> blockViews {
44 std::make_shared<std::vector<float>>(mAudio[iChannel])
45 };
46 // todo(mhodgkinson) review argument types.
48 std::move(blockViews), start.as_size_t(), len);
49}
50
52{
53 return mAudio[0].size();
54}
55
57{
58 return mAudio.size();
59}
60
62{
63 return mSampleRate;
64}
65
67{
68 return sampleCount(floor(time * GetRate() + 0.5));
69}
70
72{
73 return stretchRatio * mAudio[0].size() / mSampleRate;
74}
MockedAudio audio
double GetPlayDuration() const
const int mSampleRate
int GetRate() const override
FloatVectorClip(int sampleRate, const std::vector< std::vector< float > > &audio)
const std::vector< std::vector< float > > mAudio
AudioSegmentSampleView GetSampleView(size_t iChannel, sampleCount start, size_t len, bool mayThrow) const override
sampleCount GetVisibleSampleCount() const override
size_t NChannels() const override
sampleCount TimeToSamples(double time) const override
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
size_t as_size_t() const
Definition: SampleCount.cpp:16
std::vector< std::vector< float > > Duplicate(const std::vector< float > &audio, size_t numChannels)