Skip to content

Commit

Permalink
Fix encode() output length
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Sep 12, 2019
1 parent 0b4e847 commit 33d86c8
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## v4.1.2 (2019-09-12)
- Fix: output array in correct size

## v4.1.1 (2019-09-11)
- Fix: encode() should always return a even number of samples

Expand Down
9 changes: 6 additions & 3 deletions dist/imaadpcm.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,22 @@ function encode(samples) {
let block = [];
/** @type {number} */
let fileIndex = 0;
/** @type {number} */
let blockCount = 0;
for (let i=0; i<samples.length; i++) {
if ((i % 505 == 0 && i != 0)) {
adpcmSamples.set(encodeBlock(block), fileIndex);
fileIndex += 256;
block = [];
blockCount++;
}
block.push(samples[i]);
}
let samplesLength = (samples.length / 2);
let samplesLength = samples.length / 2;
if (samplesLength % 2) {
samplesLength--;
samplesLength++;
}
return adpcmSamples.slice(0, samplesLength + 512);
return adpcmSamples.slice(0, samplesLength + 512 + blockCount * 4);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions dist/imaadpcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,22 @@ function encode(samples) {
let block = [];
/** @type {number} */
let fileIndex = 0;
/** @type {number} */
let blockCount = 0;
for (let i=0; i<samples.length; i++) {
if ((i % 505 == 0 && i != 0)) {
adpcmSamples.set(encodeBlock(block), fileIndex);
fileIndex += 256;
block = [];
blockCount++;
}
block.push(samples[i]);
}
let samplesLength = (samples.length / 2);
let samplesLength = samples.length / 2;
if (samplesLength % 2) {
samplesLength--;
samplesLength++;
}
return adpcmSamples.slice(0, samplesLength + 512);
return adpcmSamples.slice(0, samplesLength + 512 + blockCount * 4);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions dist/imaadpcm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions dist/imaadpcm.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,22 @@
let block = [];
/** @type {number} */
let fileIndex = 0;
/** @type {number} */
let blockCount = 0;
for (let i=0; i<samples.length; i++) {
if ((i % 505 == 0 && i != 0)) {
adpcmSamples.set(encodeBlock(block), fileIndex);
fileIndex += 256;
block = [];
blockCount++;
}
block.push(samples[i]);
}
let samplesLength = (samples.length / 2);
let samplesLength = samples.length / 2;
if (samplesLength % 2) {
samplesLength--;
samplesLength++;
}
return adpcmSamples.slice(0, samplesLength + 512);
return adpcmSamples.slice(0, samplesLength + 512 + blockCount * 4);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ <h2>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Sep 11 2019 04:25:44 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 Thu Sep 12 2019 05:22:42 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
11 changes: 7 additions & 4 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,22 @@ <h1 class="page-title">index.js</h1>
let block = [];
/** @type {number} */
let fileIndex = 0;
/** @type {number} */
let blockCount = 0;
for (let i=0; i&lt;samples.length; i++) {
if ((i % 505 == 0 &amp;&amp; i != 0)) {
adpcmSamples.set(encodeBlock(block), fileIndex);
fileIndex += 256;
block = [];
blockCount++;
}
block.push(samples[i]);
}
let samplesLength = (samples.length / 2);
let samplesLength = samples.length / 2;
if (samplesLength % 2) {
samplesLength--;
samplesLength++;
}
return adpcmSamples.slice(0, samplesLength + 512);
return adpcmSamples.slice(0, samplesLength + 512 + blockCount * 4);
}

/**
Expand Down Expand Up @@ -374,7 +377,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 Wed Sep 11 2019 04:25:44 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 Thu Sep 12 2019 05:22:42 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
8 changes: 4 additions & 4 deletions docs/module-imaadpcm.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h4 class="name" id=".decode"><span class="type-signature">(static) </span>decod

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line122">line 122</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line125">line 125</a>
</li></ul></dd>


Expand Down Expand Up @@ -258,7 +258,7 @@ <h4 class="name" id=".decodeBlock"><span class="type-signature">(static) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line164">line 164</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line167">line 167</a>
</li></ul></dd>


Expand Down Expand Up @@ -560,7 +560,7 @@ <h4 class="name" id=".encodeBlock"><span class="type-signature">(static) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line146">line 146</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line149">line 149</a>
</li></ul></dd>


Expand Down Expand Up @@ -712,7 +712,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Sep 11 2019 04:25:44 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 Thu Sep 12 2019 05:22:42 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,22 @@ export function encode(samples) {
let block = [];
/** @type {number} */
let fileIndex = 0;
/** @type {number} */
let blockCount = 0;
for (let i=0; i<samples.length; i++) {
if ((i % 505 == 0 && i != 0)) {
adpcmSamples.set(encodeBlock(block), fileIndex);
fileIndex += 256;
block = [];
blockCount++;
}
block.push(samples[i]);
}
let samplesLength = (samples.length / 2);
let samplesLength = samples.length / 2;
if (samplesLength % 2) {
samplesLength--;
samplesLength++;
}
return adpcmSamples.slice(0, samplesLength + 512);
return adpcmSamples.slice(0, samplesLength + 512 + blockCount * 4);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imaadpcm",
"version": "4.1.1",
"version": "4.1.2",
"description": "IMA ADPCM codec in JavaScript.",
"homepage": "https://github.com/rochars/imaadpcm",
"author": "Rafael S. Rocha <[email protected]>",
Expand Down

0 comments on commit 33d86c8

Please sign in to comment.