Skip to content

Commit

Permalink
Fix: assure samples are de-interleaved on fromScratch().
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed May 10, 2018
1 parent 4c9638e commit 0c0ee9f
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 193 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Reading the "junk" chunk. The chunk is kept when changing bit depth, using compression or when re-creating an existing WaveFile object with the fromScratch() or fromBuffer() method.
- Fix: all chunkSize fields are calculated when writing the file.
- Fix: calling clearHeader_() on fromBuffer(), not just fromScratch(). The method is used to clear data in the file header that might lead to corrupt files, like the "fact" chunk.
- Fix: assure samples are de-interleaved on fromScratch() before using the array.

## version 6.4.1 (2018-05-07)
- Using compilationLevel: ADVANCED with Closure Compiler.
Expand Down
46 changes: 15 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Web browsers are typically limited to play wav files with 8, 16, 24 and 32-bit d
Playing ADPCM in the browser:
```javascript
// Load a wav file that is encoded as 4-bit IMA ADPCM:
let wav = new Wavefile(ADPCMFileBuffer);
let wav = new WaveFile(ADPCMFileBuffer);

// Decode the file to 16-bit PCM, supported by most browsers:
wav.fromIMAADPCM();
Expand All @@ -56,7 +56,7 @@ let dataURI = wav.toDataURI();
Playing a 64-bit wave file in the browser:
```javascript
// Load a wav file that has 64-bit audio:
let wav = new Wavefile(buffer);
let wav = new WaveFile(buffer);

// Change the bit depth to 16-bit, supported by most browsers:
wav.toBitDepth("16");
Expand All @@ -82,7 +82,7 @@ Some bit depths may not be supported by your browser, like 32-bit floating point
## Use
```javascript
// Load a wav file from disk into a WaveFile object
let wav = new Wavefile(buffer);
let wav = new WaveFile(buffer);

// Check some of the file properties
console.log(wav.container);
Expand All @@ -108,7 +108,7 @@ wav.fromBuffer(buffer);

This is the same as passing the buffer when creating the WaveFile object:
```javascript
let wav = new Wavefile(buffer);
let wav = new WaveFile(buffer);
```

#### WaveFile.fromScratch()
Expand Down Expand Up @@ -262,19 +262,18 @@ wav.fromMuLaw("24");
```

### Change the bit depth

You can change the bit depth of the audio with the **toBitDepth(bitDepth)** method.

```javascript
// Load a wav file with 32-bit audio
let wav = new Wavefile(fs.readFileSync("32bit-file.wav"));
let wav = new WaveFile(fs.readFileSync("32bit-file.wav"));

// Change the bit depth to 24-bit
wav.toBitDepth("24");

// Write the new 24-bit file
fs.writeFileSync("24bit-file.wav", wav.toBuffer());

// You can use any supported bit depth:
wav.toBitDepth("11");
fs.writeFileSync("11bit-file.wav", wav.toBuffer());
```

### The properties
Expand All @@ -286,7 +285,7 @@ console.log(wav.data.samples);

The other public properties:
```javascript
let wav = new Wavefile(fs.readFileSync("file.wav"));
let wav = new WaveFile(fs.readFileSync("file.wav"));

// The container data
console.log(wav.container); //"RIFF" or "RIFX"
Expand Down Expand Up @@ -332,13 +331,13 @@ console.log(wav.cue.chunkId);
console.log(wav.cue.chunkSize);

// "LIST"
console.log(wav.LISTChunks.length);
console.log(wav.LIST.length);
```

#### BWF data
BWF data ("bext" chunk) is stored in the *bext* property.
```javascript
wav.bext = {
WaveFile.bext = {
"chunkId": "",
"chunkSize": 0,
"description": "", // 256 chars
Expand All @@ -362,7 +361,7 @@ wav.bext = {
#### Cue points
"cue " chunk data is stored as follows:
```javascript
wav.cue = {
WaveFile.cue = {
"chunkId": "",
"chunkSize": 0,
"dwCuePoints": 0, //DWORD
Expand All @@ -389,10 +388,10 @@ Items in cue.points are objects with this signature:
* An array of the "LIST" chunks present in the file.
* @type {Array<Object>}
*/
wav.LISTChunks = [];
WaveFile.LIST = [];
```

WaveFile.LISTChunks is an array of objects with this signature:
WaveFile.LIST is an array of objects with this signature:
```javascript
{
/** @type {!string} */
Expand All @@ -405,22 +404,7 @@ WaveFile.LISTChunks is an array of objects with this signature:
"subChunks": []
};
```
Where "subChunks" contains the subChunks of the "LIST" chunk. They can be "INFO" or "adtl". A single file may have many "LIST" chunks as long as their formats ("INFO", "adtl", etc) are not the same.

For "LIST" chunks with the "adtl" format, "subChunks" is an array of objects with this signature:
```javascript
{
/** @type {!string} */
"chunkId": "" // only 'labl' or 'note'
/** @type {!number} */
"chunkSize" 0,
/** @type {!number} */
"dwName": 0,
/** @type {!string} */
"value": ""
}
```
Where "value" is the text of the "labl" or "note" chunk, and "dwName" is the cue point to where the note/labl points to.
Where "subChunks" contains the subChunks of the "LIST" chunk. WaveFile supports "LIST" chunks of format "INFO". A single file may have many "LIST" chunks as long as their formats ("INFO", "adtl", etc) are not the same.

For "LIST" chunks with the "INFO" format, "subChunks" is an array of objects with this signature:
```javascript
Expand Down
38 changes: 19 additions & 19 deletions dist/wavefile-min.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions docs/WaveFile.html
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ <h4 class="name" id="deInterleave"><span class="type-signature"></span>deInterle

<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#line517">line 517</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line516">line 516</a>
</li></ul></dd>


Expand Down Expand Up @@ -1321,7 +1321,7 @@ <h4 class="name" id="fromALaw"><span class="type-signature"></span>fromALaw<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#line602">line 602</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line601">line 601</a>
</li></ul></dd>


Expand Down Expand Up @@ -1708,7 +1708,7 @@ <h4 class="name" id="fromIMAADPCM"><span class="type-signature"></span>fromIMAAD

<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#line568">line 568</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line567">line 567</a>
</li></ul></dd>


Expand Down Expand Up @@ -1849,7 +1849,7 @@ <h4 class="name" id="fromMuLaw"><span class="type-signature"></span>fromMuLaw<sp

<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#line636">line 636</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line635">line 635</a>
</li></ul></dd>


Expand Down Expand Up @@ -2221,7 +2221,7 @@ <h4 class="name" id="getLISTBytes_"><span class="type-signature"></span>getLISTB

<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#line1380">line 1380</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1379">line 1379</a>
</li></ul></dd>


Expand Down Expand Up @@ -2327,7 +2327,7 @@ <h4 class="name" id="getLISTSize_"><span class="type-signature"></span>getLISTSi

<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#line1367">line 1367</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line1366">line 1366</a>
</li></ul></dd>


Expand Down Expand Up @@ -2433,7 +2433,7 @@ <h4 class="name" id="interleave"><span class="type-signature"></span>interleave<

<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#line499">line 499</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line498">line 498</a>
</li></ul></dd>


Expand Down Expand Up @@ -2517,7 +2517,7 @@ <h4 class="name" id="realBitDepth_"><span class="type-signature"></span>realBitD

<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#line654">line 654</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line653">line 653</a>
</li></ul></dd>


Expand Down Expand Up @@ -2668,7 +2668,7 @@ <h4 class="name" id="toALaw"><span class="type-signature"></span>toALaw<span cla

<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#line584">line 584</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line583">line 583</a>
</li></ul></dd>


Expand Down Expand Up @@ -2752,7 +2752,7 @@ <h4 class="name" id="toBase64"><span class="type-signature"></span>toBase64<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#line418">line 418</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line417">line 417</a>
</li></ul></dd>


Expand Down Expand Up @@ -2887,7 +2887,7 @@ <h4 class="name" id="toBitDepth"><span class="type-signature"></span>toBitDepth<

<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#line477">line 477</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line476">line 476</a>
</li></ul></dd>


Expand Down Expand Up @@ -3084,7 +3084,7 @@ <h4 class="name" id="toBuffer"><span class="type-signature"></span>toBuffer<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#line406">line 406</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line405">line 405</a>
</li></ul></dd>


Expand Down Expand Up @@ -3219,7 +3219,7 @@ <h4 class="name" id="toDataURI"><span class="type-signature"></span>toDataURI<sp

<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#line429">line 429</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line428">line 428</a>
</li></ul></dd>


Expand Down Expand Up @@ -3354,7 +3354,7 @@ <h4 class="name" id="toIMAADPCM"><span class="type-signature"></span>toIMAADPCM<

<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#line543">line 543</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line542">line 542</a>
</li></ul></dd>


Expand Down Expand Up @@ -3494,7 +3494,7 @@ <h4 class="name" id="toMuLaw"><span class="type-signature"></span>toMuLaw<span c

<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#line618">line 618</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line617">line 617</a>
</li></ul></dd>


Expand Down Expand Up @@ -3578,7 +3578,7 @@ <h4 class="name" id="toRIFF"><span class="type-signature"></span>toRIFF<span cla

<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#line437">line 437</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line436">line 436</a>
</li></ul></dd>


Expand Down Expand Up @@ -3662,7 +3662,7 @@ <h4 class="name" id="toRIFX"><span class="type-signature"></span>toRIFX<span cla

<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#line454">line 454</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line453">line 453</a>
</li></ul></dd>


Expand Down Expand Up @@ -3747,7 +3747,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 Thu May 10 2018 02:22:06 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 May 10 2018 03:28:54 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
Loading

0 comments on commit 0c0ee9f

Please sign in to comment.