Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: third_party/WebKit/Source/platform/audio/HRTFPanner.cpp

Issue 2478283003: Use kRenderQuantumFrames in more places (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/audio/AudioDestination.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 20 matching lines...) Expand all
31 #include "wtf/RefPtr.h" 31 #include "wtf/RefPtr.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 // The value of 2 milliseconds is larger than the largest delay which exists in 35 // The value of 2 milliseconds is larger than the largest delay which exists in
36 // any HRTFKernel from the default HRTFDatabase (0.0136 seconds). 36 // any HRTFKernel from the default HRTFDatabase (0.0136 seconds).
37 // We ASSERT the delay values used in process() with this value. 37 // We ASSERT the delay values used in process() with this value.
38 const double MaxDelayTimeSeconds = 0.002; 38 const double MaxDelayTimeSeconds = 0.002;
39 39
40 const int UninitializedAzimuth = -1; 40 const int UninitializedAzimuth = -1;
41 const unsigned RenderingQuantum = 128;
42 41
43 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) 42 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader)
44 : Panner(PanningModelHRTF), 43 : Panner(PanningModelHRTF),
45 m_databaseLoader(databaseLoader), 44 m_databaseLoader(databaseLoader),
46 m_sampleRate(sampleRate), 45 m_sampleRate(sampleRate),
47 m_crossfadeSelection(CrossfadeSelection1), 46 m_crossfadeSelection(CrossfadeSelection1),
48 m_azimuthIndex1(UninitializedAzimuth), 47 m_azimuthIndex1(UninitializedAzimuth),
49 m_elevation1(0), 48 m_elevation1(0),
50 m_azimuthIndex2(UninitializedAzimuth), 49 m_azimuthIndex2(UninitializedAzimuth),
51 m_elevation2(0), 50 m_elevation2(0),
52 m_crossfadeX(0), 51 m_crossfadeX(0),
53 m_crossfadeIncr(0), 52 m_crossfadeIncr(0),
54 m_convolverL1(fftSizeForSampleRate(sampleRate)), 53 m_convolverL1(fftSizeForSampleRate(sampleRate)),
55 m_convolverR1(fftSizeForSampleRate(sampleRate)), 54 m_convolverR1(fftSizeForSampleRate(sampleRate)),
56 m_convolverL2(fftSizeForSampleRate(sampleRate)), 55 m_convolverL2(fftSizeForSampleRate(sampleRate)),
57 m_convolverR2(fftSizeForSampleRate(sampleRate)), 56 m_convolverR2(fftSizeForSampleRate(sampleRate)),
58 m_delayLineL(MaxDelayTimeSeconds, sampleRate), 57 m_delayLineL(MaxDelayTimeSeconds, sampleRate),
59 m_delayLineR(MaxDelayTimeSeconds, sampleRate), 58 m_delayLineR(MaxDelayTimeSeconds, sampleRate),
60 m_tempL1(RenderingQuantum), 59 m_tempL1(AudioUtilities::kRenderQuantumFrames),
61 m_tempR1(RenderingQuantum), 60 m_tempR1(AudioUtilities::kRenderQuantumFrames),
62 m_tempL2(RenderingQuantum), 61 m_tempL2(AudioUtilities::kRenderQuantumFrames),
63 m_tempR2(RenderingQuantum) { 62 m_tempR2(AudioUtilities::kRenderQuantumFrames) {
64 ASSERT(databaseLoader); 63 ASSERT(databaseLoader);
65 } 64 }
66 65
67 HRTFPanner::~HRTFPanner() {} 66 HRTFPanner::~HRTFPanner() {}
68 67
69 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) { 68 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) {
70 // The HRTF impulse responses (loaded as audio resources) are 512 69 // The HRTF impulse responses (loaded as audio resources) are 512
71 // sample-frames @44.1KHz. Currently, we truncate the impulse responses to 70 // sample-frames @44.1KHz. Currently, we truncate the impulse responses to
72 // half this size, but an FFT-size of twice impulse response size is needed 71 // half this size, but an FFT-size of twice impulse response size is needed
73 // (for convolution). So for sample rates around 44.1KHz an FFT size of 512 72 // (for convolution). So for sample rates around 44.1KHz an FFT size of 512
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (m_crossfadeX == 1 && m_crossfadeSelection == CrossfadeSelection2) { 202 if (m_crossfadeX == 1 && m_crossfadeSelection == CrossfadeSelection2) {
204 if (desiredAzimuthIndex != m_azimuthIndex2 || elevation != m_elevation2) { 203 if (desiredAzimuthIndex != m_azimuthIndex2 || elevation != m_elevation2) {
205 // Cross-fade from 2 -> 1 204 // Cross-fade from 2 -> 1
206 m_crossfadeIncr = -1 / fadeFrames; 205 m_crossfadeIncr = -1 / fadeFrames;
207 m_azimuthIndex1 = desiredAzimuthIndex; 206 m_azimuthIndex1 = desiredAzimuthIndex;
208 m_elevation1 = elevation; 207 m_elevation1 = elevation;
209 } 208 }
210 } 209 }
211 210
212 // This algorithm currently requires that we process in power-of-two size 211 // This algorithm currently requires that we process in power-of-two size
213 // chunks at least RenderingQuantum. 212 // chunks at least AudioUtilities::kRenderQuantumFrames.
214 ASSERT(1UL << static_cast<int>(log2(framesToProcess)) == framesToProcess); 213 ASSERT(1UL << static_cast<int>(log2(framesToProcess)) == framesToProcess);
215 ASSERT(framesToProcess >= RenderingQuantum); 214 DCHECK_GE(framesToProcess, AudioUtilities::kRenderQuantumFrames);
216 215
217 const unsigned framesPerSegment = RenderingQuantum; 216 const unsigned framesPerSegment = AudioUtilities::kRenderQuantumFrames;
218 const unsigned numberOfSegments = framesToProcess / framesPerSegment; 217 const unsigned numberOfSegments = framesToProcess / framesPerSegment;
219 218
220 for (unsigned segment = 0; segment < numberOfSegments; ++segment) { 219 for (unsigned segment = 0; segment < numberOfSegments; ++segment) {
221 // Get the HRTFKernels and interpolated delays. 220 // Get the HRTFKernels and interpolated delays.
222 HRTFKernel* kernelL1; 221 HRTFKernel* kernelL1;
223 HRTFKernel* kernelR1; 222 HRTFKernel* kernelR1;
224 HRTFKernel* kernelL2; 223 HRTFKernel* kernelL2;
225 HRTFKernel* kernelR2; 224 HRTFKernel* kernelR2;
226 double frameDelayL1; 225 double frameDelayL1;
227 double frameDelayR1; 226 double frameDelayR1;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 (fftSize() / 2) / static_cast<double>(sampleRate()); 353 (fftSize() / 2) / static_cast<double>(sampleRate());
355 } 354 }
356 355
357 double HRTFPanner::latencyTime() const { 356 double HRTFPanner::latencyTime() const {
358 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition to 357 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition to
359 // its tailTime of the same value. 358 // its tailTime of the same value.
360 return (fftSize() / 2) / static_cast<double>(sampleRate()); 359 return (fftSize() / 2) / static_cast<double>(sampleRate());
361 } 360 }
362 361
363 } // namespace blink 362 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/audio/AudioDestination.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698