Skip to content

Remove redundant zeroing #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions AudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,10 @@ void AudioFile<T>::setAudioBufferSize (int numChannels, int numSamples)
template <class T>
void AudioFile<T>::setNumSamplesPerChannel (int numSamples)
{
int originalSize = getNumSamplesPerChannel();

for (int i = 0; i < getNumChannels();i++)
{
samples[i].resize (numSamples);

// set any new samples to zero
if (numSamples > originalSize)
std::fill (samples[i].begin() + originalSize, samples[i].end(), (T)0.);
// std::vector::resize already zeroes the new samples
}
}

Expand All @@ -456,13 +451,10 @@ void AudioFile<T>::setNumChannels (int numChannels)

// make sure any new channels are set to the right size
// and filled with zeros
if (numChannels > originalNumChannels)
for (int i = originalNumChannels; i < numChannels; i++)
{
for (int i = originalNumChannels; i < numChannels; i++)
{
samples[i].resize (originalNumSamplesPerChannel);
std::fill (samples[i].begin(), samples[i].end(), (T)0.);
}
samples[i].resize (originalNumSamplesPerChannel);
// std::vector::resize already zeroes the new samples
}
}

Expand Down