mirror of
https://github.com/cookiengineer/audacity
synced 2026-02-06 11:42:17 +01:00
More uses of SampleBuffer, eliminating explicit DeleteSamples calls
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user