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

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

Issue 375383002: Extending supported sample rate from 3.0KHz to 192.0KHz for OfflineAudioContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix as review direct return fftsize Created 6 years, 3 months 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 | « Source/modules/webaudio/OfflineAudioContext.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 27 matching lines...) Expand all
38 38
39 namespace blink { 39 namespace blink {
40 40
41 // The value of 2 milliseconds is larger than the largest delay which exists in any HRTFKernel from the default HRTFDatabase (0.0136 seconds). 41 // The value of 2 milliseconds is larger than the largest delay which exists in any HRTFKernel from the default HRTFDatabase (0.0136 seconds).
42 // We ASSERT the delay values used in process() with this value. 42 // We ASSERT the delay values used in process() with this value.
43 const double MaxDelayTimeSeconds = 0.002; 43 const double MaxDelayTimeSeconds = 0.002;
44 44
45 const int UninitializedAzimuth = -1; 45 const int UninitializedAzimuth = -1;
46 const unsigned RenderingQuantum = 128; 46 const unsigned RenderingQuantum = 128;
47 47
48 const size_t fftSizes[] = { 64, 128, 256, 512, 1024, 2048, 4096 };
49
48 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader) 50 HRTFPanner::HRTFPanner(float sampleRate, HRTFDatabaseLoader* databaseLoader)
49 : Panner(PanningModelHRTF) 51 : Panner(PanningModelHRTF)
50 , m_databaseLoader(databaseLoader) 52 , m_databaseLoader(databaseLoader)
51 , m_sampleRate(sampleRate) 53 , m_sampleRate(sampleRate)
52 , m_crossfadeSelection(CrossfadeSelection1) 54 , m_crossfadeSelection(CrossfadeSelection1)
53 , m_azimuthIndex1(UninitializedAzimuth) 55 , m_azimuthIndex1(UninitializedAzimuth)
54 , m_elevation1(0) 56 , m_elevation1(0)
55 , m_azimuthIndex2(UninitializedAzimuth) 57 , m_azimuthIndex2(UninitializedAzimuth)
56 , m_elevation2(0) 58 , m_elevation2(0)
57 , m_crossfadeX(0) 59 , m_crossfadeX(0)
(...skipping 14 matching lines...) Expand all
72 74
73 HRTFPanner::~HRTFPanner() 75 HRTFPanner::~HRTFPanner()
74 { 76 {
75 } 77 }
76 78
77 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate) 79 size_t HRTFPanner::fftSizeForSampleRate(float sampleRate)
78 { 80 {
79 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra mes @44.1KHz. 81 // The HRTF impulse responses (loaded as audio resources) are 512 sample-fra mes @44.1KHz.
80 // Currently, we truncate the impulse responses to half this size, but an FF T-size of twice impulse response size is needed (for convolution). 82 // Currently, we truncate the impulse responses to half this size, but an FF T-size of twice impulse response size is needed (for convolution).
81 // So for sample rates around 44.1KHz an FFT size of 512 is good. We double the FFT-size only for sample rates at least double this. 83 // So for sample rates around 44.1KHz an FFT size of 512 is good. We double the FFT-size only for sample rates at least double this.
82 ASSERT(sampleRate >= 44100 && sampleRate <= 96000.0); 84 ASSERT(sampleRate >= 3000 && sampleRate <= 192000);
83 return (sampleRate < 88200.0) ? 512 : 1024; 85
86 if (sampleRate <= 5512.5)
87 return fftSizes[0];
Raymond Toy 2014/09/05 16:19:52 Why not just return 64 instead of looking it up in
KhNo 2014/09/05 20:18:14 Sorry, I misunderstood your previous comment. I fi
88 if (sampleRate <= 11025)
89 return fftSizes[1];
90 if (sampleRate <= 22050)
91 return fftSizes[2];
92 if (sampleRate <= 44100)
93 return fftSizes[3];
94 if (sampleRate <= 88200)
95 return fftSizes[4];
Raymond Toy 2014/09/05 16:19:52 There's a difference here. In the original the FFT
KhNo 2014/09/05 20:18:14 // So for sample rates around 44.1KHz an FFT size
KhNo 2014/09/05 20:22:52 Please ignore above my comment, there is mistakes
Raymond Toy 2014/09/05 20:28:04 Ok. I'm not saying my proposal is the best way, b
96 if (sampleRate <= 176400)
97 return fftSizes[5];
98
99 return fftSizes[6];
84 } 100 }
85 101
86 void HRTFPanner::reset() 102 void HRTFPanner::reset()
87 { 103 {
88 m_convolverL1.reset(); 104 m_convolverL1.reset();
89 m_convolverR1.reset(); 105 m_convolverR1.reset();
90 m_convolverL2.reset(); 106 m_convolverL2.reset();
91 m_convolverR2.reset(); 107 m_convolverR2.reset();
92 m_delayLineL.reset(); 108 m_delayLineL.reset();
93 m_delayLineR.reset(); 109 m_delayLineR.reset();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 double HRTFPanner::latencyTime() const 320 double HRTFPanner::latencyTime() const
305 { 321 {
306 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the 322 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the
307 // same value. 323 // same value.
308 return (fftSize() / 2) / static_cast<double>(sampleRate()); 324 return (fftSize() / 2) / static_cast<double>(sampleRate());
309 } 325 }
310 326
311 } // namespace blink 327 } // namespace blink
312 328
313 #endif // ENABLE(WEB_AUDIO) 329 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/OfflineAudioContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698