Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AudioSegmentSampleView Class Referencefinal

#include <AudioSegmentSampleView.h>

Collaboration diagram for AudioSegmentSampleView:
[legend]

Public Member Functions

 AudioSegmentSampleView (std::vector< BlockSampleView > blockViews, size_t start, size_t length)
 Constructs an AudioSegmentSampleView from BlockSampleViews. More...
 
 AudioSegmentSampleView (size_t length)
 Constructs a silent AudioSegmentSampleView. More...
 
void Copy (float *buffer, size_t bufferSize) const
 Copies up to GetSampleCount() or bufferSize samples, whichever is less, into buffer. Samples after that are zeroed. More...
 
void AddTo (float *buffer, size_t bufferSize) const
 Adds up to GetSampleCount() or bufferSize samples, whichever is less, into buffer. Samples after that are left unchanged. More...
 
size_t GetSampleCount () const
 The number of samples in this view. More...
 

Private Member Functions

void DoCopy (float *buffer, size_t bufferSize) const
 
void DoAdd (float *buffer, size_t bufferSize) const
 

Private Attributes

const std::vector< BlockSampleViewmBlockViews
 
const size_t mStart = 0
 
const size_t mLength
 
const bool mIsSilent
 

Detailed Description

Definition at line 25 of file AudioSegmentSampleView.h.

Constructor & Destructor Documentation

◆ AudioSegmentSampleView() [1/2]

AudioSegmentSampleView::AudioSegmentSampleView ( std::vector< BlockSampleView blockViews,
size_t  start,
size_t  length 
)

Constructs an AudioSegmentSampleView from BlockSampleViews.

Parameters
blockViewsA continuous sequence of samples, segmented in blocks.
startIndex of the first sample in blockViews to look at.
lengthThe number of samples from start to look at.
Precondition
!blockViews.empty()
start < blockViews[0].size()
length <= sum(sizes(blockViews)) - start

Audacity: A Digital Audio Editor

AudioSegmentSampleView.cpp

Matthieu Hodgkinson

Definition at line 17 of file AudioSegmentSampleView.cpp.

19 : mBlockViews { std::move(blockViews) }
20 , mStart { start }
21 , mLength { length }
22 , mIsSilent { false }
23{
24 assert(
25 start + length <=
26 std::accumulate(
27 mBlockViews.begin(), mBlockViews.end(), 0u,
28 [](size_t acc, const auto& block) { return acc + block->size(); }));
29}
const std::vector< BlockSampleView > mBlockViews

References mBlockViews.

◆ AudioSegmentSampleView() [2/2]

AudioSegmentSampleView::AudioSegmentSampleView ( size_t  length)

Constructs a silent AudioSegmentSampleView.

Parameters
lengthThe number of "silence samples".

Definition at line 31 of file AudioSegmentSampleView.cpp.

32 : mLength { length }
33 , mIsSilent { true }
34{
35}

Member Function Documentation

◆ AddTo()

void AudioSegmentSampleView::AddTo ( float *  buffer,
size_t  bufferSize 
) const

Adds up to GetSampleCount() or bufferSize samples, whichever is less, into buffer. Samples after that are left unchanged.

Definition at line 43 of file AudioSegmentSampleView.cpp.

44{
45 if (mIsSilent)
46 return;
47 DoAdd(buffer, bufferSize);
48}
void DoAdd(float *buffer, size_t bufferSize) const

References DoAdd(), and mIsSilent.

Here is the call graph for this function:

◆ Copy()

void AudioSegmentSampleView::Copy ( float *  buffer,
size_t  bufferSize 
) const

Copies up to GetSampleCount() or bufferSize samples, whichever is less, into buffer. Samples after that are zeroed.

Definition at line 37 of file AudioSegmentSampleView.cpp.

38{
39 mIsSilent ? std::fill(buffer, buffer + bufferSize, 0.f) :
40 DoCopy(buffer, bufferSize);
41}
void DoCopy(float *buffer, size_t bufferSize) const

References DoCopy(), and mIsSilent.

Referenced by ClipTimeAndPitchSource::Pull().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoAdd()

void AudioSegmentSampleView::DoAdd ( float *  buffer,
size_t  bufferSize 
) const
private

Definition at line 61 of file AudioSegmentSampleView.cpp.

62{
63 size_t toWrite { limitSampleBufferSize(bufferSize, mLength) };
64 size_t written = 0u;
65 size_t offset = mStart;
66 for (const auto& block : mBlockViews)
67 {
68 const auto toWriteFromBlock = std::min(block->size() - offset, toWrite);
69 const auto src = block->data() + offset;
70 const auto dst = buffer + written;
71 std::transform(src, src + toWriteFromBlock, dst, dst, std::plus {});
72 toWrite -= toWriteFromBlock;
73 written += toWriteFromBlock;
74 offset = 0;
75 }
76}
int min(int a, int b)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22

References limitSampleBufferSize(), mBlockViews, min(), mLength, and mStart.

Referenced by AddTo(), and DoCopy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoCopy()

void AudioSegmentSampleView::DoCopy ( float *  buffer,
size_t  bufferSize 
) const
private

Definition at line 55 of file AudioSegmentSampleView.cpp.

56{
57 std::fill(buffer, buffer + bufferSize, 0.f);
58 DoAdd(buffer, bufferSize);
59}

References DoAdd().

Referenced by Copy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSampleCount()

size_t AudioSegmentSampleView::GetSampleCount ( ) const

The number of samples in this view.

Definition at line 50 of file AudioSegmentSampleView.cpp.

51{
52 return mLength;
53}

References mLength.

Member Data Documentation

◆ mBlockViews

const std::vector<BlockSampleView> AudioSegmentSampleView::mBlockViews
private

Definition at line 67 of file AudioSegmentSampleView.h.

Referenced by AudioSegmentSampleView(), and DoAdd().

◆ mIsSilent

const bool AudioSegmentSampleView::mIsSilent
private

Definition at line 70 of file AudioSegmentSampleView.h.

Referenced by AddTo(), and Copy().

◆ mLength

const size_t AudioSegmentSampleView::mLength
private

Definition at line 69 of file AudioSegmentSampleView.h.

Referenced by DoAdd(), and GetSampleCount().

◆ mStart

const size_t AudioSegmentSampleView::mStart = 0
private

Definition at line 68 of file AudioSegmentSampleView.h.

Referenced by DoAdd().


The documentation for this class was generated from the following files: