![]() |
Audacity 3.2.0
|
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interface to an array of SeqBlock instances, corresponding to the audio sample blocks in the database. Contrast with RingBuffer. More...
#include <Sequence.h>
Public Member Functions | |
Sequence (const SampleBlockFactoryPtr &pFactory, SampleFormats formats) | |
Sequence (const Sequence &orig, const SampleBlockFactoryPtr &pFactory) | |
Sequence (const Sequence &)=delete | |
Sequence & | operator= (const Sequence &) PROHIBITED |
~Sequence () | |
sampleCount | GetNumSamples () const |
bool | Get (samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow) const |
void | SetSamples (constSamplePtr buffer, sampleFormat format, sampleCount start, sampleCount len, sampleFormat effectiveFormat) |
Pass nullptr to set silence. More... | |
std::unique_ptr< Sequence > | Copy (const SampleBlockFactoryPtr &pFactory, sampleCount s0, sampleCount s1) const |
void | Paste (sampleCount s0, const Sequence *src) |
size_t | GetIdealAppendLen () const |
bool | Append (constSamplePtr buffer, sampleFormat format, size_t len, size_t stride, sampleFormat effectiveFormat) |
void | Flush () |
SeqBlock::SampleBlockPtr | AppendNewBlock (constSamplePtr buffer, sampleFormat format, size_t len) |
void | AppendSharedBlock (const SeqBlock::SampleBlockPtr &pBlock) |
Append a complete block, not coalescing. More... | |
void | Delete (sampleCount start, sampleCount len) |
void | SetSilence (sampleCount s0, sampleCount len) |
void | InsertSilence (sampleCount s0, sampleCount len) |
const SampleBlockFactoryPtr & | GetFactory () |
bool | HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override |
void | HandleXMLEndTag (const std::string_view &tag) override |
XMLTagHandler * | HandleXMLChild (const std::string_view &tag) override |
void | WriteXML (XMLWriter &xmlFile) const |
bool | GetErrorOpening () |
bool | CloseLock () |
SampleFormats | GetSampleFormats () const |
bool | ConvertToSampleFormat (sampleFormat format, const std::function< void(size_t)> &progressReport={}) |
std::pair< float, float > | GetMinMax (sampleCount start, sampleCount len, bool mayThrow) const |
float | GetRMS (sampleCount start, sampleCount len, bool mayThrow) const |
sampleCount | GetBlockStart (sampleCount position) const |
size_t | GetBestBlockSize (sampleCount start) const |
size_t | GetMaxBlockSize () const |
size_t | GetIdealBlockSize () const |
BlockArray & | GetBlockArray () |
const BlockArray & | GetBlockArray () const |
size_t | GetAppendBufferLen () const |
constSamplePtr | GetAppendBuffer () const |
int | FindBlock (sampleCount pos) const |
void | ConsistencyCheck (const wxChar *whereStr, bool mayThrow=true) const |
![]() | |
XMLTagHandler () | |
virtual | ~XMLTagHandler () |
virtual bool | HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0 |
virtual void | HandleXMLEndTag (const std::string_view &WXUNUSED(tag)) |
virtual void | HandleXMLContent (const std::string_view &WXUNUSED(content)) |
virtual XMLTagHandler * | HandleXMLChild (const std::string_view &tag)=0 |
void | ReadXMLEndTag (const char *tag) |
void | ReadXMLContent (const char *s, int len) |
XMLTagHandler * | ReadXMLChild (const char *tag) |
Static Public Member Functions | |
static void | SetMaxDiskBlockSize (size_t bytes) |
static size_t | GetMaxDiskBlockSize () |
static bool | IsValidSampleFormat (const int nValue) |
true if nValue is one of the sampleFormat enum values More... | |
static bool | Read (samplePtr buffer, sampleFormat format, const SeqBlock &b, size_t blockRelativeStart, size_t len, bool mayThrow) |
static void | DebugPrintf (const BlockArray &block, sampleCount numSamples, wxString *dest) |
Private Member Functions | |
SeqBlock::SampleBlockPtr | DoAppend (constSamplePtr buffer, sampleFormat format, size_t len, bool coalesce) |
Does not do any dithering. More... | |
bool | Get (int b, samplePtr buffer, sampleFormat format, sampleCount start, size_t len, bool mayThrow) const |
void | CommitChangesIfConsistent (BlockArray &newBlock, sampleCount numSamples, const wxChar *whereStr) |
void | AppendBlocksIfConsistent (BlockArray &additionalBlocks, bool replaceLast, sampleCount numSamples, const wxChar *whereStr) |
Static Private Member Functions | |
static void | AppendBlock (SampleBlockFactory *pFactory, sampleFormat format, BlockArray &blocks, sampleCount &numSamples, const SeqBlock &b) |
static void | Blockify (SampleBlockFactory &factory, size_t maxSamples, sampleFormat format, BlockArray &list, sampleCount start, constSamplePtr buffer, size_t len) |
static void | ConsistencyCheck (const BlockArray &block, size_t maxSamples, size_t from, sampleCount numSamples, const wxChar *whereStr, bool mayThrow=true) |
Private Attributes | |
SampleBlockFactoryPtr | mpFactory |
BlockArray | mBlock |
SampleFormats | mSampleFormats |
sampleCount | mNumSamples { 0 } |
size_t | mMinSamples |
size_t | mMaxSamples |
SampleBuffer | mAppendBuffer {} |
size_t | mAppendBufferLen { 0 } |
sampleFormat | mAppendEffectiveFormat { narrowestSampleFormat } |
bool | mErrorOpening { false } |
Static Private Attributes | |
static size_t | sMaxDiskBlockSize = 1048576 |
A WaveTrack contains WaveClip(s). A WaveClip contains a Sequence. A Sequence is primarily an interface to an array of SeqBlock instances, corresponding to the audio sample blocks in the database. Contrast with RingBuffer.
Definition at line 61 of file Sequence.h.
Sequence::Sequence | ( | const SampleBlockFactoryPtr & | pFactory, |
SampleFormats | formats | ||
) |
Definition at line 51 of file Sequence.cpp.
Sequence::Sequence | ( | const Sequence & | orig, |
const SampleBlockFactoryPtr & | pFactory | ||
) |
Definition at line 63 of file Sequence.cpp.
References Paste().
|
delete |
Sequence::~Sequence | ( | ) |
Definition at line 73 of file Sequence.cpp.
bool Sequence::Append | ( | constSamplePtr | buffer, |
sampleFormat | format, | ||
size_t | len, | ||
size_t | stride, | ||
sampleFormat | effectiveFormat | ||
) |
Samples may be retained in a memory buffer, pending Flush() If there are exceptions, an unspecified prefix of buffer may be appended
effectiveFormat | Make the effective format of the data at least the minumum of this value and `format`. (Maybe wider, if merging with preexistent data.) If the data are later narrowed from stored format, but not narrower than the effective, then no dithering will occur. |
Definition at line 1321 of file Sequence.cpp.
References SampleBuffer::Allocate(), CopySamples(), DoAppend(), format, GetIdealAppendLen(), gHighQualityDither, mAppendBuffer, mAppendBufferLen, mAppendEffectiveFormat, min(), mMaxSamples, mSampleFormats, none, SampleBuffer::ptr(), SAMPLE_SIZE, SampleFormats::Stored(), and SampleFormats::UpdateEffective().
|
staticprivate |
Definition at line 757 of file Sequence.cpp.
References sampleCount::as_double(), format, mBlock, mNumSamples, anonymous_namespace{Sequence.cpp}::Overflows(), SeqBlock::sb, anonymous_namespace{Sequence.cpp}::ShareOrCopySampleBlock(), and THROW_INCONSISTENCY_EXCEPTION.
Referenced by Copy(), and Paste().
|
private |
Definition at line 1767 of file Sequence.cpp.
References ConsistencyCheck(), mBlock, mMaxSamples, and mNumSamples.
Referenced by AppendSharedBlock(), and DoAppend().
SeqBlock::SampleBlockPtr Sequence::AppendNewBlock | ( | constSamplePtr | buffer, |
sampleFormat | format, | ||
size_t | len | ||
) |
Append data, not coalescing blocks, returning a pointer to the new block. No dithering applied.
Definition at line 1286 of file Sequence.cpp.
References DoAppend(), format, mSampleFormats, and SampleFormats::UpdateEffective().
void Sequence::AppendSharedBlock | ( | const SeqBlock::SampleBlockPtr & | pBlock | ) |
Append a complete block, not coalescing.
Definition at line 1297 of file Sequence.cpp.
References AppendBlocksIfConsistent(), sampleCount::as_double(), ConsistencyCheck(), mNumSamples, anonymous_namespace{Sequence.cpp}::Overflows(), THROW_INCONSISTENCY_EXCEPTION, and wxT().
|
staticprivate |
Definition at line 1498 of file Sequence.cpp.
References cloud::factory, mMaxSamples, SAMPLE_SIZE, SeqBlock::sb, and SeqBlock::start.
Referenced by ConvertToSampleFormat(), Delete(), and Paste().
bool Sequence::CloseLock | ( | ) |
Definition at line 87 of file Sequence.cpp.
References mBlock.
Referenced by WaveClip::CloseLock().
|
private |
Definition at line 1755 of file Sequence.cpp.
References ConsistencyCheck(), mBlock, mMaxSamples, and mNumSamples.
Referenced by ConvertToSampleFormat(), Delete(), Paste(), and SetSamples().
|
staticprivate |
void Sequence::ConsistencyCheck | ( | const wxChar * | whereStr, |
bool | mayThrow = true |
||
) | const |
Definition at line 1699 of file Sequence.cpp.
References ConsistencyCheck(), mBlock, mMaxSamples, and mNumSamples.
Referenced by AppendBlocksIfConsistent(), AppendSharedBlock(), CommitChangesIfConsistent(), ConsistencyCheck(), Delete(), DoAppend(), and Paste().
bool Sequence::ConvertToSampleFormat | ( | sampleFormat | format, |
const std::function< void(size_t)> & | progressReport = {} |
||
) |
Definition at line 137 of file Sequence.cpp.
References Blockify(), CommitChangesIfConsistent(), CopySamples(), SampleFormats::Effective(), anonymous_namespace{Sequence.cpp}::ensureSampleBufferSize(), format, gHighQualityDither, mBlock, mMaxSamples, mMinSamples, mNumSamples, mpFactory, mSampleFormats, narrowestSampleFormat, none, SampleBuffer::ptr(), Read(), SAMPLE_SIZE, SeqBlock::sb, sMaxDiskBlockSize, SeqBlock::start, SampleFormats::Stored(), and wxT().
Referenced by AUPImportFileHandle::HandleSequence().
std::unique_ptr< Sequence > Sequence::Copy | ( | const SampleBlockFactoryPtr & | pFactory, |
sampleCount | s0, | ||
sampleCount | s1 | ||
) | const |
Definition at line 389 of file Sequence.cpp.
References AppendBlock(), SampleFormats::Effective(), anonymous_namespace{Sequence.cpp}::ensureSampleBufferSize(), FindBlock(), format, Get(), mBlock, min(), mMaxSamples, mNumSamples, mpFactory, mSampleFormats, SampleBuffer::ptr(), SeqBlock::sb, SeqBlock::start, SampleFormats::Stored(), and wxT().
|
static |
Definition at line 1810 of file Sequence.cpp.
References sampleCount::as_long_long(), mBlock, mNumSamples, SeqBlock::sb, SeqBlock::start, and wxT().
void Sequence::Delete | ( | sampleCount | start, |
sampleCount | len | ||
) |
Definition at line 1524 of file Sequence.cpp.
References SampleBuffer::Allocate(), Blockify(), CommitChangesIfConsistent(), ConsistencyCheck(), anonymous_namespace{Sequence.cpp}::ensureSampleBufferSize(), cloud::factory, FindBlock(), format, limitSampleBufferSize(), mBlock, mMaxSamples, mMinSamples, mNumSamples, mpFactory, mSampleFormats, SampleBuffer::ptr(), Read(), SAMPLE_SIZE, SeqBlock::sb, SeqBlock::start, SampleFormats::Stored(), THROW_INCONSISTENCY_EXCEPTION, and wxT().
Referenced by WaveClip::ClearAndAddCutLine(), and WaveClip::ClearSequence().
|
private |
Does not do any dithering.
Definition at line 1376 of file Sequence.cpp.
References AppendBlocksIfConsistent(), sampleCount::as_double(), ConsistencyCheck(), CopySamples(), cloud::factory, format, GetIdealBlockSize(), mBlock, min(), mMaxSamples, mMinSamples, mNumSamples, mpFactory, mSampleFormats, none, anonymous_namespace{Sequence.cpp}::Overflows(), SampleBuffer::ptr(), Read(), SAMPLE_SIZE, SeqBlock::sb, SeqBlock::start, SampleFormats::Stored(), THROW_INCONSISTENCY_EXCEPTION, and wxT().
Referenced by Append(), AppendNewBlock(), and Flush().
int Sequence::FindBlock | ( | sampleCount | pos | ) | const |
Definition at line 1041 of file Sequence.cpp.
References mBlock, min(), mNumSamples, SeqBlock::sb, and SeqBlock::start.
Referenced by Copy(), Delete(), Get(), GetBestBlockSize(), GetBlockStart(), GetMinMax(), GetRMS(), GetWaveDisplay(), Paste(), and SetSamples().
void Sequence::Flush | ( | ) |
Definition at line 1476 of file Sequence.cpp.
References DoAppend(), SampleBuffer::Free(), mAppendBuffer, mAppendBufferLen, mAppendEffectiveFormat, mSampleFormats, narrowestSampleFormat, SampleBuffer::ptr(), SampleFormats::Stored(), and SampleFormats::UpdateEffective().
|
private |
Definition at line 1130 of file Sequence.cpp.
References format, mBlock, min(), Read(), SAMPLE_SIZE, SeqBlock::sb, and SeqBlock::start.
bool Sequence::Get | ( | samplePtr | buffer, |
sampleFormat | format, | ||
sampleCount | start, | ||
size_t | len, | ||
bool | mayThrow | ||
) | const |
Definition at line 1112 of file Sequence.cpp.
References ClearSamples(), FindBlock(), floatSample, format, Get(), mNumSamples, and THROW_INCONSISTENCY_EXCEPTION.
Referenced by Copy(), Get(), and Paste().
|
inline |
Definition at line 221 of file Sequence.h.
Referenced by WaveClip::GetAppendBuffer().
|
inline |
Definition at line 220 of file Sequence.h.
Referenced by WaveClip::GetAppendBufferLen().
size_t Sequence::GetBestBlockSize | ( | sampleCount | start | ) | const |
Definition at line 782 of file Sequence.cpp.
References FindBlock(), mBlock, mMaxSamples, mMinSamples, mNumSamples, SeqBlock::sb, and SeqBlock::start.
|
inline |
Definition at line 217 of file Sequence.h.
Referenced by GetAllSeqBlocks(), and GetWaveDisplay().
|
inline |
Definition at line 218 of file Sequence.h.
sampleCount Sequence::GetBlockStart | ( | sampleCount | position | ) | const |
Definition at line 776 of file Sequence.cpp.
References FindBlock(), and mBlock.
|
inline |
Definition at line 172 of file Sequence.h.
|
inline |
Definition at line 161 of file Sequence.h.
size_t Sequence::GetIdealAppendLen | ( | ) | const |
Definition at line 1270 of file Sequence.cpp.
References GetMaxBlockSize(), and mBlock.
Referenced by Append().
size_t Sequence::GetIdealBlockSize | ( | ) | const |
Definition at line 82 of file Sequence.cpp.
References mMaxSamples.
Referenced by DoAppend(), WaveTrack::GetIdealBlockSize(), and InsertSilence().
size_t Sequence::GetMaxBlockSize | ( | ) | const |
Definition at line 77 of file Sequence.cpp.
References mMaxSamples.
Referenced by GetIdealAppendLen(), and GetWaveDisplay().
|
static |
Definition at line 1845 of file Sequence.cpp.
References sMaxDiskBlockSize.
Referenced by BenchmarkDialog::OnRun().
std::pair< float, float > Sequence::GetMinMax | ( | sampleCount | start, |
sampleCount | len, | ||
bool | mayThrow | ||
) | const |
Definition at line 238 of file Sequence.cpp.
References FindBlock(), limitSampleBufferSize(), mBlock, min(), mMaxSamples, SeqBlock::sb, and SeqBlock::start.
|
inline |
Definition at line 91 of file Sequence.h.
Referenced by GetWaveDisplay(), and WaveClipWaveformCache::GetWaveDisplay().
float Sequence::GetRMS | ( | sampleCount | start, |
sampleCount | len, | ||
bool | mayThrow | ||
) | const |
Definition at line 320 of file Sequence.cpp.
References sampleCount::as_double(), FindBlock(), limitSampleBufferSize(), mBlock, mMaxSamples, SeqBlock::sb, and SeqBlock::start.
SampleFormats Sequence::GetSampleFormats | ( | ) | const |
Definition at line 95 of file Sequence.cpp.
References mSampleFormats.
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 979 of file Sequence.cpp.
|
override |
Definition at line 937 of file Sequence.cpp.
References sampleCount::as_double(), mBlock, mErrorOpening, mNumSamples, SeqBlock::sb, SeqBlock::start, Internat::ToString(), and wxT().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 811 of file Sequence.cpp.
References SampleFormats::Effective(), cloud::factory, floatSample, IsValidSampleFormat(), mBlock, mErrorOpening, mMaxSamples, mNumSamples, mpFactory, mSampleFormats, SeqBlock::sb, SeqBlock::start, and SampleFormats::Stored().
void Sequence::InsertSilence | ( | sampleCount | s0, |
sampleCount | len | ||
) |
Definition at line 707 of file Sequence.cpp.
References sampleCount::as_double(), sampleCount::as_size_t(), cloud::factory, format, GetIdealBlockSize(), mNumSamples, mpFactory, mSampleFormats, anonymous_namespace{Sequence.cpp}::Overflows(), Paste(), SampleFormats::Stored(), and THROW_INCONSISTENCY_EXCEPTION.
Referenced by WaveClip::InsertSilence().
|
static |
true if nValue is one of the sampleFormat enum values
Definition at line 1850 of file Sequence.cpp.
References floatSample, int16Sample, and int24Sample.
Referenced by AUPImportFileHandle::HandleSequence(), HandleXMLTag(), and WaveTrack::HandleXMLTag().
void Sequence::Paste | ( | sampleCount | s, |
const Sequence * | src | ||
) |
Definition at line 494 of file Sequence.cpp.
References AppendBlock(), sampleCount::as_double(), Blockify(), CommitChangesIfConsistent(), ConsistencyCheck(), TranslatableString::Debug(), SampleFormats::Effective(), FindBlock(), format, Get(), GetSampleFormatStr(), mBlock, mMaxSamples, mMinSamples, mNumSamples, mpFactory, mSampleFormats, anonymous_namespace{Sequence.cpp}::Overflows(), SampleBuffer::ptr(), Read(), SAMPLE_SIZE, SeqBlock::sb, anonymous_namespace{Sequence.cpp}::ShareOrCopySampleBlock(), SeqBlock::start, SampleFormats::Stored(), THROW_INCONSISTENCY_EXCEPTION, Internat::ToString(), SampleFormats::UpdateEffective(), and wxT().
Referenced by InsertSilence(), and Sequence().
|
static |
Definition at line 1091 of file Sequence.cpp.
References format, SeqBlock::sb, and wxT().
Referenced by ConvertToSampleFormat(), Delete(), DoAppend(), Get(), GetWaveDisplay(), Paste(), and SetSamples().
|
static |
Definition at line 1840 of file Sequence.cpp.
References sMaxDiskBlockSize.
Referenced by AudacityApp::InitPart2(), and BenchmarkDialog::OnRun().
void Sequence::SetSamples | ( | constSamplePtr | buffer, |
sampleFormat | format, | ||
sampleCount | start, | ||
sampleCount | len, | ||
sampleFormat | effectiveFormat | ||
) |
Pass nullptr to set silence.
Note that len is not size_t, because nullptr may be passed for buffer, in which case, silence is inserted, possibly a large amount.
effectiveFormat | Make the effective format of the data at least the minumum of this value and `format`. (Maybe wider, if merging with preexistent data.) If the data are later narrowed from stored format, but not narrower than the effective, then no dithering will occur. |
Definition at line 1154 of file Sequence.cpp.
References SampleBuffer::Allocate(), ClearSamples(), CommitChangesIfConsistent(), CopySamples(), anonymous_namespace{Sequence.cpp}::ensureSampleBufferSize(), cloud::factory, FindBlock(), format, gHighQualityDither, limitSampleBufferSize(), mBlock, min(), mMaxSamples, mNumSamples, mpFactory, mSampleFormats, none, SampleBuffer::ptr(), Read(), SAMPLE_SIZE, SeqBlock::sb, size, SeqBlock::start, SampleFormats::Stored(), THROW_INCONSISTENCY_EXCEPTION, SampleFormats::UpdateEffective(), and wxT().
Referenced by SetSilence().
void Sequence::SetSilence | ( | sampleCount | s0, |
sampleCount | len | ||
) |
Definition at line 700 of file Sequence.cpp.
References mSampleFormats, narrowestSampleFormat, SetSamples(), and SampleFormats::Stored().
Referenced by WaveClip::SetSilence().
void Sequence::WriteXML | ( | XMLWriter & | xmlFile | ) | const |
Definition at line 990 of file Sequence.cpp.
References sampleCount::as_long_long(), BasicUI::MessageBoxOptions::Caption(), SeqBlock::sb, BasicUI::ShowMessageBox(), SeqBlock::start, Internat::ToString(), wxT(), and XO().
|
private |
Definition at line 246 of file Sequence.h.
|
private |
Definition at line 247 of file Sequence.h.
|
private |
Definition at line 248 of file Sequence.h.
|
private |
Definition at line 237 of file Sequence.h.
Referenced by AppendBlock(), AppendBlocksIfConsistent(), CloseLock(), CommitChangesIfConsistent(), ConsistencyCheck(), ConvertToSampleFormat(), Copy(), DebugPrintf(), Delete(), DoAppend(), FindBlock(), Get(), GetBestBlockSize(), GetBlockStart(), GetIdealAppendLen(), GetMinMax(), GetRMS(), HandleXMLEndTag(), HandleXMLTag(), Paste(), and SetSamples().
|
private |
Definition at line 250 of file Sequence.h.
Referenced by HandleXMLEndTag(), and HandleXMLTag().
|
private |
Definition at line 244 of file Sequence.h.
Referenced by Append(), AppendBlocksIfConsistent(), Blockify(), CommitChangesIfConsistent(), ConsistencyCheck(), ConvertToSampleFormat(), Copy(), Delete(), DoAppend(), GetBestBlockSize(), GetIdealBlockSize(), GetMaxBlockSize(), GetMinMax(), GetRMS(), HandleXMLTag(), Paste(), and SetSamples().
|
private |
Definition at line 243 of file Sequence.h.
Referenced by ConvertToSampleFormat(), Delete(), DoAppend(), GetBestBlockSize(), and Paste().
|
private |
Definition at line 241 of file Sequence.h.
Referenced by AppendBlock(), AppendBlocksIfConsistent(), AppendSharedBlock(), CommitChangesIfConsistent(), ConsistencyCheck(), ConvertToSampleFormat(), Copy(), DebugPrintf(), Delete(), DoAppend(), FindBlock(), Get(), GetBestBlockSize(), HandleXMLEndTag(), HandleXMLTag(), InsertSilence(), Paste(), and SetSamples().
|
private |
Definition at line 235 of file Sequence.h.
Referenced by ConvertToSampleFormat(), Copy(), Delete(), DoAppend(), HandleXMLTag(), InsertSilence(), Paste(), and SetSamples().
|
private |
Definition at line 238 of file Sequence.h.
Referenced by Append(), AppendNewBlock(), ConvertToSampleFormat(), Copy(), Delete(), DoAppend(), Flush(), GetSampleFormats(), HandleXMLTag(), InsertSilence(), Paste(), SetSamples(), and SetSilence().
|
staticprivate |
Definition at line 229 of file Sequence.h.
Referenced by ConvertToSampleFormat(), GetMaxDiskBlockSize(), and SetMaxDiskBlockSize().