1

I have a question regarding the PeriodicWave in Web Audio API. Take a look at the following code:

https://slack-files.com/T04PVA27V-F051SS7LD-a71e14c8a2

For every iteration of the script processor, I get different values for the channel data 0. Isn't it supposed to get the same time frame at each iteration? After all, it is performing the IFFT for the provided real and imaginary values.

Steps: 1) Open the browser inspector. 2) Copy that code into the inspector console. 3) Put a breakpoint inside the script processor. 4) Check the values of the input buffer.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
echo66
  • 113
  • 1
  • 2
  • 6
  • 2
    Posting the relevant code here as well as documentation on what you have tried will get much better results than a link. – rfornal May 26 '15 at 00:54
  • 2
    Steps: 1) Open the browser inspector. 2) Copy that code into the inspector console. 3) Put a breakpoint inside the script processor. 4) Check the values of the input buffer. – echo66 May 26 '15 at 00:59

2 Answers2

2

Echo66: you don't ever set the osc.frequency.value; it's playing back at A440. I don't think you should expect the same values at each iteration then.

cwilso
  • 13,610
  • 1
  • 30
  • 35
2

Why not just use an offline context to capture the desired IFFT? Something like IFFT via PeriodicWave and OfflineAudioContext

var c = new OfflineAudioContext(1, 128, 48000)
var r = new Float32Array(128)
var i = new Float32Array(128)

// Set up r/i for a plain cos wave.
r[1] = 1;

var o = c.createOscillator();
var w = c.createPeriodicWave(r, i);

o.setPeriodicWave(w);
o.connect(c.destination);
o.start();

// The result should be a cos(2*pi*440/48000*k), k = 0, 1,..., 127.
var result;

c.startRendering().then(function (b) {result = b; });
Raymond Toy
  • 5,490
  • 10
  • 13
  • 1
    The reported issue regarding the usage of script processor + offline context still exists (http://jsfiddle.net/bestiole/E3rSx/ in chrome/chromium, you can't have all frames processed). – echo66 May 26 '15 at 20:19
  • 1
    What is the reported issue? Is it a chrome bug that has been filed? And what does script processor + offline context have to do with my example? I did to a quick test and the rendered output is the expected cos wave. Without some context, I don't understand what your jsfiddle is supposed to be telling me. – Raymond Toy May 26 '15 at 22:59