Skip to content

Commit

Permalink
WaveFile.toBase64() and WaveFile.toDataURI()
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed May 7, 2018
1 parent d927b7b commit 2e96db2
Show file tree
Hide file tree
Showing 11 changed files with 781 additions and 256 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## version 6.4.0 (2018-05-07)
- WaveFile.toBase64() and WaveFile.toDataURI() to export the file as a Base64 string or a DataURI.

## version 6.3.0 (2018-05-06)
- fromIMAADPCM, fromALaw and fromMuLaw can receive an optional parameter: the bit depth of the output. If ommited, defaults to "16".
- Fix: argument validation in fromScratch
Expand Down
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,51 @@ Some bit depths may not be supported by your browser, like 32-bit floating point

## Use
```javascript
let fs = require("fs");
let Wavefile = require("wavefile");
const fs = require("fs");
const Wavefile = require("wavefile");

// Load a wav file from disk into a WaveFile object
let wav = new Wavefile(fs.readFileSync("file.wav"));

// Check some of the file properties
console.log(wav.container);
console.log(wav.chunkSize);
console.log(wav.fmt.chunkId);

// Call toBuffer() to get the bytes of the file.
// You can write the output straight to disk:
fs.writeFileSync(path, wav.toBuffer());

// Call toDataURI() to get the file as a base64-encoded
// DataURI to load the file a web browser:
wavDataURI = wav.toDataURI();
```

### Main methods:

#### WaveFile.fromBuffer()
Load a .wav file from a byte buffer into a WaveFile object:
```javascript
let wav = new Wavefile(buffer);
```

#### WaveFile.fromScratch()
Create a WaveFile object with the arguments you pass:
```javascript
// A mono, 44.1 kHz, 32-bit .wav file with just 4 samples:
wav.fromScratch(1, 44100, '32', [0, -2147483648, 2147483647, 4]);
```

#### WaveFile.toBuffer()
Return a Uint8Array with the WaveFile object data. The buffer is a .wav file and can be written to disk:
```javascript
buffer = wav.toBuffer();
```

#### WaveFile.toDataURI()
Return a DataURI string with the WaveFile object data. The DataURI is a .wav file and can be played in browsers:
```javascript
wavDataURI = wav.toDataURI();
```

### Create wave files from scratch
Expand Down
113 changes: 58 additions & 55 deletions dist/wavefile-min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2e96db2

Please sign in to comment.