Implement int24 for bitDepth24
This commit is contained in:
parent
797d1f28a0
commit
6f1fcefe69
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ results
|
||||
|
||||
npm-debug.log
|
||||
node_modules
|
||||
.idea
|
||||
|
22
lib/input.js
22
lib/input.js
@ -1,6 +1,7 @@
|
||||
var
|
||||
Writable = require('stream').Writable,
|
||||
util = require('util')
|
||||
util = require('util'),
|
||||
int24 = require('int24')
|
||||
;
|
||||
|
||||
function Input(args) {
|
||||
@ -25,6 +26,15 @@ function Input(args) {
|
||||
this.writeSample = this.buffer.writeInt32LE;
|
||||
this.sampleByteLength = 4;
|
||||
}
|
||||
else if (args.bitDepth == 24) {
|
||||
this.readSample = function (offset) {
|
||||
return int24.readInt24LE(this.buffer, offset);
|
||||
};
|
||||
this.writeSample = function (offset, value) {
|
||||
int24.writeInt24LE(this.buffer, offset, value);
|
||||
};
|
||||
this.sampleByteLength = 3;
|
||||
}
|
||||
else {
|
||||
args.bitDepth = 16;
|
||||
this.readSample = this.buffer.readInt16LE;
|
||||
@ -54,7 +64,7 @@ Input.prototype.read = function (samples) {
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
Input.prototype.readMono = function (samples) {
|
||||
// This function will be overridden by this.read, if input already is mono.
|
||||
@ -67,7 +77,7 @@ Input.prototype.readMono = function (samples) {
|
||||
this.writeSample.call(monoBuffer, Math.round((l + r) / 2), i * this.sampleByteLength);
|
||||
}
|
||||
return monoBuffer;
|
||||
}
|
||||
};
|
||||
|
||||
Input.prototype.readStereo = function (samples) {
|
||||
// This function will be overridden by this.read, if input already is stereo.
|
||||
@ -80,12 +90,12 @@ Input.prototype.readStereo = function (samples) {
|
||||
this.writeSample.call(stereoBuffer, m, (i * this.sampleByteLength * 2) + this.sampleByteLength);
|
||||
}
|
||||
return stereoBuffer;
|
||||
}
|
||||
};
|
||||
|
||||
Input.prototype.availSamples = function (length) {
|
||||
if (typeof length === 'undefined') length = this.buffer.length;
|
||||
return Math.floor(length / ((this.bitDepth / 8) * this.channels));
|
||||
}
|
||||
};
|
||||
|
||||
Input.prototype._write = function (chunk, encoding, next) {
|
||||
|
||||
@ -102,6 +112,6 @@ Input.prototype._write = function (chunk, encoding, next) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Input;
|
||||
|
15
lib/mixer.js
15
lib/mixer.js
@ -1,7 +1,7 @@
|
||||
var
|
||||
Readable = require('stream').Readable,
|
||||
util = require('util'),
|
||||
|
||||
int24 = require('int24'),
|
||||
Input = require('./input.js')
|
||||
;
|
||||
|
||||
@ -25,6 +25,15 @@ function Mixer(args) {
|
||||
this.writeSample = this.buffer.writeInt32LE;
|
||||
this.sampleByteLength = 4;
|
||||
}
|
||||
else if (args.bitDepth == 24) {
|
||||
this.readSample = function (offset) {
|
||||
return int24.readInt24LE(this.buffer, offset);
|
||||
};
|
||||
this.writeSample = function (offset, value) {
|
||||
int24.writeInt24LE(this.buffer, offset, value);
|
||||
};
|
||||
this.sampleByteLength = 3;
|
||||
}
|
||||
else {
|
||||
args.bitDepth = 16;
|
||||
this.readSample = this.buffer.readInt16LE;
|
||||
@ -66,7 +75,7 @@ Mixer.prototype._read = function() {
|
||||
} else {
|
||||
setImmediate(this._read.bind(this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mixer.prototype.input = function (args) {
|
||||
if (typeof args === 'undefined') args = {};
|
||||
@ -80,6 +89,6 @@ Mixer.prototype.input = function (args) {
|
||||
this.inputs.push(input);
|
||||
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Mixer;
|
||||
|
@ -5,6 +5,9 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
},
|
||||
"dependencies": {
|
||||
"int24": "*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/alfreddatakillen/audio-mixer.git"
|
||||
|
Loading…
Reference in New Issue
Block a user