| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 // The max length of a periodic wave. This must be a power of two greater than | 48 // The max length of a periodic wave. This must be a power of two greater than |
| 49 // or equal to 2048 and must be supported by the FFT routines. | 49 // or equal to 2048 and must be supported by the FFT routines. |
| 50 const unsigned kMaxPeriodicWaveSize = 16384; | 50 const unsigned kMaxPeriodicWaveSize = 16384; |
| 51 | 51 |
| 52 const float kCentsPerRange = 1200 / kNumberOfOctaveBands; | 52 const float kCentsPerRange = 1200 / kNumberOfOctaveBands; |
| 53 | 53 |
| 54 using namespace VectorMath; | 54 using namespace VectorMath; |
| 55 | 55 |
| 56 PeriodicWave* PeriodicWave::Create(BaseAudioContext& context, | 56 PeriodicWave* PeriodicWave::Create(BaseAudioContext& context, |
| 57 size_t real_length, | 57 const Vector<float>& real, |
| 58 const float* real, | 58 const Vector<float>& imag, |
| 59 size_t imag_length, | 59 bool disableNormalization, |
| 60 const float* imag, | |
| 61 bool disable_normalization, | |
| 62 ExceptionState& exception_state) { | 60 ExceptionState& exception_state) { |
| 63 DCHECK(IsMainThread()); | 61 DCHECK(IsMainThread()); |
| 64 | 62 |
| 65 if (context.IsContextClosed()) { | 63 if (context.IsContextClosed()) { |
| 66 context.ThrowExceptionForClosedState(exception_state); | 64 context.ThrowExceptionForClosedState(exception_state); |
| 67 return nullptr; | 65 return nullptr; |
| 68 } | 66 } |
| 69 | 67 |
| 70 if (real_length != imag_length) { | 68 if (real.size() != imag.size()) { |
| 71 exception_state.ThrowDOMException( | 69 exception_state.ThrowDOMException( |
| 72 kIndexSizeError, "length of real array (" + | 70 kIndexSizeError, "length of real array (" + |
| 73 String::Number(real_length) + | 71 String::Number(real.size()) + |
| 74 ") and length of imaginary array (" + | 72 ") and length of imaginary array (" + |
| 75 String::Number(imag_length) + ") must match."); | 73 String::Number(imag.size()) + ") must match."); |
| 76 return nullptr; | 74 return nullptr; |
| 77 } | 75 } |
| 78 | 76 |
| 79 PeriodicWave* periodic_wave = new PeriodicWave(context.sampleRate()); | 77 PeriodicWave* periodicWave = new PeriodicWave(context.sampleRate()); |
| 80 periodic_wave->CreateBandLimitedTables(real, imag, real_length, | 78 periodicWave->CreateBandLimitedTables(real.Data(), imag.Data(), real.size(), |
| 81 disable_normalization); | 79 disableNormalization); |
| 82 return periodic_wave; | 80 return periodicWave; |
| 83 } | |
| 84 | |
| 85 PeriodicWave* PeriodicWave::Create(BaseAudioContext& context, | |
| 86 DOMFloat32Array* real, | |
| 87 DOMFloat32Array* imag, | |
| 88 bool disable_normalization, | |
| 89 ExceptionState& exception_state) { | |
| 90 DCHECK(IsMainThread()); | |
| 91 | |
| 92 return Create(context, real->length(), real->Data(), imag->length(), | |
| 93 imag->Data(), disable_normalization, exception_state); | |
| 94 } | 81 } |
| 95 | 82 |
| 96 PeriodicWave* PeriodicWave::Create(BaseAudioContext* context, | 83 PeriodicWave* PeriodicWave::Create(BaseAudioContext* context, |
| 97 const PeriodicWaveOptions& options, | 84 const PeriodicWaveOptions& options, |
| 98 ExceptionState& exception_state) { | 85 ExceptionState& exception_state) { |
| 99 bool normalize = options.hasDisableNormalization() | 86 bool normalize = options.hasDisableNormalization() |
| 100 ? options.disableNormalization() | 87 ? options.disableNormalization() |
| 101 : false; | 88 : false; |
| 102 | 89 |
| 103 Vector<float> real_coef; | 90 Vector<float> real_coef; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 imag_coef = options.imag(); | 101 imag_coef = options.imag(); |
| 115 real_coef.Resize(imag_coef.size()); | 102 real_coef.Resize(imag_coef.size()); |
| 116 } else { | 103 } else { |
| 117 // Neither |real| nor |imag| given. Return an object that would | 104 // Neither |real| nor |imag| given. Return an object that would |
| 118 // generate a sine wave, which means real = [0,0], and imag = [0, 1] | 105 // generate a sine wave, which means real = [0,0], and imag = [0, 1] |
| 119 real_coef.Resize(2); | 106 real_coef.Resize(2); |
| 120 imag_coef.Resize(2); | 107 imag_coef.Resize(2); |
| 121 imag_coef[1] = 1; | 108 imag_coef[1] = 1; |
| 122 } | 109 } |
| 123 | 110 |
| 124 return Create(*context, real_coef.size(), real_coef.Data(), imag_coef.size(), | 111 return Create(*context, real_coef, imag_coef, normalize, exception_state); |
| 125 imag_coef.Data(), normalize, exception_state); | |
| 126 } | 112 } |
| 127 | 113 |
| 128 PeriodicWave* PeriodicWave::CreateSine(float sample_rate) { | 114 PeriodicWave* PeriodicWave::CreateSine(float sample_rate) { |
| 129 PeriodicWave* periodic_wave = new PeriodicWave(sample_rate); | 115 PeriodicWave* periodic_wave = new PeriodicWave(sample_rate); |
| 130 periodic_wave->GenerateBasicWaveform(OscillatorHandler::SINE); | 116 periodic_wave->GenerateBasicWaveform(OscillatorHandler::SINE); |
| 131 return periodic_wave; | 117 return periodic_wave; |
| 132 } | 118 } |
| 133 | 119 |
| 134 PeriodicWave* PeriodicWave::CreateSquare(float sample_rate) { | 120 PeriodicWave* PeriodicWave::CreateSquare(float sample_rate) { |
| 135 PeriodicWave* periodic_wave = new PeriodicWave(sample_rate); | 121 PeriodicWave* periodic_wave = new PeriodicWave(sample_rate); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 383 } |
| 398 | 384 |
| 399 real_p[n] = 0; | 385 real_p[n] = 0; |
| 400 imag_p[n] = b; | 386 imag_p[n] = b; |
| 401 } | 387 } |
| 402 | 388 |
| 403 CreateBandLimitedTables(real_p, imag_p, half_size, false); | 389 CreateBandLimitedTables(real_p, imag_p, half_size, false); |
| 404 } | 390 } |
| 405 | 391 |
| 406 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |