Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can it compress Int16Array WebAudio pcm data? #51

Open
Fallsleep opened this issue Jun 1, 2017 · 2 comments
Open

Can it compress Int16Array WebAudio pcm data? #51

Fallsleep opened this issue Jun 1, 2017 · 2 comments

Comments

@Fallsleep
Copy link

I want to compress the pcm data produce by WebAudio API, it is Int16Array.

Can I use zlib.js?

@CWBudde
Copy link

CWBudde commented Jul 11, 2017

It should be possible to use the underlying array buffer and cast it to an UInt8Array.

Something as simple as

var a = new UInt8Array(YourInt16Array);

should already do the trick.

However, speaking of the WebAudio API (where the data is often available as Float32Array), it might make sense to use a different intermediate representation. Personally I have made success converting the data into something like a Float16Array by using the inofficial half point floating point format where the converted bytes can be stored directly as a UInt8Array. Conversion from floating point to floating point format will better preserve the quality and suits better for audio (where the ear operates in a similar non-linear fashion as the exponential floating point format).

@Fallsleep
Copy link
Author

Fallsleep commented Jul 27, 2017

I tried to compress pcm data such as :

var udata = new Uint8Array(data);// data is the pcm audio data
var gzip = new Zlib.Gzip(udata);
var udatac = gzip.compress();
data = udatac.buffer;
xhr.send(data);

For the code above, I got http://wx4.sinaimg.cn/large/715d71fdgy1fhyi6x3kpkj206x062mxl.jpg this result.The compressed Uint8Array's byteLength and the buffer's byteLength not the same. Should I slice it myself? Or I done something wrong? I think if the origin data were not enough? I'll try it tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants