Please note that Speex is a lossy codec . Thus, by definition, it cannot give the same result as the encoded buffer. In addition, it is designed to encode voice. Thus, a range of 1-2 kHz will be most effective, since it expects a certain waveform. In some ways, it can be compared with JPEG technology for bitmaps.
I slightly modified your jsfiddle example so that you can play with different parameters and compare the results. Simply providing a simple sinusoid with an unknown frequency is not the proper way to test a codec. However, in this example you can see different effects on the original signal at different frequencies.
buffer1.push(Math.sin(2*Math.PI*i*frequency/sampleRate));
I think you should create an example with a recorded voice and compare the results in this case. That would be more correct.
In general, to get detailed information, you will need to study the processing of a digital signal. I canβt even provide the correct connection, because it is a whole science, and it is mathematically intense. (the only correct reading book I know is in Russian ). If someone here with a strong mathematical background can share the relevant literature for this case, I would appreciate it.
EDITOR: as Kuroi Neko mentioned, there are problems with buffer boundaries. And it seems that the state of the decoder cannot be saved, as mentioned in this post, because the library used does not support it. If you look at the source code, you will see that they use a third-party speex codec and do not provide full access to its functions. I think the best approach would be to find a decent library for speex that supports state recovery like this
source share