OLD | NEW |
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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 const unsigned HRTFElevation::InterpolationFactor = 8; | 43 const unsigned HRTFElevation::InterpolationFactor = 8; |
44 const unsigned HRTFElevation::NumberOfTotalAzimuths = | 44 const unsigned HRTFElevation::NumberOfTotalAzimuths = |
45 NumberOfRawAzimuths * InterpolationFactor; | 45 NumberOfRawAzimuths * InterpolationFactor; |
46 | 46 |
47 // Total number of components of an HRTF database. | 47 // Total number of components of an HRTF database. |
48 const size_t TotalNumberOfResponses = 240; | 48 const size_t TotalNumberOfResponses = 240; |
49 | 49 |
50 // Number of frames in an individual impulse response. | 50 // Number of frames in an individual impulse response. |
51 const size_t ResponseFrameSize = 256; | 51 const size_t ResponseFrameSize = 256; |
52 | 52 |
53 // Sample-rate of the spatialization impulse responses as stored in the resource
file. | 53 // Sample-rate of the spatialization impulse responses as stored in the resource |
54 // The impulse responses may be resampled to a different sample-rate (depending
on the audio hardware) when they are loaded. | 54 // file. The impulse responses may be resampled to a different sample-rate |
| 55 // (depending on the audio hardware) when they are loaded. |
55 const float ResponseSampleRate = 44100; | 56 const float ResponseSampleRate = 44100; |
56 | 57 |
57 #if USE(CONCATENATED_IMPULSE_RESPONSES) | 58 #if USE(CONCATENATED_IMPULSE_RESPONSES) |
58 | 59 |
59 // This table maps the index into the elevation table with the corresponding ang
le. See | 60 // This table maps the index into the elevation table with the corresponding |
60 // https://bugs.webkit.org/show_bug.cgi?id=98294#c9 for the elevation angles and
their order in the | 61 // angle. See https://bugs.webkit.org/show_bug.cgi?id=98294#c9 for the |
61 // concatenated response. | 62 // elevation angles and their order in the concatenated response. |
62 const int ElevationIndexTableSize = 10; | 63 const int ElevationIndexTableSize = 10; |
63 const int ElevationIndexTable[ElevationIndexTableSize] = { | 64 const int ElevationIndexTable[ElevationIndexTableSize] = { |
64 0, 15, 30, 45, 60, 75, 90, 315, 330, 345}; | 65 0, 15, 30, 45, 60, 75, 90, 315, 330, 345}; |
65 | 66 |
66 // Lazily load a concatenated HRTF database for given subject and store it in a | 67 // Lazily load a concatenated HRTF database for given subject and store it in a |
67 // local hash table to ensure quick efficient future retrievals. | 68 // local hash table to ensure quick efficient future retrievals. |
68 static PassRefPtr<AudioBus> getConcatenatedImpulseResponsesForSubject( | 69 static PassRefPtr<AudioBus> getConcatenatedImpulseResponsesForSubject( |
69 const String& subjectName) { | 70 const String& subjectName) { |
70 typedef HashMap<String, RefPtr<AudioBus>> AudioBusMap; | 71 typedef HashMap<String, RefPtr<AudioBus>> AudioBusMap; |
71 DEFINE_THREAD_SAFE_STATIC_LOCAL(AudioBusMap, audioBusMap, new AudioBusMap()); | 72 DEFINE_THREAD_SAFE_STATIC_LOCAL(AudioBusMap, audioBusMap, new AudioBusMap()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 ASSERT(isAzimuthGood); | 118 ASSERT(isAzimuthGood); |
118 if (!isAzimuthGood) | 119 if (!isAzimuthGood) |
119 return false; | 120 return false; |
120 | 121 |
121 bool isElevationGood = | 122 bool isElevationGood = |
122 elevation >= -45 && elevation <= 90 && (elevation / 15) * 15 == elevation; | 123 elevation >= -45 && elevation <= 90 && (elevation / 15) * 15 == elevation; |
123 ASSERT(isElevationGood); | 124 ASSERT(isElevationGood); |
124 if (!isElevationGood) | 125 if (!isElevationGood) |
125 return false; | 126 return false; |
126 | 127 |
127 // Construct the resource name from the subject name, azimuth, and elevation,
for example: | 128 // Construct the resource name from the subject name, azimuth, and elevation, |
| 129 // for example: |
128 // "IRC_Composite_C_R0195_T015_P000" | 130 // "IRC_Composite_C_R0195_T015_P000" |
129 // Note: the passed in subjectName is not a string passed in via JavaScript or
the web. | 131 // Note: the passed in subjectName is not a string passed in via JavaScript or |
130 // It's passed in as an internal ASCII identifier and is an implementation det
ail. | 132 // the web. It's passed in as an internal ASCII identifier and is an |
| 133 // implementation detail. |
131 int positiveElevation = elevation < 0 ? elevation + 360 : elevation; | 134 int positiveElevation = elevation < 0 ? elevation + 360 : elevation; |
132 | 135 |
133 #if USE(CONCATENATED_IMPULSE_RESPONSES) | 136 #if USE(CONCATENATED_IMPULSE_RESPONSES) |
134 RefPtr<AudioBus> bus(getConcatenatedImpulseResponsesForSubject(subjectName)); | 137 RefPtr<AudioBus> bus(getConcatenatedImpulseResponsesForSubject(subjectName)); |
135 | 138 |
136 if (!bus) | 139 if (!bus) |
137 return false; | 140 return false; |
138 | 141 |
139 // Just sequentially search the table to find the correct index. | 142 // Just sequentially search the table to find the correct index. |
140 int elevationIndex = -1; | 143 int elevationIndex = -1; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 ASSERT(isBusGood); | 201 ASSERT(isBusGood); |
199 if (!isBusGood) | 202 if (!isBusGood) |
200 return false; | 203 return false; |
201 | 204 |
202 AudioChannel* leftEarImpulseResponse = | 205 AudioChannel* leftEarImpulseResponse = |
203 impulseResponse->channelByType(AudioBus::ChannelLeft); | 206 impulseResponse->channelByType(AudioBus::ChannelLeft); |
204 AudioChannel* rightEarImpulseResponse = | 207 AudioChannel* rightEarImpulseResponse = |
205 impulseResponse->channelByType(AudioBus::ChannelRight); | 208 impulseResponse->channelByType(AudioBus::ChannelRight); |
206 #endif | 209 #endif |
207 | 210 |
208 // Note that depending on the fftSize returned by the panner, we may be trunca
ting the impulse response we just loaded in. | 211 // Note that depending on the fftSize returned by the panner, we may be |
| 212 // truncating the impulse response we just loaded in. |
209 const size_t fftSize = HRTFPanner::fftSizeForSampleRate(sampleRate); | 213 const size_t fftSize = HRTFPanner::fftSizeForSampleRate(sampleRate); |
210 kernelL = HRTFKernel::create(leftEarImpulseResponse, fftSize, sampleRate); | 214 kernelL = HRTFKernel::create(leftEarImpulseResponse, fftSize, sampleRate); |
211 kernelR = HRTFKernel::create(rightEarImpulseResponse, fftSize, sampleRate); | 215 kernelR = HRTFKernel::create(rightEarImpulseResponse, fftSize, sampleRate); |
212 | 216 |
213 return true; | 217 return true; |
214 } | 218 } |
215 | 219 |
216 // The range of elevations for the IRCAM impulse responses varies depending on a
zimuth, but the minimum elevation appears to always be -45. | 220 // The range of elevations for the IRCAM impulse responses varies depending on |
| 221 // azimuth, but the minimum elevation appears to always be -45. |
217 // | 222 // |
218 // Here's how it goes: | 223 // Here's how it goes: |
219 static int maxElevations[] = { | 224 static int maxElevations[] = { |
220 // Azimuth | 225 // Azimuth |
221 // | 226 // |
222 90, // 0 | 227 90, // 0 |
223 45, // 15 | 228 45, // 15 |
224 60, // 30 | 229 60, // 30 |
225 45, // 45 | 230 45, // 45 |
226 75, // 60 | 231 75, // 60 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay(); | 374 double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay(); |
370 | 375 |
371 // Linearly interpolate delays. | 376 // Linearly interpolate delays. |
372 frameDelayL = | 377 frameDelayL = |
373 (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay2L; | 378 (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay2L; |
374 frameDelayR = | 379 frameDelayR = |
375 (1.0 - azimuthBlend) * frameDelayR + azimuthBlend * frameDelay2R; | 380 (1.0 - azimuthBlend) * frameDelayR + azimuthBlend * frameDelay2R; |
376 } | 381 } |
377 | 382 |
378 } // namespace blink | 383 } // namespace blink |
OLD | NEW |