-
Notifications
You must be signed in to change notification settings - Fork 31
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
Outputs 32-bit float instead of signed 16-bit int #10
Comments
You can get by with something (probably slow, but fast enough for my uses) like this: function float_to_int(options) {
stream.Transform.call(this, options);
}
util.inherits(float_to_int, stream.Transform);
float_to_int.prototype._transform = function (chunk, enc, cb) {
var b = new buffer.Buffer(chunk.length/4 * 2);
for (var i=0, j=0; i<chunk.length; i+=4,j+=2) {
var f = chunk.readFloatLE(i);
f = f * 32768;
if (f > 32767) f = 32767;
if (f < -32768) f = -32768;
b.writeInt16LE(Math.floor(f), j);
}
this.push(b);
cb();
};
... SNIP ...
vorbisBuffer.pipe(new float_to_int()).pipe(audioSink); |
You could I think also use the tremor library made by Xiph.org for slower devices incapable of floating-point math (like older ARMs). It uses 16-bit signed samples:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This library uses libvorbis which only returns PCM data as 32-bit floats.
This unusual output format is unusable with several other utilities such as node-lame.
I think this library needs a routine similar to vorbisfile.c "ov_read_filter" that uses vorbis_ftoi() to correctly convert 32-bit floating points to the usual & expected signed 16-bit integers.
The text was updated successfully, but these errors were encountered: