fix comments in flac-related codebase
This commit is contained in:
parent
7822831b1e
commit
4550848eac
|
@ -192,7 +192,7 @@ export class FlacAdapter extends RecordingAdapter {
|
|||
// set up listen for messages from the WebWorker
|
||||
this._encoder.onmessage = e => {
|
||||
if (e.data.command === WORKER_BLOB_READY) {
|
||||
// receiving blob
|
||||
// Received a Blob representing an encoded FLAC file.
|
||||
this._data = e.data.buf;
|
||||
if (this._stopPromiseResolver !== null) {
|
||||
this._stopPromiseResolver();
|
||||
|
@ -233,7 +233,9 @@ export class FlacAdapter extends RecordingAdapter {
|
|||
this._audioProcessingNode
|
||||
= this._audioContext.createScriptProcessor(4096, 1, 1);
|
||||
this._audioProcessingNode.onaudioprocess = e => {
|
||||
// delegate to the WebWorker to do the encoding
|
||||
// Delegates to the WebWorker to do the encoding.
|
||||
// The return of getChannelData() is a Float32Array,
|
||||
// each element representing one sample.
|
||||
const channelLeft = e.inputBuffer.getChannelData(0);
|
||||
|
||||
this._encoder.postMessage({
|
||||
|
|
|
@ -215,7 +215,7 @@ class Encoder {
|
|||
/**
|
||||
* Receive and encode new data.
|
||||
*
|
||||
* @param {*} audioData - Raw audio data.
|
||||
* @param {Float32Array} audioData - Raw audio data.
|
||||
* @returns {void}
|
||||
*/
|
||||
encode(audioData) {
|
||||
|
@ -228,9 +228,16 @@ class Encoder {
|
|||
}
|
||||
const bufferLength = audioData.length;
|
||||
|
||||
// convert to Uint32,
|
||||
// appearantly libflac requires 32-bit signed integer input
|
||||
// FIXME: why unsigned 32bit array?
|
||||
// Convert sample to signed 32-bit integers.
|
||||
// According to libflac documentation:
|
||||
// each sample in the buffers should be a signed integer,
|
||||
// right-justified to the resolution set by
|
||||
// FLAC__stream_encoder_set_bits_per_sample().
|
||||
|
||||
// Here we are using 16 bits per sample, the samples should all be in
|
||||
// the range [-32768,32767]. This is achieved by multipling Float32
|
||||
// numbers with 0x7FFF.
|
||||
|
||||
const bufferI32 = new Int32Array(bufferLength);
|
||||
const view = new DataView(bufferI32.buffer);
|
||||
const volume = 1;
|
||||
|
@ -238,7 +245,7 @@ class Encoder {
|
|||
|
||||
for (let i = 0; i < bufferLength; i++) {
|
||||
view.setInt32(index, audioData[i] * (0x7FFF * volume), true);
|
||||
index += 4; // 4 bytes (32bit)
|
||||
index += 4; // 4 bytes (32-bit)
|
||||
}
|
||||
|
||||
// pass it to libflac
|
||||
|
@ -249,7 +256,7 @@ class Encoder {
|
|||
);
|
||||
|
||||
if (status !== 1) {
|
||||
// get error
|
||||
// gets error number
|
||||
|
||||
const errorNo
|
||||
= Flac.FLAC__stream_encoder_get_state(this._encoderId);
|
||||
|
@ -278,17 +285,6 @@ class Encoder {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stats.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
getStats() {
|
||||
return {
|
||||
'samplesEncoded': this._bufferSize
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the encoded flac file.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue