Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
DynamicRangeProcessorHistory Class Referencefinal

#include <DynamicRangeProcessorHistory.h>

Collaboration diagram for DynamicRangeProcessorHistory:
[legend]

Classes

struct  Packet
 

Public Types

using Segment = std::vector< Packet >
 

Public Member Functions

 DynamicRangeProcessorHistory (double sampleRate)
 
void Push (const std::vector< DynamicRangeProcessorOutputPacket > &packets)
 
void BeginNewSegment ()
 
const std::vector< Segment > & GetSegments () const
 
bool IsEmpty () const
 

Static Public Attributes

static constexpr auto maxTimeSeconds = 2.5f
 

Private Member Functions

float GetPacketTime (const DynamicRangeProcessorOutputPacket &packet) const
 

Private Attributes

const double mSampleRate
 
bool mBeginNewSegment = true
 
std::vector< SegmentmSegments
 
std::optional< long long > mFirstPacketFirstSampleIndex
 
std::optional< long long > mExpectedNextPacketFirstSampleIndex
 

Detailed Description


Audacity: A Digital Audio Editor

DynamicRangeProcessorHistory.h

Matthieu Hodgkinson

Definition at line 18 of file DynamicRangeProcessorHistory.h.

Member Typedef Documentation

◆ Segment

Definition at line 34 of file DynamicRangeProcessorHistory.h.

Constructor & Destructor Documentation

◆ DynamicRangeProcessorHistory()

DynamicRangeProcessorHistory::DynamicRangeProcessorHistory ( double  sampleRate)

Audacity: A Digital Audio Editor

DynamicRangeProcessorHistory.cpp

Matthieu Hodgkinson

Definition at line 17 of file DynamicRangeProcessorHistory.cpp.

Member Function Documentation

◆ BeginNewSegment()

void DynamicRangeProcessorHistory::BeginNewSegment ( )

Definition at line 86 of file DynamicRangeProcessorHistory.cpp.

References mBeginNewSegment.

◆ GetPacketTime()

float DynamicRangeProcessorHistory::GetPacketTime ( const DynamicRangeProcessorOutputPacket packet) const
private

◆ GetSegments()

const std::vector< DynamicRangeProcessorHistory::Segment > & DynamicRangeProcessorHistory::GetSegments ( ) const

Definition at line 92 of file DynamicRangeProcessorHistory.cpp.

93{
94 return mSegments;
95}

References mSegments.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ IsEmpty()

bool DynamicRangeProcessorHistory::IsEmpty ( ) const

Definition at line 97 of file DynamicRangeProcessorHistory.cpp.

98{
99 return std::all_of(
100 mSegments.begin(), mSegments.end(),
101 [](const auto& segment) { return segment.empty(); });
102}

References mSegments.

◆ Push()

void DynamicRangeProcessorHistory::Push ( const std::vector< DynamicRangeProcessorOutputPacket > &  packets)

Definition at line 22 of file DynamicRangeProcessorHistory.cpp.

24{
25 if (packets.empty())
26 return;
27
28 if (!mFirstPacketFirstSampleIndex.has_value())
29 mFirstPacketFirstSampleIndex = packets.front().indexOfFirstSample;
30
31 const int numNewPackets = packets.size();
32 const auto lastPacketTime = !mSegments.empty() && !mSegments[0].empty() ?
33 std::make_optional(mSegments[0].back().time) :
34 std::nullopt;
35
36 const auto firstPacketToInsertIt =
37 std::find_if(packets.begin(), packets.end(), [&](const auto& packet) {
38 return !lastPacketTime.has_value() ||
39 GetPacketTime(packet) > *lastPacketTime;
40 });
41
42 if (firstPacketToInsertIt == packets.end())
43 return;
44
45 // Some packets can go lost in the transmission from audio to main thread.
46 const auto isContinuous = mExpectedNextPacketFirstSampleIndex.has_value() &&
47 firstPacketToInsertIt->indexOfFirstSample ==
49 if (mSegments.empty() || mBeginNewSegment || !isContinuous)
50 {
51 mSegments.emplace_back();
52 mBeginNewSegment = false;
53 }
55 packets.back().indexOfFirstSample + packets.back().numSamples;
56
57 auto& lastSegment = mSegments.back();
58
59 std::transform(
60 firstPacketToInsertIt, packets.end(), std::back_inserter(lastSegment),
61 [&](const auto& packet) -> Packet {
62 const auto t = GetPacketTime(packet);
63 return { t, packet.targetCompressionDb, packet.actualCompressionDb,
64 packet.inputDb, packet.outputDb };
65 });
66
67 // Clean up older packets.
68 // Algorithmically it's not completely correct to only do this for the oldest
69 // segment, but in practice, `Push` is called much more often than
70 // `BeginNewSegment`, so a simpler implementation is sufficient.
71 const auto lastTime = lastSegment.back().time;
72 auto& firstSegment = mSegments.front();
73 const auto it = std::find_if(
74 firstSegment.begin(), firstSegment.end(),
75 [lastTime](const Packet& packet) {
76 // Extend a little bit the time window, to avoid the extremities of a
77 // display to tremble.
78 return lastTime - packet.time < maxTimeSeconds + 1.f;
79 });
80 firstSegment.erase(firstSegment.begin(), it);
81
82 if (firstSegment.empty())
83 mSegments.erase(mSegments.begin());
84}
std::optional< long long > mExpectedNextPacketFirstSampleIndex
STL namespace.

References mBeginNewSegment, mExpectedNextPacketFirstSampleIndex, mFirstPacketFirstSampleIndex, and mSegments.

Member Data Documentation

◆ maxTimeSeconds

constexpr auto DynamicRangeProcessorHistory::maxTimeSeconds = 2.5f
staticconstexpr

◆ mBeginNewSegment

bool DynamicRangeProcessorHistory::mBeginNewSegment = true
private

Definition at line 45 of file DynamicRangeProcessorHistory.h.

Referenced by BeginNewSegment(), and Push().

◆ mExpectedNextPacketFirstSampleIndex

std::optional<long long> DynamicRangeProcessorHistory::mExpectedNextPacketFirstSampleIndex
private

Definition at line 48 of file DynamicRangeProcessorHistory.h.

Referenced by Push().

◆ mFirstPacketFirstSampleIndex

std::optional<long long> DynamicRangeProcessorHistory::mFirstPacketFirstSampleIndex
private

Definition at line 47 of file DynamicRangeProcessorHistory.h.

Referenced by GetPacketTime(), and Push().

◆ mSampleRate

const double DynamicRangeProcessorHistory::mSampleRate
private

Definition at line 44 of file DynamicRangeProcessorHistory.h.

Referenced by GetPacketTime().

◆ mSegments

std::vector<Segment> DynamicRangeProcessorHistory::mSegments
private

Definition at line 46 of file DynamicRangeProcessorHistory.h.

Referenced by GetSegments(), IsEmpty(), and Push().


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