Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created February 10, 2020 17:33
Show Gist options
  • Save Xenakios/82e0e436b7ac97b11d5edc48f041c6a1 to your computer and use it in GitHub Desktop.
Save Xenakios/82e0e436b7ac97b11d5edc48f041c6a1 to your computer and use it in GitHub Desktop.
inline void getSamples(int64 sourceindex, float* destbuf, int nframes, int numdestchans)
{
auto ptrs = m_buf.getArrayOfReadPointers();
for (int i = 0; i < nframes; ++i)
{
if (sourceindex + i < m_buf.getNumSamples())
{
for (int j = 0; j < numdestchans; ++j)
destbuf[i*numdestchans + j] = ptrs[j][i + sourceindex];
}
else
{
for (int j = 0; j < numdestchans; ++j)
destbuf[i*numdestchans + j] = 0.0f;
}
}
}
if (m_fadelen > 0.0)
{
int flensamples = m_sr * m_fadelen;
auto len = m_length;
if (flensamples * 2 > len)
flensamples = len / 2;
for (int i = 0; i < nframes; ++i)
{
float gain = 1.0f;
int64 index = sourceindex + i;
if (index < flensamples)
gain = 1.0f / flensamples * index;
if (index >= len - flensamples)
gain = 1.0f - 1.0f / flensamples * (index - (len - flensamples));
for (int j = 0; j < numdestchans; ++j)
destbuf[i*numdestchans + j] *= gain;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment