| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 imag->data(), disableNormalization, exceptionState); | 92 imag->data(), disableNormalization, exceptionState); |
| 93 } | 93 } |
| 94 | 94 |
| 95 PeriodicWave* PeriodicWave::create(BaseAudioContext* context, | 95 PeriodicWave* PeriodicWave::create(BaseAudioContext* context, |
| 96 const PeriodicWaveOptions& options, | 96 const PeriodicWaveOptions& options, |
| 97 ExceptionState& exceptionState) { | 97 ExceptionState& exceptionState) { |
| 98 bool normalize = options.hasDisableNormalization() | 98 bool normalize = options.hasDisableNormalization() |
| 99 ? options.disableNormalization() | 99 ? options.disableNormalization() |
| 100 : false; | 100 : false; |
| 101 | 101 |
| 102 if (!options.hasReal() && !options.hasImag()) { | |
| 103 exceptionState.throwDOMException( | |
| 104 InvalidStateError, | |
| 105 "At least one of real and imag members must be specified."); | |
| 106 return nullptr; | |
| 107 } | |
| 108 | |
| 109 Vector<float> realCoef; | 102 Vector<float> realCoef; |
| 110 Vector<float> imagCoef; | 103 Vector<float> imagCoef; |
| 111 | 104 |
| 112 if (options.hasReal()) { | 105 if (options.hasReal()) { |
| 113 realCoef = options.real(); | 106 realCoef = options.real(); |
| 114 if (options.hasImag()) | 107 if (options.hasImag()) |
| 115 imagCoef = options.imag(); | 108 imagCoef = options.imag(); |
| 116 else | 109 else |
| 117 imagCoef.resize(realCoef.size()); | 110 imagCoef.resize(realCoef.size()); |
| 118 } else { | 111 } else if (options.hasImag()) { |
| 119 // We know real is not given, so imag must exist (because we checked for | 112 // |real| not given, but we have |imag|. |
| 120 // this above). | |
| 121 imagCoef = options.imag(); | 113 imagCoef = options.imag(); |
| 122 realCoef.resize(imagCoef.size()); | 114 realCoef.resize(imagCoef.size()); |
| 115 } else { |
| 116 // Neither |real| nor |imag| given. Return an object that would |
| 117 // generate a sine wave, which means real = [0,0], and imag = [0, 1] |
| 118 realCoef.resize(2); |
| 119 imagCoef.resize(2); |
| 120 imagCoef[1] = 1; |
| 123 } | 121 } |
| 124 | 122 |
| 125 return create(*context, realCoef.size(), realCoef.data(), imagCoef.size(), | 123 return create(*context, realCoef.size(), realCoef.data(), imagCoef.size(), |
| 126 imagCoef.data(), normalize, exceptionState); | 124 imagCoef.data(), normalize, exceptionState); |
| 127 } | 125 } |
| 128 | 126 |
| 129 PeriodicWave* PeriodicWave::createSine(float sampleRate) { | 127 PeriodicWave* PeriodicWave::createSine(float sampleRate) { |
| 130 PeriodicWave* periodicWave = new PeriodicWave(sampleRate); | 128 PeriodicWave* periodicWave = new PeriodicWave(sampleRate); |
| 131 periodicWave->generateBasicWaveform(OscillatorHandler::SINE); | 129 periodicWave->generateBasicWaveform(OscillatorHandler::SINE); |
| 132 return periodicWave; | 130 return periodicWave; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 395 } |
| 398 | 396 |
| 399 realP[n] = 0; | 397 realP[n] = 0; |
| 400 imagP[n] = b; | 398 imagP[n] = b; |
| 401 } | 399 } |
| 402 | 400 |
| 403 createBandLimitedTables(realP, imagP, halfSize, false); | 401 createBandLimitedTables(realP, imagP, halfSize, false); |
| 404 } | 402 } |
| 405 | 403 |
| 406 } // namespace blink | 404 } // namespace blink |
| OLD | NEW |