mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1240054 - Only rebuild BandLimitedTables if more partials are required r=padenot
We currently rebuild the BandLimitedTables whenever we encounter a lower fundamental frequency but it is only necessary to rebuild the tables if we can fit more partials below the Nyquist frequency. Rebuilding the tables unnecessarily can cause performance problems, particularly in the case where the frequency is continually lowered.
This commit is contained in:
parent
53250aff04
commit
8e008f9729
@ -109,7 +109,7 @@ PeriodicWave::createTriangle(float sampleRate)
|
||||
PeriodicWave::PeriodicWave(float sampleRate, size_t numberOfComponents)
|
||||
: m_sampleRate(sampleRate)
|
||||
, m_centsPerRange(CentsPerRange)
|
||||
, m_lowestRequestedFundamentalFrequency(std::numeric_limits<float>::max())
|
||||
, m_maxPartialsInBandLimitedTable(0)
|
||||
, m_normalizationScale(1.0f)
|
||||
{
|
||||
float nyquist = 0.5 * m_sampleRate;
|
||||
@ -148,7 +148,13 @@ void PeriodicWave::waveDataForFundamentalFrequency(float fundamentalFrequency, f
|
||||
// to the positive frequency.
|
||||
fundamentalFrequency = fabsf(fundamentalFrequency);
|
||||
|
||||
if (fundamentalFrequency < m_lowestRequestedFundamentalFrequency) {
|
||||
// We only need to rebuild to the tables if the new fundamental
|
||||
// frequency is low enough to allow for more partials below the
|
||||
// Nyquist frequency.
|
||||
unsigned numberOfPartials = numberOfPartialsForRange(0);
|
||||
float nyquist = 0.5 * m_sampleRate;
|
||||
numberOfPartials = std::min(numberOfPartials, (unsigned)(nyquist / fundamentalFrequency));
|
||||
if (numberOfPartials > m_maxPartialsInBandLimitedTable) {
|
||||
for (unsigned rangeIndex = 0; rangeIndex < m_numberOfRanges; ++rangeIndex) {
|
||||
m_bandLimitedTables[rangeIndex] = 0;
|
||||
}
|
||||
@ -156,7 +162,7 @@ void PeriodicWave::waveDataForFundamentalFrequency(float fundamentalFrequency, f
|
||||
// We need to create the first table to determine the normalization
|
||||
// constant.
|
||||
createBandLimitedTables(fundamentalFrequency, 0);
|
||||
m_lowestRequestedFundamentalFrequency = fundamentalFrequency;
|
||||
m_maxPartialsInBandLimitedTable = numberOfPartials;
|
||||
}
|
||||
|
||||
// Calculate the pitch range.
|
||||
|
@ -106,7 +106,7 @@ private:
|
||||
|
||||
// Creates table for specified index based on fundamental frequency.
|
||||
void createBandLimitedTables(float fundamentalFrequency, unsigned rangeIndex);
|
||||
float m_lowestRequestedFundamentalFrequency;
|
||||
unsigned m_maxPartialsInBandLimitedTable;
|
||||
float m_normalizationScale;
|
||||
nsTArray<nsAutoPtr<AlignedAudioFloatArray> > m_bandLimitedTables;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user