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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 const String& subjectName, | 254 const String& subjectName, |
255 int elevation, | 255 int elevation, |
256 float sampleRate) { | 256 float sampleRate) { |
257 bool isElevationGood = | 257 bool isElevationGood = |
258 elevation >= -45 && elevation <= 90 && (elevation / 15) * 15 == elevation; | 258 elevation >= -45 && elevation <= 90 && (elevation / 15) * 15 == elevation; |
259 ASSERT(isElevationGood); | 259 ASSERT(isElevationGood); |
260 if (!isElevationGood) | 260 if (!isElevationGood) |
261 return nullptr; | 261 return nullptr; |
262 | 262 |
263 std::unique_ptr<HRTFKernelList> kernelListL = | 263 std::unique_ptr<HRTFKernelList> kernelListL = |
264 makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); | 264 WTF::makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); |
265 std::unique_ptr<HRTFKernelList> kernelListR = | 265 std::unique_ptr<HRTFKernelList> kernelListR = |
266 makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); | 266 WTF::makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); |
267 | 267 |
268 // Load convolution kernels from HRTF files. | 268 // Load convolution kernels from HRTF files. |
269 int interpolatedIndex = 0; | 269 int interpolatedIndex = 0; |
270 for (unsigned rawIndex = 0; rawIndex < NumberOfRawAzimuths; ++rawIndex) { | 270 for (unsigned rawIndex = 0; rawIndex < NumberOfRawAzimuths; ++rawIndex) { |
271 // Don't let elevation exceed maximum for this azimuth. | 271 // Don't let elevation exceed maximum for this azimuth. |
272 int maxElevation = maxElevations[rawIndex]; | 272 int maxElevation = maxElevations[rawIndex]; |
273 int actualElevation = std::min(elevation, maxElevation); | 273 int actualElevation = std::min(elevation, maxElevation); |
274 | 274 |
275 bool success = calculateKernelsForAzimuthElevation( | 275 bool success = calculateKernelsForAzimuthElevation( |
276 rawIndex * AzimuthSpacing, actualElevation, sampleRate, subjectName, | 276 rawIndex * AzimuthSpacing, actualElevation, sampleRate, subjectName, |
(...skipping 13 matching lines...) Expand all Loading... |
290 float x = | 290 float x = |
291 float(jj) / float(InterpolationFactor); // interpolate from 0 -> 1 | 291 float(jj) / float(InterpolationFactor); // interpolate from 0 -> 1 |
292 | 292 |
293 (*kernelListL)[i + jj] = HRTFKernel::createInterpolatedKernel( | 293 (*kernelListL)[i + jj] = HRTFKernel::createInterpolatedKernel( |
294 kernelListL->at(i).get(), kernelListL->at(j).get(), x); | 294 kernelListL->at(i).get(), kernelListL->at(j).get(), x); |
295 (*kernelListR)[i + jj] = HRTFKernel::createInterpolatedKernel( | 295 (*kernelListR)[i + jj] = HRTFKernel::createInterpolatedKernel( |
296 kernelListR->at(i).get(), kernelListR->at(j).get(), x); | 296 kernelListR->at(i).get(), kernelListR->at(j).get(), x); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 std::unique_ptr<HRTFElevation> hrtfElevation = wrapUnique(new HRTFElevation( | 300 std::unique_ptr<HRTFElevation> hrtfElevation = WTF::wrapUnique( |
301 std::move(kernelListL), std::move(kernelListR), elevation, sampleRate)); | 301 new HRTFElevation(std::move(kernelListL), std::move(kernelListR), |
| 302 elevation, sampleRate)); |
302 return hrtfElevation; | 303 return hrtfElevation; |
303 } | 304 } |
304 | 305 |
305 std::unique_ptr<HRTFElevation> HRTFElevation::createByInterpolatingSlices( | 306 std::unique_ptr<HRTFElevation> HRTFElevation::createByInterpolatingSlices( |
306 HRTFElevation* hrtfElevation1, | 307 HRTFElevation* hrtfElevation1, |
307 HRTFElevation* hrtfElevation2, | 308 HRTFElevation* hrtfElevation2, |
308 float x, | 309 float x, |
309 float sampleRate) { | 310 float sampleRate) { |
310 ASSERT(hrtfElevation1 && hrtfElevation2); | 311 ASSERT(hrtfElevation1 && hrtfElevation2); |
311 if (!hrtfElevation1 || !hrtfElevation2) | 312 if (!hrtfElevation1 || !hrtfElevation2) |
312 return nullptr; | 313 return nullptr; |
313 | 314 |
314 ASSERT(x >= 0.0 && x < 1.0); | 315 ASSERT(x >= 0.0 && x < 1.0); |
315 | 316 |
316 std::unique_ptr<HRTFKernelList> kernelListL = | 317 std::unique_ptr<HRTFKernelList> kernelListL = |
317 makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); | 318 WTF::makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); |
318 std::unique_ptr<HRTFKernelList> kernelListR = | 319 std::unique_ptr<HRTFKernelList> kernelListR = |
319 makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); | 320 WTF::makeUnique<HRTFKernelList>(NumberOfTotalAzimuths); |
320 | 321 |
321 HRTFKernelList* kernelListL1 = hrtfElevation1->kernelListL(); | 322 HRTFKernelList* kernelListL1 = hrtfElevation1->kernelListL(); |
322 HRTFKernelList* kernelListR1 = hrtfElevation1->kernelListR(); | 323 HRTFKernelList* kernelListR1 = hrtfElevation1->kernelListR(); |
323 HRTFKernelList* kernelListL2 = hrtfElevation2->kernelListL(); | 324 HRTFKernelList* kernelListL2 = hrtfElevation2->kernelListL(); |
324 HRTFKernelList* kernelListR2 = hrtfElevation2->kernelListR(); | 325 HRTFKernelList* kernelListR2 = hrtfElevation2->kernelListR(); |
325 | 326 |
326 // Interpolate kernels of corresponding azimuths of the two elevations. | 327 // Interpolate kernels of corresponding azimuths of the two elevations. |
327 for (unsigned i = 0; i < NumberOfTotalAzimuths; ++i) { | 328 for (unsigned i = 0; i < NumberOfTotalAzimuths; ++i) { |
328 (*kernelListL)[i] = HRTFKernel::createInterpolatedKernel( | 329 (*kernelListL)[i] = HRTFKernel::createInterpolatedKernel( |
329 kernelListL1->at(i).get(), kernelListL2->at(i).get(), x); | 330 kernelListL1->at(i).get(), kernelListL2->at(i).get(), x); |
330 (*kernelListR)[i] = HRTFKernel::createInterpolatedKernel( | 331 (*kernelListR)[i] = HRTFKernel::createInterpolatedKernel( |
331 kernelListR1->at(i).get(), kernelListR2->at(i).get(), x); | 332 kernelListR1->at(i).get(), kernelListR2->at(i).get(), x); |
332 } | 333 } |
333 | 334 |
334 // Interpolate elevation angle. | 335 // Interpolate elevation angle. |
335 double angle = (1.0 - x) * hrtfElevation1->elevationAngle() + | 336 double angle = (1.0 - x) * hrtfElevation1->elevationAngle() + |
336 x * hrtfElevation2->elevationAngle(); | 337 x * hrtfElevation2->elevationAngle(); |
337 | 338 |
338 std::unique_ptr<HRTFElevation> hrtfElevation = wrapUnique( | 339 std::unique_ptr<HRTFElevation> hrtfElevation = WTF::wrapUnique( |
339 new HRTFElevation(std::move(kernelListL), std::move(kernelListR), | 340 new HRTFElevation(std::move(kernelListL), std::move(kernelListR), |
340 static_cast<int>(angle), sampleRate)); | 341 static_cast<int>(angle), sampleRate)); |
341 return hrtfElevation; | 342 return hrtfElevation; |
342 } | 343 } |
343 | 344 |
344 void HRTFElevation::getKernelsFromAzimuth(double azimuthBlend, | 345 void HRTFElevation::getKernelsFromAzimuth(double azimuthBlend, |
345 unsigned azimuthIndex, | 346 unsigned azimuthIndex, |
346 HRTFKernel*& kernelL, | 347 HRTFKernel*& kernelL, |
347 HRTFKernel*& kernelR, | 348 HRTFKernel*& kernelR, |
348 double& frameDelayL, | 349 double& frameDelayL, |
(...skipping 25 matching lines...) Expand all Loading... |
374 double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay(); | 375 double frameDelay2R = m_kernelListR->at(azimuthIndex2)->frameDelay(); |
375 | 376 |
376 // Linearly interpolate delays. | 377 // Linearly interpolate delays. |
377 frameDelayL = | 378 frameDelayL = |
378 (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay2L; | 379 (1.0 - azimuthBlend) * frameDelayL + azimuthBlend * frameDelay2L; |
379 frameDelayR = | 380 frameDelayR = |
380 (1.0 - azimuthBlend) * frameDelayR + azimuthBlend * frameDelay2R; | 381 (1.0 - azimuthBlend) * frameDelayR + azimuthBlend * frameDelay2R; |
381 } | 382 } |
382 | 383 |
383 } // namespace blink | 384 } // namespace blink |
OLD | NEW |