mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-17 08:01:12 +02:00
Change sampleCount arguments, variables, return values to size_t...
... whenever they really describe the size of a buffer that fits in memory, or of a block file (which is never now more than a megabyte and so could be fit in memory all at once), or a part thereof.
This commit is contained in:
@@ -48,7 +48,7 @@ struct FFMpegDecodeCache
|
||||
|
||||
uint8_t* samplePtr{};//interleaved samples
|
||||
sampleCount start;
|
||||
sampleCount len;
|
||||
size_t len;
|
||||
unsigned numChannels;
|
||||
AVSampleFormat samplefmt; // input (from libav) sample format
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
///this->ReadData(sampleData, floatSample, 0, mLen);
|
||||
///This class should call ReadHeader() first, so it knows the length, and can prepare
|
||||
///the file object if it needs to.
|
||||
int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel) override;
|
||||
int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel) override;
|
||||
|
||||
///This is a must implement abstract virtual in the superclass.
|
||||
///However it doesn't do anything because ImportFFMpeg does all that for us.
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
void InsertCache(movable_ptr<FFMpegDecodeCache> &&cache);
|
||||
|
||||
//puts the actual audio samples into the blockfile's data array
|
||||
int FillDataFromCache(samplePtr & data, sampleFormat outFormat, sampleCount & start, sampleCount& len, unsigned int channel);
|
||||
int FillDataFromCache(samplePtr & data, sampleFormat outFormat, sampleCount & start, size_t& len, unsigned int channel);
|
||||
///REFACTORABLE CODE FROM IMPORT FFMPEG
|
||||
///! Reads next audio frame
|
||||
///\return pointer to the stream context structure to which the frame belongs to or NULL on error, or 1 if stream is not to be imported.
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
std::vector<movable_ptr<FFMpegDecodeCache>> mDecodeCache;
|
||||
int mNumSamplesInCache;
|
||||
sampleCount mCurrentPos; //the index of the next sample to be decoded
|
||||
sampleCount mCurrentLen; //length of the last packet decoded
|
||||
size_t mCurrentLen; //length of the last packet decoded
|
||||
|
||||
bool mSeekingAllowedStatus;
|
||||
int mStreamIndex;
|
||||
@@ -289,7 +289,7 @@ ODFFmpegDecoder::~ODFFmpegDecoder()
|
||||
#define kDecodeSampleAllowance 400000
|
||||
//number of jump backwards seeks
|
||||
#define kMaxSeekRewindAttempts 8
|
||||
int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)
|
||||
int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel)
|
||||
{
|
||||
auto mFormatContext = mContext->ic_ptr;
|
||||
|
||||
@@ -301,7 +301,7 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo
|
||||
samplePtr bufStart = data.ptr();
|
||||
streamContext* sc = NULL;
|
||||
|
||||
// printf("start %llu len %llu\n", start, len);
|
||||
// printf("start %llu len %lu\n", start, len);
|
||||
//TODO update this to work with seek - this only works linearly now.
|
||||
if(mCurrentPos > start && mCurrentPos <= start+len + kDecodeSampleAllowance)
|
||||
{
|
||||
@@ -387,7 +387,7 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo
|
||||
seeking = false;
|
||||
}
|
||||
if(actualDecodeStart != mCurrentPos)
|
||||
printf("ts not matching - now:%llu , last:%llu, lastlen:%llu, start %llu, len %llu\n",actualDecodeStart.as_long_long(), mCurrentPos.as_long_long(), mCurrentLen, start.as_long_long(), len);
|
||||
printf("ts not matching - now:%llu , last:%llu, lastlen:%lu, start %llu, len %lu\n",actualDecodeStart.as_long_long(), mCurrentPos.as_long_long(), mCurrentLen, start.as_long_long(), len);
|
||||
//if we've skipped over some samples, fill the gap with silence. This could happen often in the beginning of the file.
|
||||
if(actualDecodeStart>start && firstpass) {
|
||||
// find the number of samples for the leading silence
|
||||
@@ -398,7 +398,7 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo
|
||||
auto amt = (actualDecodeStart - start).as_size_t();
|
||||
auto cache = make_movable<FFMpegDecodeCache>();
|
||||
|
||||
//printf("skipping/zeroing %i samples. - now:%llu (%f), last:%llu, lastlen:%llu, start %llu, len %llu\n",amt,actualDecodeStart, actualDecodeStartdouble, mCurrentPos, mCurrentLen, start, len);
|
||||
//printf("skipping/zeroing %i samples. - now:%llu (%f), last:%llu, lastlen:%lu, start %llu, len %lu\n",amt,actualDecodeStart, actualDecodeStartdouble, mCurrentPos, mCurrentLen, start, len);
|
||||
|
||||
//put it in the cache so the other channels can use it.
|
||||
// wxASSERT(sc->m_stream->codec->channels > 0);
|
||||
@@ -466,7 +466,7 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo
|
||||
#define kODFFmpegSearchThreshold 10
|
||||
///returns the number of samples filled in from start.
|
||||
//also updates data and len to reflect NEW unfilled area - start is unmodified.
|
||||
int ODFFmpegDecoder::FillDataFromCache(samplePtr & data, sampleFormat outFormat, sampleCount &start, sampleCount& len, unsigned int channel)
|
||||
int ODFFmpegDecoder::FillDataFromCache(samplePtr & data, sampleFormat outFormat, sampleCount &start, size_t& len, unsigned int channel)
|
||||
{
|
||||
if(mDecodeCache.size() <= 0)
|
||||
return 0;
|
||||
@@ -529,7 +529,7 @@ int ODFFmpegDecoder::FillDataFromCache(samplePtr & data, sampleFormat outFormat,
|
||||
FFMAX(sampleCount{0},start-mDecodeCache[i]->start).as_size_t();
|
||||
//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 : sampleCount{ 0 };
|
||||
? len - samplesHit : 0;
|
||||
for(decltype(samplesHit) j = 0; j < samplesHit; j++)
|
||||
{
|
||||
const auto outIndex = hitStartInRequest + j;
|
||||
@@ -537,27 +537,27 @@ int ODFFmpegDecoder::FillDataFromCache(samplePtr & data, sampleFormat outFormat,
|
||||
switch (mDecodeCache[i]->samplefmt)
|
||||
{
|
||||
case AV_SAMPLE_FMT_U8:
|
||||
//printf("u8 in %llu out %llu cachelen %llu outLen %llu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
//printf("u8 in %lu out %lu cachelen %lu outLen %lu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
((int16_t *)outBuf)[outIndex] = (int16_t) (((uint8_t*)mDecodeCache[i]->samplePtr)[inIndex] - 0x80) << 8;
|
||||
break;
|
||||
|
||||
case AV_SAMPLE_FMT_S16:
|
||||
//printf("u16 in %llu out %llu cachelen %llu outLen %llu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
//printf("u16 in %lu out %lu cachelen %lu outLen % lu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
((int16_t *)outBuf)[outIndex] = ((int16_t*)mDecodeCache[i]->samplePtr)[inIndex];
|
||||
break;
|
||||
|
||||
case AV_SAMPLE_FMT_S32:
|
||||
//printf("s32 in %llu out %llu cachelen %llu outLen %llu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
//printf("s32 in %lu out %lu cachelen %lu outLen %lu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
((float *)outBuf)[outIndex] = (float) ((int32_t*)mDecodeCache[i]->samplePtr)[inIndex] * (1.0 / (1 << 31));
|
||||
break;
|
||||
|
||||
case AV_SAMPLE_FMT_FLT:
|
||||
//printf("f in %llu out %llu cachelen %llu outLen %llu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
//printf("f in %lu out %lu cachelen %lu outLen %lu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
((float *)outBuf)[outIndex] = (float) ((float*)mDecodeCache[i]->samplePtr)[inIndex];
|
||||
break;
|
||||
|
||||
case AV_SAMPLE_FMT_DBL:
|
||||
//printf("dbl in %llu out %llu cachelen %llu outLen %llu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
//printf("dbl in %lu out %lu cachelen %lu outLen %lu\n", inIndex, outIndex, mDecodeCache[i]->len, len);
|
||||
((float *)outBuf)[outIndex] = (float) ((double*)mDecodeCache[i]->samplePtr)[inIndex];
|
||||
break;
|
||||
|
||||
|
@@ -168,7 +168,7 @@ FLAC__StreamDecoderWriteStatus ODFLACFile::write_callback(const FLAC__Frame *fra
|
||||
///this->ReadData(sampleData, floatSample, 0, mLen);
|
||||
///This class should call ReadHeader() first, so it knows the length, and can prepare
|
||||
///the file object if it needs to.
|
||||
int ODFlacDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)
|
||||
int ODFlacDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel)
|
||||
{
|
||||
|
||||
//we need to lock this so the target stays fixed over the seek/write callback.
|
||||
|
@@ -106,7 +106,7 @@ public:
|
||||
///this->ReadData(sampleData, floatSample, 0, mLen);
|
||||
///This class should call ReadHeader() first, so it knows the length, and can prepare
|
||||
///the file object if it needs to.
|
||||
int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel) override;
|
||||
int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel) override;
|
||||
|
||||
|
||||
///Read header. Subclasses must override. Probably should save the info somewhere.
|
||||
|
@@ -119,7 +119,7 @@ public:
|
||||
///This class should call ReadHeader() first, so it knows the length, and can prepare
|
||||
///the file object if it needs to.
|
||||
///returns negative value for failure, 0 or positive value for success.
|
||||
virtual int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)=0;
|
||||
virtual int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel) = 0;
|
||||
|
||||
const wxString &GetFileName(){return mFName;}
|
||||
|
||||
|
Reference in New Issue
Block a user