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

Side by Side Diff: LayoutTests/webaudio/resources/oscillator-testing.js

Issue 209423006: WebAudio: Remove legacy support for numerical values for Oscillator types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
OLDNEW
1 // Notes about generated waveforms: 1 // Notes about generated waveforms:
2 // 2 //
3 // QUESTION: Why does the wave shape not look like the exact shape (sharp edges) ? 3 // QUESTION: Why does the wave shape not look like the exact shape (sharp edges) ?
4 // ANSWER: Because a shape with sharp edges has infinitely high frequency conten t. 4 // ANSWER: Because a shape with sharp edges has infinitely high frequency conten t.
5 // Since a digital audio signal must be band-limited based on the nyquist freque ncy (half the sample-rate) 5 // Since a digital audio signal must be band-limited based on the nyquist freque ncy (half the sample-rate)
6 // in order to avoid aliasing, this creates more rounded edges and "ringing" in the 6 // in order to avoid aliasing, this creates more rounded edges and "ringing" in the
7 // appearance of the waveform. See Nyquist-Shannon sampling theorem: 7 // appearance of the waveform. See Nyquist-Shannon sampling theorem:
8 // http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem 8 // http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem
9 // 9 //
10 // QUESTION: Why does the very end of the generated signal appear to get slightl y weaker? 10 // QUESTION: Why does the very end of the generated signal appear to get slightl y weaker?
11 // ANSWER: This is an artifact of the algorithm to avoid aliasing. 11 // ANSWER: This is an artifact of the algorithm to avoid aliasing.
12 12
13 var sampleRate = 44100.0; 13 var sampleRate = 44100.0;
14 var nyquist = 0.5 * sampleRate; 14 var nyquist = 0.5 * sampleRate;
15 var lengthInSeconds = 4; 15 var lengthInSeconds = 4;
16 var lowFrequency = 10; 16 var lowFrequency = 10;
17 var highFrequency = nyquist + 2000; // go slightly higher than nyquist to make s ure we generate silence there 17 var highFrequency = nyquist + 2000; // go slightly higher than nyquist to make s ure we generate silence there
18 var context = 0; 18 var context = 0;
19 19
20 var OSC = {
21 SINE: 0,
22 SQUARE: 1,
23 SAWTOOTH: 2,
24 TRIANGLE: 3,
25 CUSTOM: 4,
26 };
27
28 function generateExponentialOscillatorSweep(oscillatorType) { 20 function generateExponentialOscillatorSweep(oscillatorType) {
29 // Create offline audio context. 21 // Create offline audio context.
30 context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRat e); 22 context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRat e);
31 23
32 var osc = context.createOscillator(); 24 var osc = context.createOscillator();
33 if (oscillatorType == OSC.CUSTOM) { 25 if (oscillatorType == "custom") {
34 // Create a simple waveform with three Fourier coefficients. 26 // Create a simple waveform with three Fourier coefficients.
35 // Note the first values are expected to be zero (DC for coeffA and Nyqu ist for coeffB). 27 // Note the first values are expected to be zero (DC for coeffA and Nyqu ist for coeffB).
36 var coeffA = new Float32Array([0, 1, 0.5]); 28 var coeffA = new Float32Array([0, 1, 0.5]);
37 var coeffB = new Float32Array([0, 0, 0]); 29 var coeffB = new Float32Array([0, 0, 0]);
38 var wave = context.createPeriodicWave(coeffA, coeffB); 30 var wave = context.createPeriodicWave(coeffA, coeffB);
39 osc.setPeriodicWave(wave); 31 osc.setPeriodicWave(wave);
40 } else { 32 } else {
41 osc.type = oscillatorType; 33 osc.type = oscillatorType;
42 } 34 }
43 35
44 // Scale by 1/2 to better visualize the waveform and to avoid clipping past full scale. 36 // Scale by 1/2 to better visualize the waveform and to avoid clipping past full scale.
45 var gainNode = context.createGain(); 37 var gainNode = context.createGain();
46 gainNode.gain.value = 0.5; 38 gainNode.gain.value = 0.5;
47 osc.connect(gainNode); 39 osc.connect(gainNode);
48 gainNode.connect(context.destination); 40 gainNode.connect(context.destination);
49 41
50 osc.start(0); 42 osc.start(0);
51 43
52 var nyquist = 0.5 * sampleRate; 44 var nyquist = 0.5 * sampleRate;
53 osc.frequency.setValueAtTime(10, 0); 45 osc.frequency.setValueAtTime(10, 0);
54 osc.frequency.exponentialRampToValueAtTime(highFrequency, lengthInSeconds); 46 osc.frequency.exponentialRampToValueAtTime(highFrequency, lengthInSeconds);
55 47
56 context.oncomplete = finishAudioTest; 48 context.oncomplete = finishAudioTest;
57 context.startRendering(); 49 context.startRendering();
58 50
59 testRunner.waitUntilDone(); 51 testRunner.waitUntilDone();
60 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698