Skip to content

Commit

Permalink
using bitdepth^3.0.1 to fix float to int precision loss
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Apr 30, 2018
1 parent f794d63 commit faad3d8
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 70 deletions.
56 changes: 28 additions & 28 deletions dist/wavefile-min.js

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions dist/wavefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,24 @@ module.exports.float64BE = new Type({"bits": 64, "float": true, "be": true});

/*
* type: The Type class.
* Copyright (c) 2017 Rafael da Silva Rocha.
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
* https://github.com/rochars/byte-data
*/

/** @private */
let f32 = new Float32Array(1);
var int8 = new Int8Array(4);
/** @private */
var i32 = new Int32Array(int8.buffer, 0, 1);
/** @private */
var f32 = new Float32Array(int8.buffer, 0, 1);

/** @private */
var int8f64 = new Int8Array(8);
/** @private */
let i32 = new Int32Array(f32.buffer);
let f64 = new Float64Array(int8f64.buffer);
/** @private */
let f64 = new Float64Array(1);
let ui32 = new Uint32Array(int8f64.buffer);
/** @private */
let ui32 = new Uint32Array(f64.buffer);
let GenericInteger = __webpack_require__(7);

/**
Expand Down Expand Up @@ -517,7 +523,7 @@ class Type extends GenericInteger {

/**
* Read 1 32-bit float from bytes.
* @param {!Array<number>|Uint8Array} bytes An array of bytes.
* @param {Array<number>|Uint8Array} bytes An array of bytes.
* @param {number} i The index to read.
* @return {number}
* @private
Expand All @@ -530,7 +536,7 @@ class Type extends GenericInteger {
/**
* Read 1 64-bit double from bytes.
* Thanks https://gist.github.com/kg/2192799
* @param {!Array<number>|Uint8Array} bytes An array of bytes.
* @param {Array<number>|Uint8Array} bytes An array of bytes.
* @param {number} i The index to read.
* @return {number}
* @private
Expand Down Expand Up @@ -1125,7 +1131,8 @@ const CODECS = {
*/
"floatToInt": function(sample, args) {
return sample > 0 ?
sample * args["newPositive"] : sample * args["newNegative"];
parseInt(sample * args["newPositive"], 10) :
parseInt(sample * args["newNegative"], 10);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/WaveFile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ <h4 class="name" id="toRIFX"><span class="type-signature"></span>toRIFX<span cla
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 30 2018 19:20:37 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 30 2018 20:41:52 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
56 changes: 28 additions & 28 deletions docs/example/wavefile-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h2>LICENSE</h2><p>Copyright (c) 2017-2018 Rafael da Silva Rocha.</p>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 30 2018 19:20:37 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 30 2018 20:41:52 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ <h1 class="page-title">index.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 30 2018 19:20:37 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Apr 30 2018 20:41:52 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wavefile",
"version": "5.0.2",
"version": "5.0.3",
"description": "Read & write wave files with 4, 8, 11, 12, 16, 20, 24, 32 & 64-bit data.",
"homepage": "https://github.com/rochars/wavefile",
"author": "Rafael da Silva Rocha <[email protected]>",
Expand Down Expand Up @@ -68,8 +68,8 @@
},
"dependencies": {
"alawmulaw": "^2.0.3",
"bitdepth": "^3.0.0",
"byte-data": "^5.0.1",
"bitdepth": "^3.0.1",
"byte-data": "^5.0.6",
"imaadpcm": "^1.1.3",
"riff-chunks": "^4.0.0"
},
Expand Down
Binary file modified test/files/out/to-bit-depth/32IEEE-to-16.wav
Binary file not shown.
Binary file modified test/files/out/to-bit-depth/32IEEE-to-8.wav
Binary file not shown.
Binary file modified test/files/out/to-bit-depth/64-to-16.wav
Binary file not shown.
Binary file modified test/files/out/to-bit-depth/64-to-8.wav
Binary file not shown.

0 comments on commit faad3d8

Please sign in to comment.