Index: Source/platform/audio/AudioUtilities.cpp |
diff --git a/Source/platform/audio/AudioUtilities.cpp b/Source/platform/audio/AudioUtilities.cpp |
index 531d22d3ed8e4788da6ca2a771fa987434cdb4b2..73786f0279be2c09365f5ac16c932b61d69fcf44 100644 |
--- a/Source/platform/audio/AudioUtilities.cpp |
+++ b/Source/platform/audio/AudioUtilities.cpp |
@@ -27,6 +27,7 @@ |
#if ENABLE(WEB_AUDIO) |
#include "platform/audio/AudioUtilities.h" |
+ |
#include "wtf/Assertions.h" |
#include "wtf/MathExtras.h" |
@@ -59,6 +60,41 @@ size_t timeToSampleFrame(double time, double sampleRate) |
{ |
return static_cast<size_t>(round(time * sampleRate)); |
} |
+ |
+bool isSampleRateRangeGood(float sampleRate) |
+{ |
+ return sampleRate >= minAllowedSampleRate() && sampleRate <= maxAllowedSampleRate(); |
+} |
+ |
+size_t fftSizeForSampleRate(float sampleRate) |
+{ |
+ // Currently, we truncate the impulse responses to half this size, |
Raymond Toy
2014/09/11 16:38:45
Need more context here because "this size" has no
KhNo
2014/09/12 15:01:05
Done.
|
+ // but an FFT-size of twice impulse response size is needed (for convolution). |
+ // So for sample rates around 44.1KHz an FFT size of 512 is good. |
+ // For different sample rates, the truncated response is resampled. |
+ // The resampled length is used to compute the FFT size by choosing a power of two that is |
+ // greater than or equal the resampled length. This power of two is doubled to get the actual FFT size. |
+ |
+ ASSERT(isSampleRateRangeGood(sampleRate)); |
+ |
+ int truncatedImpulseLength = 256; |
+ double sampleRateRatio = sampleRate / 44100; |
+ double resampledLength = truncatedImpulseLength * sampleRateRatio; |
+ |
+ return 2 * (1 << static_cast<unsigned>(log2(resampledLength))); |
+} |
+ |
+float minAllowedSampleRate() |
+{ |
+ // crbug.com/344375 |
+ return 3000; |
+} |
+ |
+float maxAllowedSampleRate() |
+{ |
+ // Windows can support up to this rate. |
+ return 192000; |
+} |
} // AudioUtilites |
} // namespace blink |