Skip to content

Commit

Permalink
Fix type declarations for fromScratch()
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Jan 8, 2020
1 parent f2991fd commit 8ccf2cb
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 139 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,18 +479,22 @@ WaveFile(bytes=null);
### The WaveFile methods
```javascript
/**
* Set up the WaveFile object based on the arguments passed.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* Set up the WaveFileCreator object based on the arguments passed.
* Existing chunks are reset.
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepth The audio bit depth code.
* One of "4", "8", "8a", "8m", "16", "24", "32", "32f", "64"
* or any value between "8" and "32" (like "12").
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} samples
* The samples. Must be in the correct range according to the bit depth.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {
* !Array<number> |
* !Array<Array<number>> |
* !TypedArray |
* !Array<TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {"container": "RIFX"}
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
*/
WaveFile.fromScratch(numChannels, sampleRate, bitDepth, samples, options={}) {}
Expand Down
52 changes: 26 additions & 26 deletions dist/wavefile.js

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,22 @@ <h2>API</h2>
</code></pre>
<h3>The WaveFile methods</h3>
<pre class="prettyprint source lang-javascript"><code>/**
* Set up the WaveFile object based on the arguments passed.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* Set up the WaveFileCreator object based on the arguments passed.
* Existing chunks are reset.
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepth The audio bit depth code.
* One of &quot;4&quot;, &quot;8&quot;, &quot;8a&quot;, &quot;8m&quot;, &quot;16&quot;, &quot;24&quot;, &quot;32&quot;, &quot;32f&quot;, &quot;64&quot;
* or any value between &quot;8&quot; and &quot;32&quot; (like &quot;12&quot;).
* @param {!Array&lt;number>|!Array&lt;!Array&lt;number>>|!ArrayBufferView} samples
* The samples. Must be in the correct range according to the bit depth.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {
* !Array&lt;number> |
* !Array&lt;Array&lt;number>> |
* !TypedArray |
* !Array&lt;TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {&quot;container&quot;: &quot;RIFX&quot;}
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
*/
WaveFile.fromScratch(numChannels, sampleRate, bitDepth, samples, options={}) {}
Expand Down
88 changes: 47 additions & 41 deletions docs/lib_wavefile-creator.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ <h1 class="page-title">lib/wavefile-creator.js</h1>
/**
* Set up the WaveFileCreator object based on the arguments passed.
* Existing chunks are reset.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {!Array&lt;number>|!Array&lt;!Array&lt;number>>|!TypedArray} samples
* The samples. Must be in the correct range according to the bit depth.
* @param {
* !Array&lt;number> |
* !Array&lt;Array&lt;number>> |
* !TypedArray |
* !Array&lt;TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
Expand All @@ -139,42 +142,6 @@ <h1 class="page-title">lib/wavefile-creator.js</h1>
this.newWavFile_(numChannels, sampleRate, bitDepthCode, samples, options);
}

/**
* Set up the WaveFileCreator object based on the arguments passed.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {!Array&lt;number>|!Array&lt;!Array&lt;number>>|!TypedArray} samples
* The samples. Must be in the correct range according to the bit depth.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
* @private
*/
newWavFile_(numChannels, sampleRate, bitDepthCode, samples, options={}) {
if (!options.container) {
options.container = 'RIFF';
}
this.container = options.container;
this.bitDepth = bitDepthCode;
samples = interleave(samples);
this.updateDataType_();
/** @type {number} */
let numBytes = this.dataType.bits / 8;
this.data.samples = new Uint8Array(samples.length * numBytes);
packArrayTo(samples, this.dataType, this.data.samples);
this.makeWavHeader_(
bitDepthCode, numChannels, sampleRate,
numBytes, this.data.samples.length, options);
this.data.chunkId = 'data';
this.data.chunkSize = this.data.samples.length;
this.validateWavHeader_();
}

/**
* Set up the WaveFileParser object from a byte buffer.
* @param {!Uint8Array} wavBuffer The buffer.
Expand Down Expand Up @@ -297,6 +264,45 @@ <h1 class="page-title">lib/wavefile-creator.js</h1>
this._PMX.chunkId = '_PMX';
}

/**
* Set up the WaveFileCreator object based on the arguments passed.
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {
* !Array&lt;number> |
* !Array&lt;Array&lt;number>> |
* !TypedArray |
* !Array&lt;TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
* @private
*/
newWavFile_(numChannels, sampleRate, bitDepthCode, samples, options={}) {
if (!options.container) {
options.container = 'RIFF';
}
this.container = options.container;
this.bitDepth = bitDepthCode;
samples = interleave(samples);
this.updateDataType_();
/** @type {number} */
let numBytes = this.dataType.bits / 8;
this.data.samples = new Uint8Array(samples.length * numBytes);
packArrayTo(samples, this.dataType, this.data.samples);
this.makeWavHeader_(
bitDepthCode, numChannels, sampleRate,
numBytes, this.data.samples.length, options);
this.data.chunkId = 'data';
this.data.chunkSize = this.data.samples.length;
this.validateWavHeader_();
}

/**
* Define the header of a wav file.
* @param {string} bitDepthCode The audio bit depth
Expand Down
14 changes: 8 additions & 6 deletions externs/wavefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,18 @@ WaveFile.prototype.setSample = function(index, sample) {};

/**
* Set up the WaveFile object based on the arguments passed.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of 4, 8, 8a, 8m, 16, 24, 32, 32f, 64
* or any value between 8 and 32 (like 12).
* @param {!Array<number>} samples Array of samples to be written.
* The samples must be in the correct range according to the
* bit depth.
* @param {
* !Array<number> |
* !Array<Array<number>> |
* !TypedArray |
* !Array<TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {container: RIFX}
* @throws {Error} If any argument does not meet the criteria.
Expand Down
8 changes: 3 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ declare module wavefile {

/**
* Set up the WaveFile object based on the arguments passed.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} samples
* The samples. Must be in the correct range according to the bit depth.
* @param {!Array<number>|!Array<Array<number>>|!TypedArray|!!Array<TypedArray>} samples
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
Expand All @@ -145,7 +143,7 @@ declare module wavefile {
numChannels: number,
sampleRate: number,
bitDepthCode: string,
samples: Array<number>|Array<Array<number>>|ArrayBufferView,
samples: Array<number>|Array<Array<number>>|ArrayLike<any>|Array<ArrayLike<any>>,
options?: object): void;

/**
Expand Down
88 changes: 47 additions & 41 deletions lib/wavefile-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ export class WaveFileCreator extends WaveFileParser {
/**
* Set up the WaveFileCreator object based on the arguments passed.
* Existing chunks are reset.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {!Array<number>|!Array<!Array<number>>|!TypedArray} samples
* The samples. Must be in the correct range according to the bit depth.
* @param {
* !Array<number> |
* !Array<Array<number>> |
* !TypedArray |
* !Array<TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
Expand All @@ -95,42 +98,6 @@ export class WaveFileCreator extends WaveFileParser {
this.newWavFile_(numChannels, sampleRate, bitDepthCode, samples, options);
}

/**
* Set up the WaveFileCreator object based on the arguments passed.
* @param {number} numChannels The number of channels
* (Integer numbers: 1 for mono, 2 stereo and so on).
* @param {number} sampleRate The sample rate.
* Integer numbers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {!Array<number>|!Array<!Array<number>>|!TypedArray} samples
* The samples. Must be in the correct range according to the bit depth.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
* @private
*/
newWavFile_(numChannels, sampleRate, bitDepthCode, samples, options={}) {
if (!options.container) {
options.container = 'RIFF';
}
this.container = options.container;
this.bitDepth = bitDepthCode;
samples = interleave(samples);
this.updateDataType_();
/** @type {number} */
let numBytes = this.dataType.bits / 8;
this.data.samples = new Uint8Array(samples.length * numBytes);
packArrayTo(samples, this.dataType, this.data.samples);
this.makeWavHeader_(
bitDepthCode, numChannels, sampleRate,
numBytes, this.data.samples.length, options);
this.data.chunkId = 'data';
this.data.chunkSize = this.data.samples.length;
this.validateWavHeader_();
}

/**
* Set up the WaveFileParser object from a byte buffer.
* @param {!Uint8Array} wavBuffer The buffer.
Expand Down Expand Up @@ -253,6 +220,45 @@ export class WaveFileCreator extends WaveFileParser {
this._PMX.chunkId = '_PMX';
}

/**
* Set up the WaveFileCreator object based on the arguments passed.
* @param {number} numChannels The number of channels.
* @param {number} sampleRate The sample rate.
* Integers like 8000, 44100, 48000, 96000, 192000.
* @param {string} bitDepthCode The audio bit depth code.
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
* or any value between '8' and '32' (like '12').
* @param {
* !Array<number> |
* !Array<Array<number>> |
* !TypedArray |
* !Array<TypedArray>
* } samples The samples.
* @param {?Object} options Optional. Used to force the container
* as RIFX with {'container': 'RIFX'}
* @throws {Error} If any argument does not meet the criteria.
* @private
*/
newWavFile_(numChannels, sampleRate, bitDepthCode, samples, options={}) {
if (!options.container) {
options.container = 'RIFF';
}
this.container = options.container;
this.bitDepth = bitDepthCode;
samples = interleave(samples);
this.updateDataType_();
/** @type {number} */
let numBytes = this.dataType.bits / 8;
this.data.samples = new Uint8Array(samples.length * numBytes);
packArrayTo(samples, this.dataType, this.data.samples);
this.makeWavHeader_(
bitDepthCode, numChannels, sampleRate,
numBytes, this.data.samples.length, options);
this.data.chunkId = 'data';
this.data.chunkSize = this.data.samples.length;
this.validateWavHeader_();
}

/**
* Define the header of a wav file.
* @param {string} bitDepthCode The audio bit depth
Expand Down

0 comments on commit 8ccf2cb

Please sign in to comment.