From 0b4e847cf0ed8251f5023d306d9e6c047fdb7268 Mon Sep 17 00:00:00 2001 From: Rafael Rocha Date: Wed, 11 Sep 2019 04:28:04 -0300 Subject: [PATCH] Fix: encode() return a even number of samples --- CHANGELOG.md | 3 +++ dist/imaadpcm.cjs.js | 6 +++++- dist/imaadpcm.js | 6 +++++- dist/imaadpcm.min.js | 4 ++-- dist/imaadpcm.umd.js | 6 +++++- docs/index.html | 2 +- docs/index.js.html | 8 ++++++-- docs/module-imaadpcm.html | 8 ++++---- index.js | 6 +++++- package-lock.json | 2 +- package.json | 2 +- 11 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c094b02..b5688c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## v4.1.1 (2019-09-11) +- Fix: encode() should always return a even number of samples + ## v4.1.0 (2019-09-06) - No clicks or time changes when compressing/decompressing - Fix: Range error bug when compressing diff --git a/dist/imaadpcm.cjs.js b/dist/imaadpcm.cjs.js index 7aeacfc..036d2c6 100644 --- a/dist/imaadpcm.cjs.js +++ b/dist/imaadpcm.cjs.js @@ -105,7 +105,11 @@ function encode(samples) { } block.push(samples[i]); } - return adpcmSamples.slice(0, (samples.length/2) + 512); + let samplesLength = (samples.length / 2); + if (samplesLength % 2) { + samplesLength--; + } + return adpcmSamples.slice(0, samplesLength + 512); } /** diff --git a/dist/imaadpcm.js b/dist/imaadpcm.js index 9981236..eae59fa 100644 --- a/dist/imaadpcm.js +++ b/dist/imaadpcm.js @@ -101,7 +101,11 @@ function encode(samples) { } block.push(samples[i]); } - return adpcmSamples.slice(0, (samples.length/2) + 512); + let samplesLength = (samples.length / 2); + if (samplesLength % 2) { + samplesLength--; + } + return adpcmSamples.slice(0, samplesLength + 512); } /** diff --git a/dist/imaadpcm.min.js b/dist/imaadpcm.min.js index 295dd82..53ce1ae 100644 --- a/dist/imaadpcm.min.js +++ b/dist/imaadpcm.min.js @@ -5,5 +5,5 @@ */ window.imaadpcm=function(m){function q(b){var a=b[0];n(a);var c=[];c.push(a&255);c.push(a>>8&255);c.push(k);c.push(0);for(a=3;a>4;a.push(t(f<<4^d));a.push(t(f))}return a}function n(b){var a=b-h;0<=a?b=0:(b=8,a=-a);var c=p[k],d=c>>3;a>c&&(b|=4,a-=c,d+=c);c>>=1;a>c&&(b|=2,a-=c,d+=c);c>>=1;a>c&&(b|=1,d+=c);a=b;h=a&8?h- d:h+d;-32768>h?h=-32768:32767k?k=0:88>1);b&1&&(a+=l>>2);a+=l>>3;b&8&&(a=-a);e+=a;32767e&&(e=-32767);g+=u[b];0>g?g=0:88
- Documentation generated by JSDoc 3.5.5 on Fri Sep 06 2019 13:38:13 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Sep 11 2019 04:25:44 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/docs/index.js.html b/docs/index.js.html index 810be45..8bda810 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -145,7 +145,11 @@

index.js

} block.push(samples[i]); } - return adpcmSamples.slice(0, (samples.length/2) + 512); + let samplesLength = (samples.length / 2); + if (samplesLength % 2) { + samplesLength--; + } + return adpcmSamples.slice(0, samplesLength + 512); } /** @@ -370,7 +374,7 @@

index.js


- Documentation generated by JSDoc 3.5.5 on Fri Sep 06 2019 13:38:13 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Sep 11 2019 04:25:44 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/docs/module-imaadpcm.html b/docs/module-imaadpcm.html index a99c9c7..4492d97 100644 --- a/docs/module-imaadpcm.html +++ b/docs/module-imaadpcm.html @@ -84,7 +84,7 @@

(static) decod
Source:
@@ -258,7 +258,7 @@

(static)
Source:
@@ -560,7 +560,7 @@

(static)
Source:
@@ -712,7 +712,7 @@

Returns:

- Documentation generated by JSDoc 3.5.5 on Fri Sep 06 2019 13:38:13 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Wed Sep 11 2019 04:25:44 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/index.js b/index.js index 91d2f2c..aed2529 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,11 @@ export function encode(samples) { } block.push(samples[i]); } - return adpcmSamples.slice(0, (samples.length/2) + 512); + let samplesLength = (samples.length / 2); + if (samplesLength % 2) { + samplesLength--; + } + return adpcmSamples.slice(0, samplesLength + 512); } /** diff --git a/package-lock.json b/package-lock.json index d6168a4..02a9988 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "imaadpcm", - "version": "4.1.0", + "version": "4.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 14ed834..0e8bec3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "imaadpcm", - "version": "4.1.0", + "version": "4.1.1", "description": "IMA ADPCM codec in JavaScript.", "homepage": "https://github.com/rochars/imaadpcm", "author": "Rafael S. Rocha ",