Audacity 3.2.0
TestWaveClipMaker.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 TestWaveClipMaker.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "TestWaveClipMaker.h"
14
17 : mSampleRate { sampleRate }
18 , mFactory { factory }
19{
20}
21
23 const std::vector<std::vector<float>>& values, Operations operations) const
24{
25 const auto numSamples = values[0].size();
26 const auto clip = std::make_shared<WaveClip>(
28 // Is there any more convenient way of doing this ?
29 clip->InsertSilence(0, 1. * numSamples / mSampleRate);
30 for (auto i = 0u; i < values.size(); ++i)
31 {
32 AudioContainer audio(numSamples, 1u);
33 std::copy(values[i].begin(), values[i].end(), audio.Get()[0u]);
34 clip->SetSamples(
35 i, AudioContainerHelper::GetData<char>(audio)[0u], floatSample, 0,
36 numSamples, floatSample);
37 }
38 operations(*clip);
39 return clip;
40}
41
43 const std::vector<float>& values, size_t numChannels,
44 Operations operations) const
45{
46 return ClipFilledWith(
47 std::vector<std::vector<float>> { values }, operations);
48}
49
51 float value, size_t numValues, size_t numChannels,
52 Operations operations) const
53{
54 std::vector<float> values(numValues);
55 std::fill(values.begin(), values.end(), value);
56 return ClipFilledWith(values, numChannels, operations);
57}
static RegisteredToolbarFactory factory
const wxChar * values
std::shared_ptr< SampleBlockFactory > SampleBlockFactoryPtr
Definition: SampleBlock.h:31
MockedAudio audio
std::shared_ptr< WaveClip > WaveClipHolder
Definition: WaveClip.h:43
const SampleBlockFactoryPtr mFactory
WaveClipHolder ClipFilledWith(const std::vector< std::vector< float > > &values, Operations operations=[](WaveClip &) {}) const
TestWaveClipMaker(int sampleRate, SampleBlockFactoryPtr)
std::function< void(WaveClip &)> Operations
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40