1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-19 06:07:42 +02:00

More uses of SampleBuffer, eliminating explicit DeleteSamples calls

This commit is contained in:
Paul Licameli 2016-02-01 10:16:00 -05:00
parent 508286661a
commit 321d5259a2
22 changed files with 145 additions and 156 deletions

View File

@ -879,9 +879,6 @@ AudioIO::AudioIO()
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
mAILAActive = false;
#endif
mSilentBuf = NULL;
mLastSilentBufSize = 0;
mStreamToken = 0;
mLastPaError = paNoError;
@ -989,9 +986,6 @@ AudioIO::~AudioIO()
mThread->Delete();
if(mSilentBuf)
DeleteSamples(mSilentBuf);
delete mThread;
#ifdef EXPERIMENTAL_SCRUBBING_SUPPORT
@ -3364,16 +3358,9 @@ void AudioIO::FillBuffers()
// numbers of samples for all channels for this pass of the do-loop.
if(processed < frames && mPlayMode != PLAY_STRAIGHT)
{
if(mLastSilentBufSize < frames)
{
//delete old if necessary
if(mSilentBuf)
DeleteSamples(mSilentBuf);
mLastSilentBufSize = frames;
mSilentBuf = NewSamples(mLastSilentBufSize, floatSample);
ClearSamples(mSilentBuf, floatSample, 0, mLastSilentBufSize);
}
mPlaybackBuffers[i]->Put(mSilentBuf, floatSample, frames - processed);
mSilentBuf.Resize(frames, floatSample);
ClearSamples(mSilentBuf.ptr(), floatSample, 0, frames);
mPlaybackBuffers[i]->Put(mSilentBuf.ptr(), floatSample, frames - processed);
}
}
@ -3463,28 +3450,25 @@ void AudioIO::FillBuffers()
if( mFactor == 1.0 )
{
samplePtr temp = NewSamples(avail, trackFormat);
mCaptureBuffers[i]->Get (temp, trackFormat, avail);
(*mCaptureTracks)[i]-> Append(temp, trackFormat, avail, 1,
SampleBuffer temp(avail, trackFormat);
mCaptureBuffers[i]->Get (temp.ptr(), trackFormat, avail);
(*mCaptureTracks)[i]-> Append(temp.ptr(), trackFormat, avail, 1,
&appendLog);
DeleteSamples(temp);
}
else
{
int size = lrint(avail * mFactor);
samplePtr temp1 = NewSamples(avail, floatSample);
samplePtr temp2 = NewSamples(size, floatSample);
mCaptureBuffers[i]->Get(temp1, floatSample, avail);
SampleBuffer temp1(avail, floatSample);
SampleBuffer temp2(size, floatSample);
mCaptureBuffers[i]->Get(temp1.ptr(), floatSample, avail);
/* we are re-sampling on the fly. The last resampling call
* must flush any samples left in the rate conversion buffer
* so that they get recorded
*/
size = mResample[i]->Process(mFactor, (float *)temp1, avail, !IsStreamActive(),
&size, (float *)temp2, size);
(*mCaptureTracks)[i]-> Append(temp2, floatSample, size, 1,
size = mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail, !IsStreamActive(),
&size, (float *)temp2.ptr(), size);
(*mCaptureTracks)[i]-> Append(temp2.ptr(), floatSample, size, 1,
&appendLog);
DeleteSamples(temp1);
DeleteSamples(temp2);
}
if (!appendLog.IsEmpty())

View File

@ -648,8 +648,7 @@ private:
double mCutPreviewGapStart;
double mCutPreviewGapLen;
samplePtr mSilentBuf;
sampleCount mLastSilentBufSize;
GrowableSampleBuffer mSilentBuf;
AudioIOListener* mListener;

View File

@ -386,8 +386,8 @@ void BlockFile::GetMinMax(sampleCount start, sampleCount len,
float *outMin, float *outMax, float *outRMS)
{
// TODO: actually use summaries
samplePtr blockData = NewSamples(len, floatSample);
this->ReadData(blockData, floatSample, start, len);
SampleBuffer blockData(len, floatSample);
this->ReadData(blockData.ptr(), floatSample, start, len);
float min = FLT_MAX;
float max = -FLT_MAX;
@ -395,7 +395,7 @@ void BlockFile::GetMinMax(sampleCount start, sampleCount len,
for( int i = 0; i < len; i++ )
{
float sample = ((float*)blockData)[i];
float sample = ((float*)blockData.ptr())[i];
if( sample > max )
max = sample;
@ -404,8 +404,6 @@ void BlockFile::GetMinMax(sampleCount start, sampleCount len,
sumsq += (sample*sample);
}
DeleteSamples(blockData);
*outMin = min;
*outMax = max;
*outRMS = sqrt(sumsq/len);
@ -579,14 +577,12 @@ void AliasBlockFile::WriteSummary()
// To build the summary data, call ReadData (implemented by the
// derived classes) to get the sample data
samplePtr sampleData = NewSamples(mLen, floatSample);
this->ReadData(sampleData, floatSample, 0, mLen);
SampleBuffer sampleData(mLen, floatSample);
this->ReadData(sampleData.ptr(), floatSample, 0, mLen);
void *summaryData = BlockFile::CalcSummary(sampleData, mLen,
void *summaryData = BlockFile::CalcSummary(sampleData.ptr(), mLen,
floatSample);
summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);
DeleteSamples(sampleData);
}
AliasBlockFile::~AliasBlockFile()

View File

@ -202,11 +202,13 @@ static void RemoveDependencies(AudacityProject *project,
// Convert it from an aliased file to an actual file in the project.
unsigned int len = aliasBlockFile->GetLength();
samplePtr buffer = NewSamples(len, format);
f->ReadData(buffer, format, 0, len);
BlockFile *newBlockFile =
dirManager->NewSimpleBlockFile(buffer, len, format);
DeleteSamples(buffer);
BlockFile *newBlockFile;
{
SampleBuffer buffer(len, format);
f->ReadData(buffer.ptr(), format, 0, len);
newBlockFile =
dirManager->NewSimpleBlockFile(buffer.ptr(), len, format);
}
// Update our hash so we know what block files we've done
blockFileHash[f] = newBlockFile;

View File

@ -294,11 +294,11 @@ Mixer::Mixer(int numInputTracks, WaveTrack **inputTracks,
mInterleavedBufferSize = mBufferSize;
}
mBuffer = new samplePtr[mNumBuffers];
mTemp = new samplePtr[mNumBuffers];
mBuffer = new SampleBuffer[mNumBuffers];
mTemp = new SampleBuffer[mNumBuffers];
for (int c = 0; c < mNumBuffers; c++) {
mBuffer[c] = NewSamples(mInterleavedBufferSize, mFormat);
mTemp[c] = NewSamples(mInterleavedBufferSize, floatSample);
mBuffer[c].Allocate(mInterleavedBufferSize, mFormat);
mTemp[c].Allocate(mInterleavedBufferSize, floatSample);
}
mFloatBuffer = new float[mInterleavedBufferSize];
@ -356,10 +356,6 @@ Mixer::~Mixer()
{
int i;
for (i = 0; i < mNumBuffers; i++) {
DeleteSamples(mBuffer[i]);
DeleteSamples(mTemp[i]);
}
delete[] mBuffer;
delete[] mTemp;
delete[] mInputTrack;
@ -386,12 +382,12 @@ void Mixer::ApplyTrackGains(bool apply)
void Mixer::Clear()
{
for (int c = 0; c < mNumBuffers; c++) {
memset(mTemp[c], 0, mInterleavedBufferSize * SAMPLE_SIZE(floatSample));
memset(mTemp[c].ptr(), 0, mInterleavedBufferSize * SAMPLE_SIZE(floatSample));
}
}
void MixBuffers(int numChannels, int *channelFlags, float *gains,
samplePtr src, samplePtr *dests,
samplePtr src, SampleBuffer *dests,
int len, bool interleaved)
{
for (int c = 0; c < numChannels; c++) {
@ -402,10 +398,10 @@ void MixBuffers(int numChannels, int *channelFlags, float *gains,
int skip;
if (interleaved) {
destPtr = dests[0] + c*SAMPLE_SIZE(floatSample);
destPtr = dests[0].ptr() + c*SAMPLE_SIZE(floatSample);
skip = numChannels;
} else {
destPtr = dests[c];
destPtr = dests[c].ptr();
skip = 1;
}
@ -689,9 +685,9 @@ sampleCount Mixer::Process(sampleCount maxToProcess)
}
if(mInterleaved) {
for(int c=0; c<mNumChannels; c++) {
CopySamples(mTemp[0] + (c * SAMPLE_SIZE(floatSample)),
CopySamples(mTemp[0].ptr() + (c * SAMPLE_SIZE(floatSample)),
floatSample,
mBuffer[0] + (c * SAMPLE_SIZE(mFormat)),
mBuffer[0].ptr() + (c * SAMPLE_SIZE(mFormat)),
mFormat,
maxOut,
mHighQuality,
@ -701,9 +697,9 @@ sampleCount Mixer::Process(sampleCount maxToProcess)
}
else {
for(int c=0; c<mNumBuffers; c++) {
CopySamples(mTemp[c],
CopySamples(mTemp[c].ptr(),
floatSample,
mBuffer[c],
mBuffer[c].ptr(),
mFormat,
maxOut,
mHighQuality);
@ -719,12 +715,12 @@ sampleCount Mixer::Process(sampleCount maxToProcess)
samplePtr Mixer::GetBuffer()
{
return mBuffer[0];
return mBuffer[0].ptr();
}
samplePtr Mixer::GetBuffer(int channel)
{
return mBuffer[channel];
return mBuffer[channel].ptr();
}
double Mixer::MixGetCurrentTime()

View File

@ -176,8 +176,8 @@ class AUDACITY_DLL_API Mixer {
int mInterleavedBufferSize;
sampleFormat mFormat;
bool mInterleaved;
samplePtr *mBuffer;
samplePtr *mTemp;
SampleBuffer *mBuffer;
SampleBuffer *mTemp;
float *mFloatBuffer;
double mRate;
double mSpeed;

View File

@ -25,17 +25,16 @@
#include "RingBuffer.h"
RingBuffer::RingBuffer(sampleFormat format, int size)
: mFormat(format)
, mBufferSize(size > 64 ? size : 64)
, mBuffer(mBufferSize, mFormat)
{
mFormat = format;
mBufferSize = (size > 64? size: 64);
mStart = 0;
mEnd = 0;
mBuffer = NewSamples(mBufferSize, mFormat);
}
RingBuffer::~RingBuffer()
{
DeleteSamples(mBuffer);
}
int RingBuffer::Len()
@ -74,7 +73,7 @@ int RingBuffer::Put(samplePtr buffer, sampleFormat format,
block = mBufferSize - pos;
CopySamples(src, format,
mBuffer + pos * SAMPLE_SIZE(mFormat), mFormat,
mBuffer.ptr() + pos * SAMPLE_SIZE(mFormat), mFormat,
block);
src += block * SAMPLE_SIZE(format);
@ -116,7 +115,7 @@ int RingBuffer::Get(samplePtr buffer, sampleFormat format,
if (block > mBufferSize - mStart)
block = mBufferSize - mStart;
CopySamples(mBuffer + mStart * SAMPLE_SIZE(mFormat), mFormat,
CopySamples(mBuffer.ptr() + mStart * SAMPLE_SIZE(mFormat), mFormat,
dest, format,
block);

View File

@ -40,7 +40,7 @@ class RingBuffer {
int mStart;
int mEnd;
int mBufferSize;
samplePtr mBuffer;
SampleBuffer mBuffer;
};
#endif /* __AUDACITY_RING_BUFFER__ */

View File

@ -56,10 +56,10 @@ class SampleBuffer {
public:
SampleBuffer()
: mCount(0), mPtr(0)
: mPtr(0)
{}
SampleBuffer(int count, sampleFormat format)
: mCount(count), mPtr(NewSamples(mCount, format))
: mPtr(NewSamples(count, format))
{}
~SampleBuffer()
{
@ -67,30 +67,61 @@ public:
}
// WARNING! May not preserve contents.
void Resize(int count, sampleFormat format)
SampleBuffer &Allocate(int count, sampleFormat format)
{
if (mCount < count) {
Free();
mPtr = NewSamples(count, format);
mCount = count;
}
Free();
mPtr = NewSamples(count, format);
return *this;
}
void Free()
{
DeleteSamples(mPtr);
mPtr = 0;
mCount = 0;
}
samplePtr ptr() const { return mPtr; }
private:
int mCount;
samplePtr mPtr;
};
class GrowableSampleBuffer : private SampleBuffer
{
public:
GrowableSampleBuffer()
: SampleBuffer()
, mCount(0)
{}
GrowableSampleBuffer(int count, sampleFormat format)
: SampleBuffer(count, format)
, mCount(count)
{}
GrowableSampleBuffer &Resize(int count, sampleFormat format)
{
if (!ptr() || mCount < count) {
Allocate(count, format);
mCount = count;
}
return *this;
}
void Free()
{
SampleBuffer::Free();
mCount = 0;
}
using SampleBuffer::ptr;
private:
int mCount;
};
//
// Copying, Converting and Clearing Samples
//

View File

@ -302,7 +302,6 @@ WaveClip::WaveClip(DirManager *projDirManager, sampleFormat format, int rate)
mWaveCache = new WaveCache();
mSpecCache = new SpecCache();
mSpecPxCache = new SpecPxCache(1);
mAppendBuffer = NULL;
mAppendBufferLen = 0;
mDirty = 0;
mIsPlaceholder = false;
@ -328,7 +327,6 @@ WaveClip::WaveClip(const WaveClip& orig, DirManager *projDirManager)
for (WaveClipList::compatibility_iterator it=orig.mCutLines.GetFirst(); it; it=it->GetNext())
mCutLines.Append(new WaveClip(*it->GetData(), projDirManager));
mAppendBuffer = NULL;
mAppendBufferLen = 0;
mDirty = 0;
mIsPlaceholder = orig.GetIsPlaceholder();
@ -345,9 +343,6 @@ WaveClip::~WaveClip()
delete mSpecCache;
delete mSpecPxCache;
if (mAppendBuffer)
DeleteSamples(mAppendBuffer);
mCutLines.DeleteContents(true);
mCutLines.Clear();
}
@ -668,10 +663,10 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
sampleCount j;
if (seqFormat == floatSample)
b = &((float *)mAppendBuffer)[left];
b = &((float *)mAppendBuffer.ptr())[left];
else {
b = new float[len];
CopySamples(mAppendBuffer + left*SAMPLE_SIZE(seqFormat),
CopySamples(mAppendBuffer.ptr() + left*SAMPLE_SIZE(seqFormat),
seqFormat,
(samplePtr)b, floatSample, len);
}
@ -1263,18 +1258,18 @@ bool WaveClip::Append(samplePtr buffer, sampleFormat format,
sampleCount blockSize = mSequence->GetIdealAppendLen();
sampleFormat seqFormat = mSequence->GetSampleFormat();
if (!mAppendBuffer)
mAppendBuffer = NewSamples(maxBlockSize, seqFormat);
if (!mAppendBuffer.ptr())
mAppendBuffer.Allocate(maxBlockSize, seqFormat);
for(;;) {
if (mAppendBufferLen >= blockSize) {
bool success =
mSequence->Append(mAppendBuffer, seqFormat, blockSize,
mSequence->Append(mAppendBuffer.ptr(), seqFormat, blockSize,
blockFileLog);
if (!success)
return false;
memmove(mAppendBuffer,
mAppendBuffer + blockSize * SAMPLE_SIZE(seqFormat),
memmove(mAppendBuffer.ptr(),
mAppendBuffer.ptr() + blockSize * SAMPLE_SIZE(seqFormat),
(mAppendBufferLen - blockSize) * SAMPLE_SIZE(seqFormat));
mAppendBufferLen -= blockSize;
blockSize = mSequence->GetIdealAppendLen();
@ -1288,7 +1283,7 @@ bool WaveClip::Append(samplePtr buffer, sampleFormat format,
toCopy = len;
CopySamples(buffer, format,
mAppendBuffer + mAppendBufferLen * SAMPLE_SIZE(seqFormat),
mAppendBuffer.ptr() + mAppendBufferLen * SAMPLE_SIZE(seqFormat),
seqFormat,
toCopy,
true, // high quality
@ -1337,7 +1332,7 @@ bool WaveClip::Flush()
bool success = true;
if (mAppendBufferLen > 0) {
success = mSequence->Append(mAppendBuffer, mSequence->GetSampleFormat(), mAppendBufferLen);
success = mSequence->Append(mAppendBuffer.ptr(), mSequence->GetSampleFormat(), mAppendBufferLen);
if (success) {
mAppendBufferLen = 0;
UpdateEnvelopeTrackLen();

View File

@ -392,7 +392,7 @@ protected:
WaveCache *mWaveCache;
ODLock mWaveCacheMutex;
SpecCache *mSpecCache;
samplePtr mAppendBuffer;
SampleBuffer mAppendBuffer;
sampleCount mAppendBufferLen;
// Cut Lines are nothing more than ordinary wave clips, with the

View File

@ -536,7 +536,7 @@ private:
const WaveTrack *mPTrack;
sampleCount mBufferSize;
Buffer mBuffers[2];
SampleBuffer mOverlapBuffer;
GrowableSampleBuffer mOverlapBuffer;
int mNValidBuffers;
};

View File

@ -66,8 +66,8 @@ void ComputeLegacySummaryInfo(wxFileName fileName,
//
float *summary = new float[info->frames64K * fields];
samplePtr data = NewSamples(info->frames64K * fields,
info->format);
SampleBuffer data(info->frames64K * fields,
info->format);
wxLogNull *silence=0;
wxFFile summaryFile(fileName.GetFullPath(), wxT("rb"));
@ -79,10 +79,10 @@ void ComputeLegacySummaryInfo(wxFileName fileName,
fileName.GetFullPath().c_str());
read=info->frames64K * info->bytesPerFrame;
memset(data,0,read);
memset(data.ptr(), 0, read);
}else{
summaryFile.Seek(info->offset64K);
read = summaryFile.Read(data,
read = summaryFile.Read(data.ptr(),
info->frames64K *
info->bytesPerFrame);
}
@ -91,7 +91,7 @@ void ComputeLegacySummaryInfo(wxFileName fileName,
int count = read / info->bytesPerFrame;
CopySamples(data, info->format,
CopySamples(data.ptr(), info->format,
(samplePtr)summary, floatSample, count);
(*min) = FLT_MAX;
@ -111,7 +111,6 @@ void ComputeLegacySummaryInfo(wxFileName fileName,
else
(*rms) = 0;
DeleteSamples(data);
delete[] summary;
}
@ -235,7 +234,7 @@ int LegacyBlockFile::ReadData(samplePtr data, sampleFormat format,
(mSummaryInfo.totalSummaryBytes / SAMPLE_SIZE(mFormat));
sf_seek(sf, seekstart , SEEK_SET);
samplePtr buffer = NewSamples(len, floatSample);
SampleBuffer buffer(len, floatSample);
int framesRead = 0;
// If both the src and dest formats are integer formats,
@ -258,15 +257,13 @@ int LegacyBlockFile::ReadData(samplePtr data, sampleFormat format,
// Otherwise, let libsndfile handle the conversion and
// scaling, and pass us normalized data as floats. We can
// then convert to whatever format we want.
framesRead = sf_readf_float(sf, (float *)buffer, len);
CopySamples(buffer, floatSample,
framesRead = sf_readf_float(sf, (float *)buffer.ptr(), len);
CopySamples(buffer.ptr(), floatSample,
(samplePtr)data, format, framesRead);
}
sf_close(sf);
DeleteSamples(buffer);
return framesRead;
}

View File

@ -308,7 +308,7 @@ int ODDecodeBlockFile::WriteODDecodeBlockFile()
// To build the summary data, call ReadData (implemented by the
// derived classes) to get the sample data
samplePtr sampleData;// = NewSamples(mLen, floatSample);
SampleBuffer sampleData;// = NewSamples(mLen, floatSample);
int ret;
//use the decoder here.
mDecoderMutex.Lock();
@ -334,7 +334,7 @@ int ODDecodeBlockFile::WriteODDecodeBlockFile()
//TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile
bool bSuccess =
WriteSimpleBlockFile(
sampleData,
sampleData.ptr(),
mLen,
mFormat,
NULL);//summaryData);
@ -342,7 +342,6 @@ int ODDecodeBlockFile::WriteODDecodeBlockFile()
mFileNameMutex.Unlock();
DeleteSamples(sampleData);
// delete [] (char *) summaryData;

View File

@ -421,16 +421,15 @@ void ODPCMAliasBlockFile::WriteSummary()
// To build the summary data, call ReadData (implemented by the
// derived classes) to get the sample data
samplePtr sampleData = NewSamples(mLen, floatSample);
this->ReadData(sampleData, floatSample, 0, mLen);
SampleBuffer sampleData(mLen, floatSample);
this->ReadData(sampleData.ptr(), floatSample, 0, mLen);
void *summaryData = CalcSummary(sampleData, mLen,
void *summaryData = CalcSummary(sampleData.ptr(), mLen,
floatSample);
//summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);
fwrite(summaryData, 1, mSummaryInfo.totalSummaryBytes, summaryFile);
fclose(summaryFile);
DeleteSamples(sampleData);
delete [] (char *) summaryData;
@ -645,7 +644,7 @@ int ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
sf_seek(sf, mAliasStart + start, SEEK_SET);
ODManager::UnlockLibSndFileMutex();
samplePtr buffer = NewSamples(len * info.channels, floatSample);
SampleBuffer buffer(len * info.channels, floatSample);
int framesRead = 0;
@ -656,28 +655,26 @@ int ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
// read 16-bit data directly. This is a pretty common
// case, as most audio files are 16-bit.
ODManager::LockLibSndFileMutex();
framesRead = sf_readf_short(sf, (short *)buffer, len);
framesRead = sf_readf_short(sf, (short *)buffer.ptr(), len);
ODManager::UnlockLibSndFileMutex();
for (int i = 0; i < framesRead; i++)
((short *)data)[i] =
((short *)buffer)[(info.channels * i) + mAliasChannel];
((short *)buffer.ptr())[(info.channels * i) + mAliasChannel];
}
else {
// Otherwise, let libsndfile handle the conversion and
// scaling, and pass us normalized data as floats. We can
// then convert to whatever format we want.
ODManager::LockLibSndFileMutex();
framesRead = sf_readf_float(sf, (float *)buffer, len);
framesRead = sf_readf_float(sf, (float *)buffer.ptr(), len);
ODManager::UnlockLibSndFileMutex();
float *bufferPtr = &((float *)buffer)[mAliasChannel];
float *bufferPtr = &((float *)buffer.ptr())[mAliasChannel];
CopySamples((samplePtr)bufferPtr, floatSample,
(samplePtr)data, format,
framesRead, true, info.channels);
}
DeleteSamples(buffer);
ODManager::LockLibSndFileMutex();
sf_close(sf);
ODManager::UnlockLibSndFileMutex();

View File

@ -116,7 +116,7 @@ int PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
ODManager::LockLibSndFileMutex();
sf_seek(sf, mAliasStart + start, SEEK_SET);
ODManager::UnlockLibSndFileMutex();
samplePtr buffer = NewSamples(len * info.channels, floatSample);
SampleBuffer buffer(len * info.channels, floatSample);
int framesRead = 0;
@ -127,26 +127,25 @@ int PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
// read 16-bit data directly. This is a pretty common
// case, as most audio files are 16-bit.
ODManager::LockLibSndFileMutex();
framesRead = sf_readf_short(sf, (short *)buffer, len);
framesRead = sf_readf_short(sf, (short *)buffer.ptr(), len);
ODManager::UnlockLibSndFileMutex();
for (int i = 0; i < framesRead; i++)
((short *)data)[i] =
((short *)buffer)[(info.channels * i) + mAliasChannel];
((short *)buffer.ptr())[(info.channels * i) + mAliasChannel];
}
else {
// Otherwise, let libsndfile handle the conversion and
// scaling, and pass us normalized data as floats. We can
// then convert to whatever format we want.
ODManager::LockLibSndFileMutex();
framesRead = sf_readf_float(sf, (float *)buffer, len);
framesRead = sf_readf_float(sf, (float *)buffer.ptr(), len);
ODManager::UnlockLibSndFileMutex();
float *bufferPtr = &((float *)buffer)[mAliasChannel];
float *bufferPtr = &((float *)buffer.ptr())[mAliasChannel];
CopySamples((samplePtr)bufferPtr, floatSample,
(samplePtr)data, format,
framesRead, true, info.channels);
}
DeleteSamples(buffer);
ODManager::LockLibSndFileMutex();
sf_close(sf);
ODManager::UnlockLibSndFileMutex();

View File

@ -428,7 +428,7 @@ int SimpleBlockFile::ReadData(samplePtr data, sampleFormat format,
mSilentLog=FALSE;
sf_seek(sf, start, SEEK_SET);
samplePtr buffer = NewSamples(len, floatSample);
SampleBuffer buffer(len, floatSample);
int framesRead = 0;
@ -456,13 +456,11 @@ int SimpleBlockFile::ReadData(samplePtr data, sampleFormat format,
// Otherwise, let libsndfile handle the conversion and
// scaling, and pass us normalized data as floats. We can
// then convert to whatever format we want.
framesRead = sf_readf_float(sf, (float *)buffer, len);
CopySamples(buffer, floatSample,
framesRead = sf_readf_float(sf, (float *)buffer.ptr(), len);
CopySamples(buffer.ptr(), floatSample,
(samplePtr)data, format, framesRead);
}
DeleteSamples(buffer);
sf_close(sf);
return framesRead;

View File

@ -423,15 +423,15 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
if (maxBlock < 1)
return eProgressFailed;
samplePtr srcbuffer;
while (NULL == (srcbuffer = NewSamples(maxBlock * mInfo.channels, mFormat)))
SampleBuffer srcbuffer;
while (NULL == srcbuffer.Allocate(maxBlock * mInfo.channels, mFormat).ptr())
{
maxBlock >>= 1;
if (maxBlock < 1)
return eProgressFailed;
}
samplePtr buffer = NewSamples(maxBlock, mFormat);
SampleBuffer buffer(maxBlock, mFormat);
unsigned long framescompleted = 0;
@ -440,25 +440,25 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
block = maxBlock;
if (mFormat == int16Sample)
block = sf_readf_short(mFile, (short *)srcbuffer, block);
block = sf_readf_short(mFile, (short *)srcbuffer.ptr(), block);
//import 24 bit int as float and have the append function convert it. This is how PCMAliasBlockFile works too.
else
block = sf_readf_float(mFile, (float *)srcbuffer, block);
block = sf_readf_float(mFile, (float *)srcbuffer.ptr(), block);
if (block) {
for(c=0; c<mInfo.channels; c++) {
if (mFormat==int16Sample) {
for(int j=0; j<block; j++)
((short *)buffer)[j] =
((short *)srcbuffer)[mInfo.channels*j+c];
((short *)buffer.ptr())[j] =
((short *)srcbuffer.ptr())[mInfo.channels*j+c];
}
else {
for(int j=0; j<block; j++)
((float *)buffer)[j] =
((float *)srcbuffer)[mInfo.channels*j+c];
((float *)buffer.ptr())[j] =
((float *)srcbuffer.ptr())[mInfo.channels*j+c];
}
channels[c]->Append(buffer, (mFormat == int16Sample)?int16Sample:floatSample, block);
channels[c]->Append(buffer.ptr(), (mFormat == int16Sample)?int16Sample:floatSample, block);
}
framescompleted += block;
}
@ -469,9 +469,6 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
break;
} while (block > 0);
DeleteSamples(buffer);
DeleteSamples(srcbuffer);
}
if (updateResult == eProgressFailed || updateResult == eProgressCancelled) {

View File

@ -68,7 +68,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.
virtual int Decode(samplePtr & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel);
virtual int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel);
///This is a must implement abstract virtual in the superclass.
///However it doesn't do anything because ImportFFMpeg does all that for us.
@ -296,12 +296,12 @@ ODFFmpegDecoder::~ODFFmpegDecoder()
#define kDecodeSampleAllowance 400000
//number of jump backwards seeks
#define kMaxSeekRewindAttempts 8
int ODFFmpegDecoder::Decode(samplePtr & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)
int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)
{
format = mScs[mStreamIndex]->m_osamplefmt;
data = NewSamples(len, format);
samplePtr bufStart = data;
data.Allocate(len, format);
samplePtr bufStart = data.ptr();
streamContext* sc = NULL;
// printf("start %llu len %llu\n", start, len);

View File

@ -166,7 +166,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(samplePtr & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)
int ODFlacDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)
{
//we need to lock this so the target stays fixed over the seek/write callback.
@ -182,8 +182,8 @@ int ODFlacDecoder::Decode(samplePtr & data, sampleFormat & format, sampleCount s
mDecodeBufferWritePosition=0;
mDecodeBufferLen = len;
data = NewSamples(len, mFormat);
mDecodeBuffer=data;
data.Allocate(len, mFormat);
mDecodeBuffer = data.ptr();
format = mFormat;
mTargetChannel=channel;

View File

@ -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.
virtual int Decode(samplePtr & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel);
virtual int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel);
///Read header. Subclasses must override. Probably should save the info somewhere.

View File

@ -117,7 +117,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(samplePtr & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)=0;
virtual int Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, sampleCount len, unsigned int channel)=0;
wxString GetFileName(){return mFName;}