Audacity 3.2.0
Functions
anonymous_namespace{WaveTrackUtilities.cpp} Namespace Reference

Functions

bool ReverseOneClip (WaveTrack &track, sampleCount start, sampleCount len, sampleCount originalStart, sampleCount originalEnd, const WaveTrackUtilities::ProgressReport &report)
 

Function Documentation

◆ ReverseOneClip()

bool anonymous_namespace{WaveTrackUtilities.cpp}::ReverseOneClip ( WaveTrack track,
sampleCount  start,
sampleCount  len,
sampleCount  originalStart,
sampleCount  originalEnd,
const WaveTrackUtilities::ProgressReport report 
)

Definition at line 66 of file WaveTrackUtilities.cpp.

70{
71 bool rc = true;
72 // keep track of two blocks whose data we will swap
73 auto first = start;
74
75 auto blockSize = track.GetMaxBlockSize();
76 const auto width = track.NChannels();
77 Floats buffers0[2]{
78 Floats(blockSize), width > 1 ? Floats(blockSize) : Floats{} };
79 float *pointers0[2]{ buffers0[0].get(),
80 width > 1 ? buffers0[1].get() : nullptr };
81 Floats buffers1[2]{
82 Floats(blockSize), width > 1 ? Floats(blockSize) : Floats{} };
83 float *pointers1[2]{ buffers1[0].get(),
84 width > 1 ? buffers1[1].get() : nullptr };
85 constexpr auto reverseBuffers =
86 [](float *const (&pointers)[2], size_t size){
87 for (const auto pointer : pointers)
88 if (pointer)
89 std::reverse(pointer, pointer + size);
90 };
91
92 auto originalLen = originalEnd - originalStart;
93
94 while (len > 1) {
95 auto block =
96 limitSampleBufferSize(track.GetBestBlockSize(first), len / 2);
97 auto second = first + (len - block);
98
99 track.GetFloats(0, width, pointers0, first, block);
100 reverseBuffers(pointers0, block);
101 track.GetFloats(0, width, pointers1, second, block);
102 reverseBuffers(pointers1, block);
103 // Don't dither on later rendering if only reversing samples
104 const bool success =
105 track.SetFloats(pointers1, first, block, narrowestSampleFormat)
106 &&
107 track.SetFloats(pointers0, second, block, narrowestSampleFormat);
108 if (!success)
109 return false;
110
111 len -= 2 * block;
112 first += block;
113
114 if (!report(
115 2 * (first - originalStart).as_double() / originalLen.as_double()
116 )) {
117 rc = false;
118 break;
119 }
120 }
121
122 return rc;
123}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
constexpr sampleFormat narrowestSampleFormat
Definition: SampleFormat.h:46
ArrayOf< float > Floats
Definition: VampEffect.h:32
bool GetFloats(size_t iChannel, size_t nBuffers, float *const buffers[], sampleCount start, size_t len, bool backwards=false, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
bool SetFloats(const float *const *buffers, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Random-access assignment of a range of samples.
Definition: WaveTrack.cpp:3273
size_t NChannels() const override
A constant property.
Definition: WaveTrack.cpp:530
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:2279
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:2260
BuiltinEffectsModule::Registration< Reverse > reverse

References WaveTrack::GetBestBlockSize(), SampleTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), limitSampleBufferSize(), narrowestSampleFormat, WaveTrack::NChannels(), anonymous_namespace{RegisterBuiltinEffects.cpp}::reverse, WaveTrack::SetFloats(), and size.

Referenced by WaveTrackUtilities::Reverse().

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