mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 16:19:43 +02:00
Define sampleCount as a class, not a type alias...
... Define lots of operators for disambiguation, but they will go away after all conversions from sampleCount to built-in numerical types are forced to be explicit.
This commit is contained in:
parent
fbfee42a00
commit
26b5e77050
@ -55,11 +55,252 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// A native 64-bit integer...used when referring to any number of samples
|
||||
// ----------------------------------------------------------------------------
|
||||
#if (defined(__VISUALC__) && defined(__WIN32__))
|
||||
typedef __int64 sampleCount;
|
||||
#else
|
||||
typedef long long sampleCount;
|
||||
#endif
|
||||
|
||||
class sampleCount
|
||||
{
|
||||
public:
|
||||
using type = long long;
|
||||
static_assert(sizeof(type) == 8, "Wrong width of sampleCount");
|
||||
|
||||
sampleCount () : value { 0 } {}
|
||||
sampleCount ( type v ) : value { v } {}
|
||||
sampleCount ( const sampleCount& ) = default;
|
||||
sampleCount &operator= ( const sampleCount& ) = default;
|
||||
|
||||
operator type () const { return value; }
|
||||
|
||||
sampleCount &operator += (sampleCount b) { value += b.value; return *this; }
|
||||
sampleCount &operator -= (sampleCount b) { value -= b.value; return *this; }
|
||||
sampleCount &operator *= (sampleCount b) { value *= b.value; return *this; }
|
||||
sampleCount &operator /= (sampleCount b) { value /= b.value; return *this; }
|
||||
sampleCount &operator %= (sampleCount b) { value %= b.value; return *this; }
|
||||
|
||||
sampleCount &operator ++ () { ++value; return *this; }
|
||||
sampleCount operator ++ (int)
|
||||
{ sampleCount result{ *this }; ++value; return result; }
|
||||
|
||||
sampleCount &operator -- () { --value; return *this; }
|
||||
sampleCount operator -- (int)
|
||||
{ sampleCount result{ *this }; --value; return result; }
|
||||
|
||||
private:
|
||||
type value;
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
inline sampleCount min (sampleCount a, sampleCount b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
inline sampleCount max (sampleCount a, sampleCount b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
sampleCount operator + (sampleCount a, sampleCount b)
|
||||
{ return (long long)a + (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (sampleCount a, size_t b)
|
||||
{ return (long long)a + b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (size_t a, sampleCount b)
|
||||
{ return a + (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (sampleCount a, int b)
|
||||
{ return (long long)a + b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (int a, sampleCount b)
|
||||
{ return a + (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (sampleCount a, long b)
|
||||
{ return (long long)a + b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (long a, sampleCount b)
|
||||
{ return a + (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (sampleCount a, long long b)
|
||||
{ return (long long)a + b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (long long a, sampleCount b)
|
||||
{ return a + (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (sampleCount a, unsigned b)
|
||||
{ return (long long)a + b; }
|
||||
|
||||
inline
|
||||
sampleCount operator + (unsigned a, sampleCount b)
|
||||
{ return a + (long long)b; }
|
||||
|
||||
|
||||
|
||||
|
||||
inline
|
||||
sampleCount operator - (sampleCount a, sampleCount b)
|
||||
{ return (long long)a - (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (sampleCount a, size_t b)
|
||||
{ return (long long)a - b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (size_t a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (sampleCount a, int b)
|
||||
{ return(long long) a - b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (int a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (sampleCount a, long b)
|
||||
{ return (long long)a - b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (long a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (sampleCount a, long long b)
|
||||
{ return (long long)a - b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (long long a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (sampleCount a, unsigned b)
|
||||
{ return (long long)a - b; }
|
||||
|
||||
inline
|
||||
sampleCount operator - (unsigned a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
|
||||
|
||||
inline
|
||||
sampleCount operator * (sampleCount a, sampleCount b)
|
||||
{ return (long long)a * (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (sampleCount a, int b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (int a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (sampleCount a, unsigned b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (unsigned a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (sampleCount a, long b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (long a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (sampleCount a, unsigned long b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (unsigned long a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (sampleCount a, long long b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
inline
|
||||
sampleCount operator * (long long a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
|
||||
|
||||
inline
|
||||
sampleCount operator / (sampleCount a, sampleCount b)
|
||||
{ return (long long)a / (long long)b; }
|
||||
|
||||
inline
|
||||
sampleCount operator / (sampleCount a, int b)
|
||||
{ return (long long)a / b; }
|
||||
|
||||
inline
|
||||
sampleCount operator / (sampleCount a, size_t b)
|
||||
{ return (long long)a / b; }
|
||||
|
||||
inline
|
||||
double operator / (sampleCount a, double b)
|
||||
{ return (long long)a / b; }
|
||||
|
||||
inline
|
||||
float operator / (float a, sampleCount b)
|
||||
{ return a / (long long)b; }
|
||||
|
||||
inline
|
||||
double operator / (double a, sampleCount b)
|
||||
{ return a / (long long)b; }
|
||||
|
||||
|
||||
|
||||
inline
|
||||
double operator + (sampleCount a, double b)
|
||||
{ return (long long)a + b; }
|
||||
|
||||
inline
|
||||
double operator + (double a, sampleCount b)
|
||||
{ return a + (long long)b; }
|
||||
|
||||
inline
|
||||
double operator - (sampleCount a, double b)
|
||||
{ return (long long)a - b; }
|
||||
|
||||
inline
|
||||
double operator - (double a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
inline
|
||||
double operator * (sampleCount a, double b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
inline
|
||||
double operator * (double a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
|
||||
inline
|
||||
float operator - (float a, sampleCount b)
|
||||
{ return a - (long long)b; }
|
||||
|
||||
inline
|
||||
float operator * (float a, sampleCount b)
|
||||
{ return a * (long long)b; }
|
||||
|
||||
inline
|
||||
float operator * (sampleCount a, float b)
|
||||
{ return (long long)a * b; }
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Function returning the minimum of a sampleCount and a size_t,
|
||||
|
@ -448,7 +448,7 @@ struct AudioIO::ScrubQueue
|
||||
auto actualDuration = origDuration;
|
||||
const sampleCount s1 = options.enqueueBySpeed
|
||||
? s0 + lrint(origDuration * end) // end is a speed
|
||||
: lrint(end * mRate); // end is a time
|
||||
: sampleCount(lrint(end * mRate)); // end is a time
|
||||
auto success =
|
||||
current->Init(previous, s0, s1, actualDuration, options);
|
||||
if (success)
|
||||
|
@ -143,7 +143,7 @@ void FindDependencies(AudacityProject *project,
|
||||
outAliasedFiles.back() =
|
||||
AliasedFile {
|
||||
wxFileNameWrapper { fileName },
|
||||
blockBytes, fileName.FileExists()
|
||||
wxLongLong(blockBytes), fileName.FileExists()
|
||||
};
|
||||
aliasedFileHash[fileNameStr] = &outAliasedFiles.back();
|
||||
}
|
||||
|
@ -1094,7 +1094,8 @@ bool Sequence::Read(samplePtr buffer, sampleFormat format,
|
||||
|
||||
if (result != len)
|
||||
{
|
||||
wxLogWarning(wxT("Expected to read %ld samples, got %d samples."), len, result);
|
||||
wxLogWarning(wxT("Expected to read %ld samples, got %d samples."),
|
||||
(long long)len, result);
|
||||
if (result < 0)
|
||||
result = 0;
|
||||
ClearSamples(buffer, format, result, len-result);
|
||||
|
@ -23,12 +23,6 @@
|
||||
|
||||
#include "audacity/Types.h"
|
||||
|
||||
#if 0
|
||||
// Moved to "audacity/types.h"
|
||||
typedef wxLongLong_t sampleCount; /** < A native 64-bit integer type, because
|
||||
32-bit integers may not be enough */
|
||||
#endif
|
||||
|
||||
class BlockFile;
|
||||
using BlockFilePtr = std::shared_ptr<BlockFile>;
|
||||
|
||||
|
@ -447,7 +447,7 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
|
||||
wxASSERT(mInfo.channels >= 0);
|
||||
while (NULL == srcbuffer.Allocate(maxBlock * mInfo.channels, mFormat).ptr())
|
||||
{
|
||||
maxBlock >>= 1;
|
||||
maxBlock /= 2;
|
||||
if (maxBlock < 1)
|
||||
return eProgressFailed;
|
||||
}
|
||||
|
@ -517,10 +517,10 @@ int ODFFmpegDecoder::FillDataFromCache(samplePtr & data, sampleFormat outFormat,
|
||||
// UNSAFE_SAMPLE_COUNT_TRUNCATION
|
||||
// -- but used only experimentally as of this writing
|
||||
// Is there a proof size_t will not overflow?
|
||||
const auto hitStartInCache = FFMAX(0,start-mDecodeCache[i]->start);
|
||||
const auto hitStartInCache = FFMAX(sampleCount{0},start-mDecodeCache[i]->start);
|
||||
//we also need to find out which end was hit - if it is the tail only we need to update from a later index.
|
||||
const auto hitStartInRequest = start < mDecodeCache[i]->start
|
||||
? len - samplesHit : 0;
|
||||
? len - samplesHit : sampleCount{ 0 };
|
||||
for(decltype(samplesHit) j = 0; j < samplesHit; j++)
|
||||
{
|
||||
const auto outIndex = hitStartInRequest + j;
|
||||
|
Loading…
x
Reference in New Issue
Block a user