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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/PeriodicWave.cpp

Issue 2807673002: createPeriodicWave parameters are sequence<float> (Closed)
Patch Set: Rebaseline test Created 3 years, 8 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 | « third_party/WebKit/Source/modules/webaudio/PeriodicWave.h ('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) 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
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,
60 const float* imag,
61 bool disable_normalization, 59 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* periodic_wave = new PeriodicWave(context.sampleRate());
80 periodic_wave->CreateBandLimitedTables(real, imag, real_length, 78 periodic_wave->CreateBandLimitedTables(real.Data(), imag.Data(), real.size(),
81 disable_normalization); 79 disable_normalization);
82 return periodic_wave; 80 return periodic_wave;
83 } 81 }
84 82
85 PeriodicWave* PeriodicWave::Create(BaseAudioContext& context,
86 NotShared<DOMFloat32Array> real,
87 NotShared<DOMFloat32Array> imag,
88 bool disable_normalization,
89 ExceptionState& exception_state) {
90 DCHECK(IsMainThread());
91
92 return Create(context, real.View()->length(), real.View()->Data(),
93 imag.View()->length(), imag.View()->Data(),
94 disable_normalization, exception_state);
95 }
96
97 PeriodicWave* PeriodicWave::Create(BaseAudioContext* context, 83 PeriodicWave* PeriodicWave::Create(BaseAudioContext* context,
98 const PeriodicWaveOptions& options, 84 const PeriodicWaveOptions& options,
99 ExceptionState& exception_state) { 85 ExceptionState& exception_state) {
100 bool normalize = options.hasDisableNormalization() 86 bool normalize = options.hasDisableNormalization()
101 ? options.disableNormalization() 87 ? options.disableNormalization()
102 : false; 88 : false;
103 89
104 Vector<float> real_coef; 90 Vector<float> real_coef;
105 Vector<float> imag_coef; 91 Vector<float> imag_coef;
106 92
107 if (options.hasReal()) { 93 if (options.hasReal()) {
108 real_coef = options.real(); 94 real_coef = options.real();
109 if (options.hasImag()) 95 if (options.hasImag())
110 imag_coef = options.imag(); 96 imag_coef = options.imag();
111 else 97 else
112 imag_coef.Resize(real_coef.size()); 98 imag_coef.Resize(real_coef.size());
113 } else if (options.hasImag()) { 99 } else if (options.hasImag()) {
114 // |real| not given, but we have |imag|. 100 // |real| not given, but we have |imag|.
115 imag_coef = options.imag(); 101 imag_coef = options.imag();
116 real_coef.Resize(imag_coef.size()); 102 real_coef.Resize(imag_coef.size());
117 } else { 103 } else {
118 // Neither |real| nor |imag| given. Return an object that would 104 // Neither |real| nor |imag| given. Return an object that would
119 // 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]
120 real_coef.Resize(2); 106 real_coef.Resize(2);
121 imag_coef.Resize(2); 107 imag_coef.Resize(2);
122 imag_coef[1] = 1; 108 imag_coef[1] = 1;
123 } 109 }
124 110
125 return Create(*context, real_coef.size(), real_coef.Data(), imag_coef.size(), 111 return Create(*context, real_coef, imag_coef, normalize, exception_state);
126 imag_coef.Data(), normalize, exception_state);
127 } 112 }
128 113
129 PeriodicWave* PeriodicWave::CreateSine(float sample_rate) { 114 PeriodicWave* PeriodicWave::CreateSine(float sample_rate) {
130 PeriodicWave* periodic_wave = new PeriodicWave(sample_rate); 115 PeriodicWave* periodic_wave = new PeriodicWave(sample_rate);
131 periodic_wave->GenerateBasicWaveform(OscillatorHandler::SINE); 116 periodic_wave->GenerateBasicWaveform(OscillatorHandler::SINE);
132 return periodic_wave; 117 return periodic_wave;
133 } 118 }
134 119
135 PeriodicWave* PeriodicWave::CreateSquare(float sample_rate) { 120 PeriodicWave* PeriodicWave::CreateSquare(float sample_rate) {
136 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
398 } 383 }
399 384
400 real_p[n] = 0; 385 real_p[n] = 0;
401 imag_p[n] = b; 386 imag_p[n] = b;
402 } 387 }
403 388
404 CreateBandLimitedTables(real_p, imag_p, half_size, false); 389 CreateBandLimitedTables(real_p, imag_p, half_size, false);
405 } 390 }
406 391
407 } // namespace blink 392 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/PeriodicWave.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698