1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00
audacity/src/SampleBlock.cpp
Paul Licameli 64c50e57da
Sample block cleanups (#657)
* Revert "[Bug 2533] New: Extreme space inefficiency importing silence from an AUP file"...

... It did not fix the symptoms.  Using a zero blob only gives temporary
in-memory space efficiency when adding a row to the database, not space savings
in the file.

This reverts commit d9047dfd254ecf92c0770c0cbda62a238c2fdd29.

* Remove unused SampleBlockFactory::Get

* Eliminate some repetition and magic numbers

* Lower some common steps into GetSummary(); removed unused argument

* mSummary256Bytes and mSummary64kBytes not needed after initialization

* Satisfy sample and summary requests for silent blocks without using db
2020-09-02 13:11:30 -05:00

108 lines
2.5 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
SampleBlock.cpp
**********************************************************************/
#include "Audacity.h"
#include "InconsistencyException.h"
#include "SampleBlock.h"
#include "SampleFormat.h"
#include <wx/defs.h>
static SampleBlockFactoryFactory& installedFactory()
{
static SampleBlockFactoryFactory theFactory;
return theFactory;
}
SampleBlockFactoryFactory SampleBlockFactory::RegisterFactoryFactory(
SampleBlockFactoryFactory newFactory )
{
auto &theFactory = installedFactory();
auto result = std::move( theFactory );
theFactory = std::move( newFactory );
return result;
}
SampleBlockFactoryPtr SampleBlockFactory::New( AudacityProject &project )
{
auto &factory = installedFactory();
if ( ! factory )
THROW_INCONSISTENCY_EXCEPTION;
return factory( project );
}
SampleBlockFactory::~SampleBlockFactory() = default;
SampleBlockPtr SampleBlockFactory::Create(samplePtr src,
size_t numsamples,
sampleFormat srcformat)
{
auto result = DoCreate(src, numsamples, srcformat);
if (!result)
THROW_INCONSISTENCY_EXCEPTION;
return result;
}
SampleBlockPtr SampleBlockFactory::CreateSilent(
size_t numsamples,
sampleFormat srcformat)
{
auto result = DoCreateSilent(numsamples, srcformat);
if (!result)
THROW_INCONSISTENCY_EXCEPTION;
return result;
}
SampleBlockPtr SampleBlockFactory::CreateFromXML(
sampleFormat srcformat,
const wxChar **attrs)
{
auto result = DoCreateFromXML(srcformat, attrs);
if (!result)
THROW_INCONSISTENCY_EXCEPTION;
return result;
}
SampleBlock::~SampleBlock() = default;
size_t SampleBlock::GetSamples(samplePtr dest,
sampleFormat destformat,
size_t sampleoffset,
size_t numsamples, bool mayThrow)
{
try{ return DoGetSamples(dest, destformat, sampleoffset, numsamples); }
catch( ... ) {
if( mayThrow )
throw;
ClearSamples( dest, destformat, 0, numsamples );
return 0;
}
}
MinMaxRMS SampleBlock::GetMinMaxRMS(
size_t start, size_t len, bool mayThrow)
{
try{ return DoGetMinMaxRMS(start, len); }
catch( ... ) {
if( mayThrow )
throw;
return {};
}
}
MinMaxRMS SampleBlock::GetMinMaxRMS(bool mayThrow) const
{
try{ return DoGetMinMaxRMS(); }
catch( ... ) {
if( mayThrow )
throw;
return {};
}
}