Audacity 3.2.0
SilenceSegment.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 SilenceSegment.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "SilenceSegment.h"
12
13#include <algorithm>
14#include <cassert>
15
16SilenceSegment::SilenceSegment(size_t numChannels, sampleCount numSamples)
17 : mNumChannels { numChannels }
18 , mNumRemainingSamples { numSamples }
19{
20}
21
22size_t
23SilenceSegment::GetFloats(float *const *buffers, size_t numSamples)
24{
25 const size_t numSamplesToProduce =
26 std::min<long long>(mNumRemainingSamples.as_long_long(), numSamples);
27 for (auto i = 0u; i < mNumChannels; ++i)
28 {
29 auto buffer = buffers[i];
30 std::fill(buffer, buffer + numSamplesToProduce, 0.f);
31 }
32 mNumRemainingSamples -= numSamplesToProduce;
33 return numSamplesToProduce;
34}
35
37{
38 return mNumRemainingSamples == 0u;
39}
40
42{
43 return mNumChannels;
44}
bool Empty() const override
Whether the segment has no more samples to provide.
sampleCount mNumRemainingSamples
const size_t mNumChannels
SilenceSegment(size_t numChannels, sampleCount numSamples)
size_t GetFloats(float *const *buffers, size_t numSamples) override
Fills buffers with as many as numSamples or the number of remaining samples, whichever is smaller.
size_t NChannels() const override
The number of channels in the segment.
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
long long as_long_long() const
Definition: SampleCount.h:48