Here is what I am trying to do: I would like to take a WAV file (for example, let's say https://freesound.org/people/thefsoundman/sounds/118513/, which is 109KB). I want to analyze this WAV file using SPEAR, which I've also done, and produced this output:
Now I want to use this data to play an approximation of the sound, using Web Audio API, by creating an oscillator using a periodic wave. Something like this:
let real = new Float32Array([ /* lots of numbers */ ]);
let imag = new Float32Array([ /* lots of numbers */ ]);
let wave = ctx.createPeriodicWave(real, imag);
let o = ctx.createOscillator();
o.setPeriodicWave(wave);
o.frequency.value = /* ? */;
I'm at a loss as to how to convert the output I'm seeing in SPEAR (or any other equivalent tool you might suggest) into the "fourier coefficients" (cosine and sine values) expected by the createPeriodicWave
function. I'm also unsure whether the question I'm asking even makes sense, and whether it's remotely possible to represent a generic WAV file as a periodic wave table like this.
(In case you ask: the goal here is to determine the smallest possible size it would take to play a sound "close to" the original sound. I realize I could shrink 109KB down considerably by going to a mono, 11KHz WAV, compressing to MP3, etc., but I would prefer to represent as a series of numbers if possible.)
Any sound experts out there that can give me a next step?